TopViewModel.cs 17 KB

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