TopViewModel.cs 19 KB

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