TopViewModel.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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.Windows;
  16. using System.Windows.Media;
  17. using System.Windows.Threading;
  18. using Venus_Core;
  19. using Venus_MainPages.Unity;
  20. namespace Venus_MainPages.ViewModels
  21. {
  22. internal class TopViewModel : BindableBase
  23. {
  24. #region 私有字段
  25. private string m_Title;
  26. private string m_SoftwareVersion;
  27. //private DateTime m_DateTimeNow;
  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. private List<eEvent> stopEntityId = new List<eEvent>()
  51. {
  52. eEvent.ERR_MATCH,
  53. eEvent.ERR_RF,
  54. eEvent.ERR_PENDULUM_VALVE,
  55. eEvent.ERR_DEVICE_INFO,
  56. eEvent.ERR_DRY_PUMP
  57. };
  58. //private PressureType m_PressureType;
  59. private ConfigType m_ConfigType;
  60. private bool m_IsExcludeInfoType;
  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 bool IsExcludeInfoType
  169. {
  170. get { return m_IsExcludeInfoType; }
  171. set { SetProperty(ref m_IsExcludeInfoType, value); }
  172. }
  173. public FACommunicationState FACommunicationState
  174. {
  175. get
  176. {
  177. return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
  178. : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
  179. }
  180. }
  181. public bool PMAIsInstalled
  182. {
  183. get { return m_PMAIsInstalled; }
  184. set { SetProperty(ref m_PMAIsInstalled, value); }
  185. }
  186. public bool PMBIsInstalled
  187. {
  188. get { return m_PMBIsInstalled; }
  189. set { SetProperty(ref m_PMBIsInstalled, value); }
  190. }
  191. public bool PMCIsInstalled
  192. {
  193. get { return m_PMCIsInstalled; }
  194. set { SetProperty(ref m_PMCIsInstalled, value); }
  195. }
  196. public bool PMDIsInstalled
  197. {
  198. get { return m_PMDIsInstalled; }
  199. set { SetProperty(ref m_PMDIsInstalled, value); }
  200. }
  201. public bool LLAIsInstalled
  202. {
  203. get { return m_LLAIsInstalled; }
  204. set { SetProperty(ref m_LLAIsInstalled, value); }
  205. }
  206. public bool LLBIsInstalled
  207. {
  208. get { return m_LLBIsInstalled; }
  209. set { SetProperty(ref m_LLBIsInstalled, value); }
  210. }
  211. public bool TMIsInstalled
  212. {
  213. get { return m_TMIsInstalled; }
  214. set { SetProperty(ref m_TMIsInstalled, value); }
  215. }
  216. public SolidColorBrush DefaultBrush = new SolidColorBrush(Colors.LightCyan);
  217. public bool EFEMIsInstalled
  218. {
  219. get { return m_EFEMIsInstalled; }
  220. set { SetProperty(ref m_EFEMIsInstalled, value); }
  221. }
  222. private bool m_SETMIsInstalled;
  223. private bool m_VCE1IsInstalled;
  224. public bool SETMIsInstalled
  225. {
  226. get { return m_SETMIsInstalled; }
  227. set { SetProperty(ref m_SETMIsInstalled, value); }
  228. }
  229. public bool VCE1IsInstalled
  230. {
  231. get { return m_VCE1IsInstalled; }
  232. set { SetProperty(ref m_VCE1IsInstalled, value); }
  233. }
  234. #endregion
  235. #region 命令
  236. private DelegateCommand _SwichLanguageCommand;
  237. public DelegateCommand SwichLanguageCommand =>
  238. _SwichLanguageCommand ?? (_SwichLanguageCommand = new DelegateCommand(OnSwitchLanguage));
  239. private DelegateCommand _ResetCommand;
  240. public DelegateCommand ResetCommand =>
  241. _ResetCommand ?? (_ResetCommand = new DelegateCommand(OnReset));
  242. private DelegateCommand _ClearCommand;
  243. public DelegateCommand ClearCommand =>
  244. _ClearCommand ?? (_ClearCommand = new DelegateCommand(OnClear));
  245. private DelegateCommand _SkipCommand;
  246. public DelegateCommand SkipCommand =>
  247. _SkipCommand ?? (_SkipCommand = new DelegateCommand(OnSkip));
  248. //private DelegateCommand _BuzzerOffCommand;
  249. //public DelegateCommand BuzzerOffCommand =>
  250. // _BuzzerOffCommand ?? (_BuzzerOffCommand = new DelegateCommand(OnBuzzerOff));
  251. private DelegateCommand _FADisableCommand;
  252. public DelegateCommand FADisableCommand =>
  253. _FADisableCommand ?? (_FADisableCommand = new DelegateCommand(FaDisable));
  254. private DelegateCommand _FAEnableCommand;
  255. public DelegateCommand FAEnableCommand =>
  256. _FAEnableCommand ?? (_FAEnableCommand = new DelegateCommand(FaEnable));
  257. private DelegateCommand _ExcludeInfoCommand;
  258. public DelegateCommand ExcludeInfoCommand =>
  259. _ExcludeInfoCommand ?? (_ExcludeInfoCommand = new DelegateCommand(OnExcludeInfo));
  260. #endregion
  261. #region 构造函数
  262. public TopViewModel()
  263. {
  264. m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  265. string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
  266. PMAIsInstalled = allModules.Contains("PMA");
  267. PMBIsInstalled = allModules.Contains("PMB");
  268. PMCIsInstalled = allModules.Contains("PMC");
  269. PMDIsInstalled = allModules.Contains("PMD");
  270. LLAIsInstalled = allModules.Contains("LLA");
  271. LLBIsInstalled = allModules.Contains("LLB");
  272. TMIsInstalled = allModules.Contains("TM");
  273. EFEMIsInstalled = allModules.Contains("EFEM");
  274. SETMIsInstalled = allModules.Contains("SETM");
  275. VCE1IsInstalled = allModules.Contains("VCE1");
  276. //ModuleName = "PMA";
  277. addDataKeys();
  278. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  279. DispatcherTimer timer = new DispatcherTimer();
  280. timer.Interval = TimeSpan.FromSeconds(0.5);
  281. timer.Tick += timer_Tick;
  282. timer.Start();
  283. EventClient.Instance.OnEvent += Instance_OnEvent;
  284. EventClient.Instance.Start();
  285. Title = QueryDataClient.Instance.Service.GetConfig($"System.Name").ToString();
  286. //object obj = QueryDataClient.Instance.Service.GetData("System.PressureUnitType");
  287. //m_PressureType = (PressureType)Convert.ToInt32(obj);
  288. m_ConfigType = (ConfigType)Enum.Parse(typeof(ConfigType), QueryDataClient.Instance.Service.GetData("System.ConfigType").ToString());
  289. //var islog= QueryDataClient.Instance.Service.GetConfig("System.IsLogExcludeInfoType");
  290. //if (m_ConfigType==ConfigType.Kepler2200)
  291. //{
  292. // isExcludeInfoType= (bool)QueryDataClient.Instance.Service.GetConfig("System.IsLogExcludeInfoType");
  293. //}
  294. }
  295. #endregion
  296. #region 方法
  297. void timer_Tick(object sender, EventArgs e)
  298. {
  299. TimeTick = DateTime.Now.ToString();
  300. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  301. SignalTowerData = CommonFunction.GetValue<AITSignalTowerData>(RtDataValues, $"System.SignalTower.DeviceData");
  302. HostCommunicationStatus = CommonFunction.GetValue<String>(RtDataValues, "System.CommunicationStatus");
  303. //IsEnableEnable = FACommunicationState == CommunicationState.Disabled;
  304. //IsEnableDisable = FACommunicationState != CommunicationState.Disabled;
  305. HostBack = HostCommunicationStatusBackground;
  306. IsEnableEnable = (HostCommunicationStatus == FACommunicationState.Disabled.ToString());
  307. IsEnableDisable = (HostCommunicationStatus != FACommunicationState.Disabled.ToString());
  308. }
  309. private void OnSwitchLanguage()
  310. {
  311. List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
  312. foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
  313. {
  314. if (dictionary.Source != null)
  315. {
  316. dictionaryList.Add(dictionary);
  317. }
  318. }
  319. string requestedCulture1 = @"/Venus_Themes;component/Languages/StringResources.en-US.xaml";
  320. string requestedCulture2 = @"/Venus_Themes;component/Languages/StringResources.zh-CN.xaml";
  321. ResourceDictionary resourceDictionary1 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture1));
  322. ResourceDictionary resourceDictionary2 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture2));
  323. if (dictionaryList.IndexOf(resourceDictionary1) < dictionaryList.IndexOf(resourceDictionary2))
  324. {
  325. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary1);
  326. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
  327. }
  328. else
  329. {
  330. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary2);
  331. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2);
  332. }
  333. }
  334. private void OnReset()
  335. {
  336. InvokeClient.Instance.Service.DoOperation("System.Reset");
  337. }
  338. private void addDataKeys()
  339. {
  340. m_RtDataKeys.Add("PMA.FsmState");
  341. m_RtDataKeys.Add("PMA.IsOnline");
  342. m_RtDataKeys.Add("PMA.IsInclude");
  343. m_RtDataKeys.Add("PMB.FsmState");
  344. m_RtDataKeys.Add("PMB.IsOnline");
  345. m_RtDataKeys.Add("PMB.IsInclude");
  346. m_RtDataKeys.Add("PMC.FsmState");
  347. m_RtDataKeys.Add("PMC.IsOnline");
  348. m_RtDataKeys.Add("PMC.IsInclude");
  349. m_RtDataKeys.Add("PMD.FsmState");
  350. m_RtDataKeys.Add("PMD.IsOnline");
  351. m_RtDataKeys.Add("PMD.IsInclude");
  352. m_RtDataKeys.Add("TM.FsmState");
  353. m_RtDataKeys.Add("TM.IsOnline");
  354. m_RtDataKeys.Add("SETM.IsOnline");
  355. m_RtDataKeys.Add("LLA.FsmState");
  356. m_RtDataKeys.Add("LLA.IsOnline");
  357. m_RtDataKeys.Add("LLA.IsInclude");
  358. m_RtDataKeys.Add("LLB.FsmState");
  359. m_RtDataKeys.Add("LLB.IsOnline");
  360. m_RtDataKeys.Add("LLB.IsInclude");
  361. m_RtDataKeys.Add("EFEM.FsmState");
  362. m_RtDataKeys.Add("EFEM.IsOnline");
  363. m_RtDataKeys.Add("SETM.FsmState");
  364. m_RtDataKeys.Add("VCE1.FsmState");
  365. m_RtDataKeys.Add("SYSTEM.FsmState");
  366. m_RtDataKeys.Add("System.IsAutoMode");
  367. m_RtDataKeys.Add($"System.SignalTower.DeviceData");
  368. m_RtDataKeys.Add("System.CommunicationStatus");
  369. }
  370. private void Instance_OnEvent(EventItem eventItem)
  371. {
  372. if (IsExcludeInfoType && eventItem.Level == EventLevel.Information)
  373. {
  374. return;
  375. }
  376. GlobalEvents.Instance.OnEventItemRaiseChanged(eventItem);
  377. switch (eventItem.Type)
  378. {
  379. case EventType.EventUI_Notify:
  380. Application.Current.Dispatcher.Invoke(delegate
  381. {
  382. EventLogList.Insert(0, eventItem);
  383. if (EventLogList.Count > logMaxCount)
  384. {
  385. EventLogList.RemoveAt(EventLogList.Count - 1);
  386. }
  387. if (eventItem.Level == EventLevel.Alarm)
  388. {
  389. alarmQuery.Enqueue(eventItem);
  390. if (m_ConfigType==ConfigType.Kepler2200)
  391. {
  392. if (stopEntityId.Contains((eEvent)eventItem.Id) && eventItem.Source.Contains("PM"))
  393. {
  394. InvokeClient.Instance.Service.DoOperation($"{eventItem.Source}.PmError");
  395. }
  396. }
  397. }
  398. if (alarmQuery.Count > 0)
  399. {
  400. CurrentEventItem = alarmQuery.First();
  401. }
  402. else
  403. {
  404. CurrentEventItem = eventItem;
  405. }
  406. EventLogListSelectedIndex = 0;
  407. });
  408. break;
  409. case EventType.Dialog_Nofity:
  410. //PopDialog(obj);
  411. break;
  412. case EventType.KickOut_Notify:
  413. break;
  414. case EventType.Sound_Notify:
  415. break;
  416. case EventType.UIMessage_Notify:
  417. //PopUIMessage(obj);
  418. break;
  419. }
  420. }
  421. private void OnClear()
  422. {
  423. CurrentEventItem = null;
  424. alarmQuery.Clear();
  425. EventLogList.Clear();
  426. }
  427. private void OnSkip()
  428. {
  429. if (alarmQuery.Count > 0)
  430. {
  431. alarmQuery.Dequeue();
  432. if (alarmQuery.Count > 0)
  433. {
  434. CurrentEventItem = alarmQuery.First();
  435. }
  436. else
  437. {
  438. CurrentEventItem = null;
  439. }
  440. }
  441. }
  442. //private void OnBuzzerOff()
  443. //{
  444. // InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SignalTower.SwitchOffBuzzer");
  445. //}
  446. public void FaDisable()
  447. {
  448. InvokeClient.Instance.Service.DoOperation($"FACommand", "FADisable");
  449. }
  450. public void FaEnable()
  451. {
  452. InvokeClient.Instance.Service.DoOperation($"FACommand", "FAEnable");
  453. }
  454. public void OnExcludeInfo()
  455. {
  456. IsExcludeInfoType = !IsExcludeInfoType;
  457. }
  458. #endregion
  459. }
  460. }