TopViewModel.cs 19 KB

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