TopViewModel.cs 18 KB

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