TopViewModel.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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("LLA.FsmState");
  384. m_RtDataKeys.Add("LLA.IsOnline");
  385. m_RtDataKeys.Add("LLA.IsInclude");
  386. m_RtDataKeys.Add("LLB.FsmState");
  387. m_RtDataKeys.Add("LLB.IsOnline");
  388. m_RtDataKeys.Add("LLB.IsInclude");
  389. m_RtDataKeys.Add("EFEM.FsmState");
  390. m_RtDataKeys.Add("EFEM.IsOnline");
  391. m_RtDataKeys.Add("SETM.FsmState");
  392. m_RtDataKeys.Add("DETM.FsmState");
  393. m_RtDataKeys.Add("VCE1.FsmState");
  394. m_RtDataKeys.Add("VCEA.FsmState");
  395. m_RtDataKeys.Add("VCEB.FsmState");
  396. m_RtDataKeys.Add("SYSTEM.FsmState");
  397. m_RtDataKeys.Add("System.IsAutoMode");
  398. m_RtDataKeys.Add($"System.SignalTower.DeviceData");
  399. m_RtDataKeys.Add("System.CommunicationStatus");
  400. }
  401. private void Instance_OnEvent(EventItem eventItem)
  402. {
  403. if (IsExcludeInfoType && eventItem.Level == EventLevel.Information)
  404. {
  405. return;
  406. }
  407. GlobalEvents.Instance.OnEventItemRaiseChanged(eventItem);
  408. switch (eventItem.Type)
  409. {
  410. case EventType.EventUI_Notify:
  411. Application.Current.Dispatcher.Invoke(delegate
  412. {
  413. EventLogList.Insert(0, eventItem);
  414. if (EventLogList.Count > logMaxCount)
  415. {
  416. EventLogList.RemoveAt(EventLogList.Count - 1);
  417. }
  418. if (eventItem.Level == EventLevel.Alarm)
  419. {
  420. alarmQuery.Enqueue(eventItem);
  421. if (m_ConfigType == ConfigType.Kepler2200)
  422. {
  423. if (stopEntityId.Contains((eEvent)eventItem.Id) && eventItem.Source.Contains("PM"))
  424. {
  425. InvokeClient.Instance.Service.DoOperation($"{eventItem.Source}.PmError");
  426. }
  427. }
  428. }
  429. if (alarmQuery.Count > 0)
  430. {
  431. CurrentEventItem = alarmQuery.First();
  432. }
  433. else
  434. {
  435. CurrentEventItem = eventItem;
  436. }
  437. EventLogListSelectedIndex = 0;
  438. });
  439. break;
  440. case EventType.Dialog_Nofity:
  441. //PopDialog(obj);
  442. break;
  443. case EventType.KickOut_Notify:
  444. break;
  445. case EventType.Sound_Notify:
  446. break;
  447. case EventType.UIMessage_Notify:
  448. //PopUIMessage(obj);
  449. break;
  450. }
  451. }
  452. private void OnClear()
  453. {
  454. CurrentEventItem = null;
  455. alarmQuery.Clear();
  456. EventLogList.Clear();
  457. }
  458. private void OnSkip()
  459. {
  460. if (alarmQuery.Count > 0)
  461. {
  462. alarmQuery.Dequeue();
  463. if (alarmQuery.Count > 0)
  464. {
  465. CurrentEventItem = alarmQuery.First();
  466. }
  467. else
  468. {
  469. CurrentEventItem = null;
  470. }
  471. }
  472. }
  473. //private void OnBuzzerOff()
  474. //{
  475. // InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SignalTower.SwitchOffBuzzer");
  476. //}
  477. public void FaDisable()
  478. {
  479. InvokeClient.Instance.Service.DoOperation($"FACommand", "FADisable");
  480. }
  481. public void FaEnable()
  482. {
  483. InvokeClient.Instance.Service.DoOperation($"FACommand", "FAEnable");
  484. }
  485. public void OnExcludeInfo()
  486. {
  487. IsExcludeInfoType = !IsExcludeInfoType;
  488. }
  489. private void OnLogout()
  490. {
  491. var _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is Window) as Window;
  492. LoginView heaterView = new LoginView(false);
  493. heaterView.Width = 1555;
  494. heaterView.Height = 874;
  495. heaterView.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  496. heaterView.Owner = _mainWindow;
  497. heaterView.Show();
  498. }
  499. private void OnSwitchBuzzer()
  500. {
  501. InvokeClient.Instance.Service.DoOperation($"System.{AITSignalTowerOperation.SwitchOffBuzzer}");
  502. }
  503. #endregion
  504. }
  505. }