TopViewModel.cs 15 KB

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