TopViewModel.cs 17 KB

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