TopViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.WCF;
  4. using FabConnect.SecsGemInterface.GemModel;
  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. public string HostCommunicationStatus
  127. {
  128. get { return m_HostCommunicationStatus; }
  129. set { SetProperty(ref m_HostCommunicationStatus, value); }
  130. }
  131. public bool IsEnableFAEnable
  132. {
  133. get
  134. {
  135. return HostCommunicationStatus == "Disabled";
  136. }
  137. }
  138. public bool _IsDisableEnable;
  139. public bool IsEnableEnable
  140. {
  141. get { return _IsDisableEnable; }
  142. set { SetProperty(ref _IsDisableEnable, value); }
  143. }
  144. public bool _IsEnableDisable;
  145. public bool IsEnableDisable
  146. {
  147. get { return _IsEnableDisable; }
  148. set { SetProperty(ref _IsEnableDisable, value); }
  149. }
  150. public bool IsDisableFAEnable
  151. {
  152. get
  153. {
  154. return HostCommunicationStatus != "Disabled";
  155. }
  156. }
  157. public CommunicationState FACommunicationState
  158. {
  159. get
  160. {
  161. return string.IsNullOrEmpty(HostCommunicationStatus) ? CommunicationState.Disabled
  162. : (CommunicationState)Enum.Parse(typeof(CommunicationState), HostCommunicationStatus);
  163. }
  164. }
  165. public bool PMAIsInstalled
  166. {
  167. get { return m_PMAIsInstalled; }
  168. set { SetProperty(ref m_PMAIsInstalled, value); }
  169. }
  170. public bool PMBIsInstalled
  171. {
  172. get { return m_PMBIsInstalled; }
  173. set { SetProperty(ref m_PMBIsInstalled, value); }
  174. }
  175. public bool PMCIsInstalled
  176. {
  177. get { return m_PMCIsInstalled; }
  178. set { SetProperty(ref m_PMCIsInstalled, value); }
  179. }
  180. public bool PMDIsInstalled
  181. {
  182. get { return m_PMDIsInstalled; }
  183. set { SetProperty(ref m_PMDIsInstalled, value); }
  184. }
  185. public bool LLAIsInstalled
  186. {
  187. get { return m_LLAIsInstalled; }
  188. set { SetProperty(ref m_LLAIsInstalled, value); }
  189. }
  190. public bool LLBIsInstalled
  191. {
  192. get { return m_LLBIsInstalled; }
  193. set { SetProperty(ref m_LLBIsInstalled, value); }
  194. }
  195. public bool TMIsInstalled
  196. {
  197. get { return m_TMIsInstalled; }
  198. set { SetProperty(ref m_TMIsInstalled, value); }
  199. }
  200. public bool EFEMIsInstalled
  201. {
  202. get { return m_EFEMIsInstalled; }
  203. set { SetProperty(ref m_EFEMIsInstalled, value); }
  204. }
  205. private bool m_SETMIsInstalled;
  206. private bool m_VCE1IsInstalled;
  207. public bool SETMIsInstalled
  208. {
  209. get { return m_SETMIsInstalled; }
  210. set { SetProperty(ref m_SETMIsInstalled, value); }
  211. }
  212. public bool VCE1IsInstalled
  213. {
  214. get { return m_VCE1IsInstalled; }
  215. set { SetProperty(ref m_VCE1IsInstalled, value); }
  216. }
  217. #endregion
  218. #region 命令
  219. private DelegateCommand _SwichLanguageCommand;
  220. public DelegateCommand SwichLanguageCommand =>
  221. _SwichLanguageCommand ?? (_SwichLanguageCommand = new DelegateCommand(OnSwitchLanguage));
  222. private DelegateCommand _ResetCommand;
  223. public DelegateCommand ResetCommand =>
  224. _ResetCommand ?? (_ResetCommand = new DelegateCommand(OnReset));
  225. private DelegateCommand _ClearCommand;
  226. public DelegateCommand ClearCommand =>
  227. _ClearCommand ?? (_ClearCommand = new DelegateCommand(OnClear));
  228. private DelegateCommand _SkipCommand;
  229. public DelegateCommand SkipCommand =>
  230. _SkipCommand ?? (_SkipCommand = new DelegateCommand(OnSkip));
  231. //private DelegateCommand _BuzzerOffCommand;
  232. //public DelegateCommand BuzzerOffCommand =>
  233. // _BuzzerOffCommand ?? (_BuzzerOffCommand = new DelegateCommand(OnBuzzerOff));
  234. private DelegateCommand _FADisableCommand;
  235. public DelegateCommand FADisableCommand =>
  236. _FADisableCommand ?? (_FADisableCommand = new DelegateCommand(FaDisable));
  237. private DelegateCommand _FAEnableCommand;
  238. public DelegateCommand FAEnableCommand =>
  239. _FAEnableCommand ?? (_FAEnableCommand = new DelegateCommand(FaEnable));
  240. #endregion
  241. #region 构造函数
  242. public TopViewModel()
  243. {
  244. m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  245. string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
  246. PMAIsInstalled = allModules.Contains("PMA");
  247. PMBIsInstalled = allModules.Contains("PMB");
  248. PMCIsInstalled = allModules.Contains("PMC");
  249. PMDIsInstalled = allModules.Contains("PMD");
  250. LLAIsInstalled = allModules.Contains("LLA");
  251. LLBIsInstalled = allModules.Contains("LLB");
  252. TMIsInstalled = allModules.Contains("TM");
  253. EFEMIsInstalled = allModules.Contains("EFEM");
  254. SETMIsInstalled = allModules.Contains("SETM");
  255. VCE1IsInstalled = allModules.Contains("VCE1");
  256. //ModuleName = "PMA";
  257. addDataKeys();
  258. DispatcherTimer timer = new DispatcherTimer();
  259. timer.Interval = TimeSpan.FromSeconds(0.5);
  260. timer.Tick += timer_Tick;
  261. timer.Start();
  262. EventClient.Instance.OnEvent += Instance_OnEvent;
  263. EventClient.Instance.Start();
  264. }
  265. #endregion
  266. #region 方法
  267. void timer_Tick(object sender, EventArgs e)
  268. {
  269. TimeTick = DateTime.Now.ToString();
  270. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  271. SignalTowerData = CommonFunction.GetValue<AITSignalTowerData>(RtDataValues, $"System.SignalTower.DeviceData");
  272. HostCommunicationStatus = CommonFunction.GetValue<String>(RtDataValues, "System.CommunicationStatus");
  273. IsEnableEnable = FACommunicationState == CommunicationState.Disabled;
  274. IsEnableDisable = FACommunicationState != CommunicationState.Disabled;
  275. HostBack = HostCommunicationStatusBackground;
  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($"System.FACommand", "FADisable");
  435. }
  436. public void FaEnable()
  437. {
  438. InvokeClient.Instance.Service.DoOperation($"System.FACommand", "FAEnable");
  439. }
  440. #endregion
  441. }
  442. }