TopViewModel.cs 20 KB

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