TopViewModel.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.Util;
  5. using Aitex.Core.WCF;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.OperationCenter;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Linq;
  14. using System.Windows;
  15. using System.Windows.Media;
  16. using System.Windows.Threading;
  17. using Venus_Core;
  18. using Venus_MainPages.Unity;
  19. using Venus_MainPages.Views;
  20. namespace Venus_MainPages.ViewModels
  21. {
  22. internal class TopViewModel : BindableBase
  23. {
  24. #region 私有字段
  25. private string m_Title;
  26. private string m_SoftwareVersion;
  27. //private DateTime m_DateTimeNow;
  28. private List<string> m_RtDataKeys = new List<string>();
  29. private Dictionary<string, object> m_RtDataValues;
  30. //private string ModuleName;
  31. private ObservableCollection<EventItem> m_EventLogList = new ObservableCollection<EventItem>();
  32. private EventItem m_CurrentEventItem = new EventItem();
  33. private string m_CurrentEventItemValue;
  34. //private object _lockObj = new object();
  35. private int m_EventLogListSelectedIndex;
  36. private Queue<EventItem> alarmQuery = new Queue<EventItem>();//控制alarm log 在 top UI显示
  37. private readonly int logMaxCount = 50;//log在ui最多显示数量
  38. private AITSignalTowerData m_SignalTowerData;
  39. private string m_HostCommunicationStatus;
  40. private string m_TimeTick;
  41. private string m_UserName;
  42. //private JetChamber m_SelectedJetChamber = JetChamber.None;
  43. private bool m_PMAIsInstalled;
  44. private bool m_PMBIsInstalled;
  45. private bool m_PMCIsInstalled;
  46. private bool m_PMDIsInstalled;
  47. private bool m_LLAIsInstalled;
  48. private bool m_LLBIsInstalled;
  49. private bool m_TMIsInstalled;
  50. private bool m_EFEMIsInstalled;
  51. //private List<eEvent> stopEntityId = new List<eEvent>()
  52. //{
  53. // eEvent.ERR_MATCH,
  54. // eEvent.ERR_RF,
  55. // eEvent.ERR_PENDULUM_VALVE,
  56. // eEvent.ERR_DEVICE_INFO,
  57. // eEvent.ERR_DRY_PUMP,
  58. // eEvent.ERR_HighTemperatureHeater
  59. // //eEvent.ERR_Sensor
  60. //};
  61. //private PressureType m_PressureType;
  62. //private ConfigType m_ConfigType;
  63. private bool m_IsExcludeInfoType;
  64. #endregion
  65. #region 属性
  66. public string UserName
  67. {
  68. get { return m_UserName; }
  69. set { SetProperty(ref m_UserName, value); }
  70. }
  71. //public DateTime DateTimeNow
  72. //{
  73. // get { return m_DateTimeNow; }
  74. // set { SetProperty(ref m_DateTimeNow, value); }
  75. //}
  76. public string Title
  77. {
  78. get { return m_Title; }
  79. set { SetProperty(ref m_Title, value); }
  80. }
  81. public string SoftwareVersion
  82. {
  83. get { return m_SoftwareVersion; }
  84. set { SetProperty(ref m_SoftwareVersion, value); }
  85. }
  86. public string TimeTick
  87. {
  88. get { return m_TimeTick; }
  89. set { SetProperty(ref m_TimeTick, value); }
  90. }
  91. public Dictionary<string, object> RtDataValues
  92. {
  93. get { return m_RtDataValues; }
  94. set { SetProperty(ref m_RtDataValues, value); }
  95. }
  96. public ObservableCollection<EventItem> EventLogList
  97. {
  98. get { return m_EventLogList; }
  99. set { SetProperty(ref m_EventLogList, value); }
  100. }
  101. public EventItem CurrentEventItem
  102. {
  103. get { return m_CurrentEventItem; }
  104. set { SetProperty(ref m_CurrentEventItem, value); }
  105. }
  106. public int EventLogListSelectedIndex
  107. {
  108. get { return m_EventLogListSelectedIndex; }
  109. set { SetProperty(ref m_EventLogListSelectedIndex, value); }
  110. }
  111. public string CurrentEventItemValue
  112. {
  113. get { return m_CurrentEventItemValue; }
  114. set { SetProperty(ref m_CurrentEventItemValue, value); }
  115. }
  116. public AITSignalTowerData SignalTowerData
  117. {
  118. get { return m_SignalTowerData; }
  119. set { SetProperty(ref m_SignalTowerData, value); }
  120. }
  121. public string HostCommunicationStatusBackground
  122. {
  123. get
  124. {
  125. switch (HostCommunicationStatus)
  126. {
  127. case "Disabled":
  128. return "#D79C11";
  129. case "Enabled":
  130. case "EnabledNotCommunicating":
  131. case "WaitCRA":
  132. case "WaitDelay":
  133. case "WaitCRFromHost":
  134. return "Transparent";
  135. case "EnabledCommunicating":
  136. return "LawnGreen";
  137. default:
  138. return "#D79C11";
  139. }
  140. }
  141. }
  142. public string m_HostBack;
  143. public string HostBack
  144. {
  145. get { return m_HostBack; }
  146. set { SetProperty(ref m_HostBack, value); }
  147. }
  148. [Subscription("System.CommunicationStatus")]
  149. public string HostCommunicationStatus
  150. {
  151. get { return m_HostCommunicationStatus; }
  152. set
  153. {
  154. SetProperty(ref m_HostCommunicationStatus, value);
  155. }
  156. }
  157. public bool IsEnableFAEnable
  158. {
  159. get
  160. {
  161. return HostCommunicationStatus == "Disabled";
  162. }
  163. }
  164. public bool _IsEnableEnable;
  165. public bool IsEnableEnable
  166. {
  167. get { return _IsEnableEnable; }
  168. set { SetProperty(ref _IsEnableEnable, value); }
  169. }
  170. public bool _IsEnableDisable;
  171. public bool IsEnableDisable
  172. {
  173. get { return _IsEnableDisable; }
  174. set { SetProperty(ref _IsEnableDisable, value); }
  175. }
  176. public bool IsExcludeInfoType
  177. {
  178. get { return m_IsExcludeInfoType; }
  179. set { SetProperty(ref m_IsExcludeInfoType, value); }
  180. }
  181. public FACommunicationState FACommunicationState
  182. {
  183. get
  184. {
  185. return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
  186. : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
  187. }
  188. }
  189. public bool PMAIsInstalled
  190. {
  191. get { return m_PMAIsInstalled; }
  192. set { SetProperty(ref m_PMAIsInstalled, value); }
  193. }
  194. public bool PMBIsInstalled
  195. {
  196. get { return m_PMBIsInstalled; }
  197. set { SetProperty(ref m_PMBIsInstalled, value); }
  198. }
  199. public bool PMCIsInstalled
  200. {
  201. get { return m_PMCIsInstalled; }
  202. set { SetProperty(ref m_PMCIsInstalled, value); }
  203. }
  204. public bool PMDIsInstalled
  205. {
  206. get { return m_PMDIsInstalled; }
  207. set { SetProperty(ref m_PMDIsInstalled, value); }
  208. }
  209. public bool LLAIsInstalled
  210. {
  211. get { return m_LLAIsInstalled; }
  212. set { SetProperty(ref m_LLAIsInstalled, value); }
  213. }
  214. public bool LLBIsInstalled
  215. {
  216. get { return m_LLBIsInstalled; }
  217. set { SetProperty(ref m_LLBIsInstalled, value); }
  218. }
  219. public bool TMIsInstalled
  220. {
  221. get { return m_TMIsInstalled; }
  222. set { SetProperty(ref m_TMIsInstalled, value); }
  223. }
  224. public SolidColorBrush DefaultBrush = new SolidColorBrush(Colors.LightCyan);
  225. public bool EFEMIsInstalled
  226. {
  227. get { return m_EFEMIsInstalled; }
  228. set { SetProperty(ref m_EFEMIsInstalled, value); }
  229. }
  230. private bool m_SETMIsInstalled;
  231. private bool m_DETMIsInstalled;
  232. private bool m_VCE1IsInstalled;
  233. private bool m_VCEAIsInstalled;
  234. private bool m_VCEBIsInstalled;
  235. public bool SETMIsInstalled
  236. {
  237. get { return m_SETMIsInstalled; }
  238. set { SetProperty(ref m_SETMIsInstalled, value); }
  239. }
  240. public bool DETMIsInstalled
  241. {
  242. get { return m_DETMIsInstalled; }
  243. set { SetProperty(ref m_DETMIsInstalled, value); }
  244. }
  245. public bool VCE1IsInstalled
  246. {
  247. get { return m_VCE1IsInstalled; }
  248. set { SetProperty(ref m_VCE1IsInstalled, value); }
  249. }
  250. public bool VCEAIsInstalled
  251. {
  252. get { return m_VCEAIsInstalled; }
  253. set { SetProperty(ref m_VCEAIsInstalled, value); }
  254. }
  255. public bool VCEBIsInstalled
  256. {
  257. get { return m_VCEBIsInstalled; }
  258. set { SetProperty(ref m_VCEBIsInstalled, value); }
  259. }
  260. #endregion
  261. #region 命令
  262. //private DelegateCommand _SwichLanguageCommand;
  263. //public DelegateCommand SwichLanguageCommand =>
  264. // _SwichLanguageCommand ?? (_SwichLanguageCommand = new DelegateCommand(OnSwitchLanguage));
  265. private DelegateCommand _ResetCommand;
  266. public DelegateCommand ResetCommand =>
  267. _ResetCommand ?? (_ResetCommand = new DelegateCommand(OnReset));
  268. private DelegateCommand _ClearCommand;
  269. public DelegateCommand ClearCommand =>
  270. _ClearCommand ?? (_ClearCommand = new DelegateCommand(OnClear));
  271. private DelegateCommand _SkipCommand;
  272. public DelegateCommand SkipCommand =>
  273. _SkipCommand ?? (_SkipCommand = new DelegateCommand(OnSkip));
  274. //private DelegateCommand _BuzzerOffCommand;
  275. //public DelegateCommand BuzzerOffCommand =>
  276. // _BuzzerOffCommand ?? (_BuzzerOffCommand = new DelegateCommand(OnBuzzerOff));
  277. private DelegateCommand _FADisableCommand;
  278. public DelegateCommand FADisableCommand =>
  279. _FADisableCommand ?? (_FADisableCommand = new DelegateCommand(FaDisable));
  280. private DelegateCommand _FAEnableCommand;
  281. public DelegateCommand FAEnableCommand =>
  282. _FAEnableCommand ?? (_FAEnableCommand = new DelegateCommand(FaEnable));
  283. private DelegateCommand _ExcludeInfoCommand;
  284. public DelegateCommand ExcludeInfoCommand =>
  285. _ExcludeInfoCommand ?? (_ExcludeInfoCommand = new DelegateCommand(OnExcludeInfo));
  286. private DelegateCommand _LogoutCommand;
  287. public DelegateCommand LogoutCommand =>
  288. _LogoutCommand ?? (_LogoutCommand = new DelegateCommand(OnLogout));
  289. private DelegateCommand _SwitchBuzzerCommand;
  290. public DelegateCommand SwitchBuzzerCommand =>
  291. _SwitchBuzzerCommand ?? (_SwitchBuzzerCommand = new DelegateCommand(OnSwitchBuzzer));
  292. #endregion
  293. #region 构造函数
  294. public TopViewModel()
  295. {
  296. m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  297. string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
  298. PMAIsInstalled = allModules.Contains("PMA");
  299. PMBIsInstalled = allModules.Contains("PMB");
  300. PMCIsInstalled = allModules.Contains("PMC");
  301. PMDIsInstalled = allModules.Contains("PMD");
  302. LLAIsInstalled = allModules.Contains("LLA");
  303. LLBIsInstalled = allModules.Contains("LLB");
  304. TMIsInstalled = allModules.Contains("TM");
  305. EFEMIsInstalled = allModules.Contains("EFEM");
  306. SETMIsInstalled = allModules.Contains("SETM");
  307. DETMIsInstalled = allModules.Contains("DETM");
  308. VCE1IsInstalled = allModules.Contains("VCE1");
  309. VCEAIsInstalled = allModules.Contains("VCEA");
  310. VCEBIsInstalled = allModules.Contains("VCEB");
  311. //ModuleName = "PMA";
  312. addDataKeys();
  313. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  314. DispatcherTimer timer = new DispatcherTimer();
  315. timer.Interval = TimeSpan.FromSeconds(1);
  316. timer.Tick += timer_Tick;
  317. timer.Start();
  318. EventClient.Instance.OnEvent += Instance_OnEvent;
  319. EventClient.Instance.Start();
  320. Title = QueryDataClient.Instance.Service.GetConfig($"System.Name").ToString();
  321. UserName=GlobalUser.Instance.User.Name;
  322. //object obj = QueryDataClient.Instance.Service.GetData("System.PressureUnitType");
  323. //m_PressureType = (PressureType)Convert.ToInt32(obj);
  324. //m_ConfigType = (ConfigType)Enum.Parse(typeof(ConfigType), QueryDataClient.Instance.Service.GetData("System.ConfigType").ToString());
  325. //var islog= QueryDataClient.Instance.Service.GetConfig("System.IsLogExcludeInfoType");
  326. //if (m_ConfigType==ConfigType.Kepler2200)
  327. //{
  328. // isExcludeInfoType= (bool)QueryDataClient.Instance.Service.GetConfig("System.IsLogExcludeInfoType");
  329. //}
  330. }
  331. #endregion
  332. #region 方法
  333. void timer_Tick(object sender, EventArgs e)
  334. {
  335. TimeTick = DateTime.Now.ToString();
  336. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  337. SignalTowerData = CommonFunction.GetValue<AITSignalTowerData>(RtDataValues, $"System.SignalTower.DeviceData");
  338. HostCommunicationStatus = CommonFunction.GetValue<String>(RtDataValues, "System.CommunicationStatus");
  339. //IsEnableEnable = FACommunicationState == CommunicationState.Disabled;
  340. //IsEnableDisable = FACommunicationState != CommunicationState.Disabled;
  341. HostBack = HostCommunicationStatusBackground;
  342. IsEnableEnable = (HostCommunicationStatus == FACommunicationState.Disabled.ToString());
  343. IsEnableDisable = (HostCommunicationStatus != FACommunicationState.Disabled.ToString());
  344. }
  345. //private void OnSwitchLanguage()
  346. //{
  347. // List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
  348. // foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
  349. // {
  350. // if (dictionary.Source != null)
  351. // {
  352. // dictionaryList.Add(dictionary);
  353. // }
  354. // }
  355. // string requestedCulture1 = @"/Venus_Themes;component/Languages/StringResources.en-US.xaml";
  356. // string requestedCulture2 = @"/Venus_Themes;component/Languages/StringResources.zh-CN.xaml";
  357. // ResourceDictionary resourceDictionary1 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture1));
  358. // ResourceDictionary resourceDictionary2 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture2));
  359. // if (dictionaryList.IndexOf(resourceDictionary1) < dictionaryList.IndexOf(resourceDictionary2))
  360. // {
  361. // Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary1);
  362. // Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
  363. // }
  364. // else
  365. // {
  366. // Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary2);
  367. // Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2);
  368. // }
  369. //}
  370. private void OnReset()
  371. {
  372. InvokeClient.Instance.Service.DoOperation("System.Reset");
  373. }
  374. private void addDataKeys()
  375. {
  376. if (PMAIsInstalled)
  377. {
  378. m_RtDataKeys.Add("PMA.FsmState");
  379. m_RtDataKeys.Add("PMA.IsOnline");
  380. m_RtDataKeys.Add("PMA.IsInclude");
  381. }
  382. if (PMBIsInstalled)
  383. {
  384. m_RtDataKeys.Add("PMB.FsmState");
  385. m_RtDataKeys.Add("PMB.IsOnline");
  386. m_RtDataKeys.Add("PMB.IsInclude");
  387. }
  388. if (PMCIsInstalled)
  389. {
  390. m_RtDataKeys.Add("PMC.FsmState");
  391. m_RtDataKeys.Add("PMC.IsOnline");
  392. m_RtDataKeys.Add("PMC.IsInclude");
  393. }
  394. if (PMDIsInstalled)
  395. {
  396. m_RtDataKeys.Add("PMD.FsmState");
  397. m_RtDataKeys.Add("PMD.IsOnline");
  398. m_RtDataKeys.Add("PMD.IsInclude");
  399. }
  400. m_RtDataKeys.Add("TM.FsmState");
  401. m_RtDataKeys.Add("TM.IsOnline");
  402. if (VCE1IsInstalled)
  403. {
  404. m_RtDataKeys.Add("VCE1.IsOnline");
  405. m_RtDataKeys.Add("VCE1.FsmState");
  406. }
  407. if (VCEAIsInstalled)
  408. {
  409. m_RtDataKeys.Add("VCEA.IsOnline");
  410. m_RtDataKeys.Add("VCEA.FsmState");
  411. }
  412. if (VCEBIsInstalled)
  413. {
  414. m_RtDataKeys.Add("VCEB.IsOnline");
  415. m_RtDataKeys.Add("VCEB.FsmState");
  416. }
  417. if (EFEMIsInstalled)
  418. {
  419. m_RtDataKeys.Add("EFEM.FsmState");
  420. m_RtDataKeys.Add("EFEM.IsOnline");
  421. }
  422. m_RtDataKeys.Add("LLA.FsmState");
  423. m_RtDataKeys.Add("LLA.IsOnline");
  424. m_RtDataKeys.Add("LLA.IsInclude");
  425. m_RtDataKeys.Add("LLB.FsmState");
  426. m_RtDataKeys.Add("LLB.IsOnline");
  427. m_RtDataKeys.Add("LLB.IsInclude");
  428. m_RtDataKeys.Add("SYSTEM.FsmState");
  429. m_RtDataKeys.Add("System.IsAutoMode");
  430. m_RtDataKeys.Add($"System.SignalTower.DeviceData");
  431. m_RtDataKeys.Add("System.CommunicationStatus");
  432. }
  433. private void Instance_OnEvent(EventItem eventItem)
  434. {
  435. if (IsExcludeInfoType && eventItem.Level == EventLevel.Information)
  436. {
  437. return;
  438. }
  439. GlobalEvents.Instance.OnEventItemRaiseChanged(eventItem);
  440. switch (eventItem.Type)
  441. {
  442. case EventType.EventUI_Notify:
  443. Application.Current.Dispatcher.Invoke(delegate
  444. {
  445. EventLogList.Insert(0, eventItem);
  446. if (EventLogList.Count > logMaxCount)
  447. {
  448. EventLogList.RemoveAt(EventLogList.Count - 1);
  449. }
  450. if (eventItem.Level == EventLevel.Alarm)
  451. {
  452. alarmQuery.Enqueue(eventItem);
  453. //if (m_ConfigType == ConfigType.Kepler2200)
  454. //{
  455. // if (stopEntityId.Contains((eEvent)eventItem.Id) && eventItem.Source.Contains("PM"))
  456. // {
  457. // InvokeClient.Instance.Service.DoOperation($"{eventItem.Source}.PmError");
  458. // }
  459. //}
  460. }
  461. if (alarmQuery.Count > 0)
  462. {
  463. CurrentEventItem = alarmQuery.First();
  464. }
  465. else
  466. {
  467. CurrentEventItem = eventItem;
  468. }
  469. EventLogListSelectedIndex = 0;
  470. });
  471. break;
  472. case EventType.Dialog_Nofity:
  473. //PopDialog(obj);
  474. break;
  475. case EventType.KickOut_Notify:
  476. break;
  477. case EventType.Sound_Notify:
  478. break;
  479. case EventType.UIMessage_Notify:
  480. //PopUIMessage(obj);
  481. break;
  482. }
  483. }
  484. private void OnClear()
  485. {
  486. CurrentEventItem = null;
  487. alarmQuery.Clear();
  488. EventLogList.Clear();
  489. }
  490. private void OnSkip()
  491. {
  492. if (alarmQuery.Count > 0)
  493. {
  494. alarmQuery.Dequeue();
  495. if (alarmQuery.Count > 0)
  496. {
  497. CurrentEventItem = alarmQuery.First();
  498. }
  499. else
  500. {
  501. CurrentEventItem = null;
  502. }
  503. }
  504. }
  505. //private void OnBuzzerOff()
  506. //{
  507. // InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SignalTower.SwitchOffBuzzer");
  508. //}
  509. public void FaDisable()
  510. {
  511. InvokeClient.Instance.Service.DoOperation($"FACommand", "FADisable");
  512. }
  513. public void FaEnable()
  514. {
  515. InvokeClient.Instance.Service.DoOperation($"FACommand", "FAEnable");
  516. }
  517. public void OnExcludeInfo()
  518. {
  519. IsExcludeInfoType = !IsExcludeInfoType;
  520. }
  521. private void OnLogout()
  522. {
  523. var _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is Window) as Window;
  524. LogoutView heaterView = new LogoutView();
  525. heaterView.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  526. heaterView.Owner = _mainWindow;
  527. heaterView.Show();
  528. }
  529. private void OnSwitchBuzzer()
  530. {
  531. InvokeClient.Instance.Service.DoOperation($"System.{AITSignalTowerOperation.SwitchOffBuzzer}");
  532. }
  533. #endregion
  534. }
  535. }