TopViewModel.cs 21 KB

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