TopViewModel.cs 17 KB

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