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. Title = QueryDataClient.Instance.Service.GetConfig($"System.Name").ToString();
  262. }
  263. #endregion
  264. #region 方法
  265. void timer_Tick(object sender, EventArgs e)
  266. {
  267. TimeTick = DateTime.Now.ToString();
  268. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  269. SignalTowerData = CommonFunction.GetValue<AITSignalTowerData>(RtDataValues, $"System.SignalTower.DeviceData");
  270. HostCommunicationStatus = CommonFunction.GetValue<String>(RtDataValues, "System.CommunicationStatus");
  271. //IsEnableEnable = FACommunicationState == CommunicationState.Disabled;
  272. //IsEnableDisable = FACommunicationState != CommunicationState.Disabled;
  273. HostBack = HostCommunicationStatusBackground;
  274. IsEnableEnable = (HostCommunicationStatus == FACommunicationState.Disabled.ToString());
  275. IsEnableDisable = (HostCommunicationStatus != FACommunicationState.Disabled.ToString());
  276. }
  277. private void OnSwitchLanguage()
  278. {
  279. List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
  280. foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
  281. {
  282. if (dictionary.Source != null)
  283. {
  284. dictionaryList.Add(dictionary);
  285. }
  286. }
  287. string requestedCulture1 = @"/Venus_Themes;component/Languages/StringResources.en-US.xaml";
  288. string requestedCulture2 = @"/Venus_Themes;component/Languages/StringResources.zh-CN.xaml";
  289. ResourceDictionary resourceDictionary1 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture1));
  290. ResourceDictionary resourceDictionary2 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture2));
  291. if (dictionaryList.IndexOf(resourceDictionary1) < dictionaryList.IndexOf(resourceDictionary2))
  292. {
  293. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary1);
  294. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
  295. }
  296. else
  297. {
  298. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary2);
  299. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2);
  300. }
  301. }
  302. private void OnReset()
  303. {
  304. InvokeClient.Instance.Service.DoOperation("System.Reset");
  305. }
  306. private void addDataKeys()
  307. {
  308. if (PMAIsInstalled == true)
  309. {
  310. m_RtDataKeys.Add("PMA.FsmState");
  311. m_RtDataKeys.Add("PMA.IsOnline");
  312. }
  313. if (PMBIsInstalled == true)
  314. {
  315. m_RtDataKeys.Add("PMB.FsmState");
  316. m_RtDataKeys.Add("PMB.IsOnline");
  317. }
  318. if (PMCIsInstalled == true)
  319. {
  320. m_RtDataKeys.Add("PMC.FsmState");
  321. m_RtDataKeys.Add("PMC.IsOnline");
  322. }
  323. if (PMDIsInstalled == true)
  324. {
  325. m_RtDataKeys.Add("PMD.FsmState");
  326. m_RtDataKeys.Add("PMD.IsOnline");
  327. }
  328. if (TMIsInstalled == true)
  329. {
  330. m_RtDataKeys.Add("TM.FsmState");
  331. m_RtDataKeys.Add("TM.IsOnline");
  332. }
  333. if (LLAIsInstalled == true)
  334. {
  335. m_RtDataKeys.Add("LLA.FsmState");
  336. m_RtDataKeys.Add("LLA.IsOnline");
  337. }
  338. if (LLBIsInstalled == true)
  339. {
  340. m_RtDataKeys.Add("LLB.FsmState");
  341. m_RtDataKeys.Add("LLB.IsOnline");
  342. }
  343. if (EFEMIsInstalled == true)
  344. {
  345. m_RtDataKeys.Add("EFEM.FsmState");
  346. m_RtDataKeys.Add("EFEM.IsOnline");
  347. }
  348. if (SETMIsInstalled)
  349. {
  350. m_RtDataKeys.Add("SETM.FsmState");
  351. //m_RtDataKeys.Add("SETM.IsOnline");
  352. }
  353. if (VCE1IsInstalled)
  354. {
  355. m_RtDataKeys.Add("VCE1.FsmState");
  356. //m_RtDataKeys.Add("VCE1.IsOnline");
  357. }
  358. m_RtDataKeys.Add("SYSTEM.FsmState");
  359. m_RtDataKeys.Add("System.IsAutoMode");
  360. m_RtDataKeys.Add($"System.SignalTower.DeviceData");
  361. m_RtDataKeys.Add("System.CommunicationStatus");
  362. }
  363. private void Instance_OnEvent(EventItem eventItem)
  364. {
  365. GlobalEvents.Instance.OnEventItemRaiseChanged(eventItem);
  366. switch (eventItem.Type)
  367. {
  368. case EventType.EventUI_Notify:
  369. Application.Current.Dispatcher.Invoke(delegate
  370. {
  371. EventLogList.Insert(0, eventItem);
  372. if (EventLogList.Count > logMaxCount)
  373. {
  374. EventLogList.RemoveAt(EventLogList.Count - 1);
  375. }
  376. if (eventItem.Level == EventLevel.Alarm)
  377. {
  378. alarmQuery.Enqueue(eventItem);
  379. //if (stopEntityId.Contains(eventItem.Id) && eventItem.Source.Contains("PM"))
  380. //{
  381. // InvokeClient.Instance.Service.DoOperation($"{eventItem.Source}.PmError");
  382. //}
  383. }
  384. if (alarmQuery.Count > 0)
  385. {
  386. CurrentEventItem = alarmQuery.First();
  387. }
  388. else
  389. {
  390. CurrentEventItem = eventItem;
  391. }
  392. EventLogListSelectedIndex = 0;
  393. });
  394. break;
  395. case EventType.Dialog_Nofity:
  396. //PopDialog(obj);
  397. break;
  398. case EventType.KickOut_Notify:
  399. break;
  400. case EventType.Sound_Notify:
  401. break;
  402. case EventType.UIMessage_Notify:
  403. //PopUIMessage(obj);
  404. break;
  405. }
  406. }
  407. private void OnClear()
  408. {
  409. CurrentEventItem = null;
  410. alarmQuery.Clear();
  411. EventLogList.Clear();
  412. }
  413. private void OnSkip()
  414. {
  415. if (alarmQuery.Count > 0)
  416. {
  417. alarmQuery.Dequeue();
  418. if (alarmQuery.Count > 0)
  419. {
  420. CurrentEventItem = alarmQuery.First();
  421. }
  422. else
  423. {
  424. CurrentEventItem = null;
  425. }
  426. }
  427. }
  428. //private void OnBuzzerOff()
  429. //{
  430. // InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SignalTower.SwitchOffBuzzer");
  431. //}
  432. public void FaDisable()
  433. {
  434. InvokeClient.Instance.Service.DoOperation($"FACommand", "FADisable");
  435. }
  436. public void FaEnable()
  437. {
  438. InvokeClient.Instance.Service.DoOperation($"FACommand", "FAEnable");
  439. }
  440. #endregion
  441. }
  442. }