TopViewModel.cs 20 KB

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