TopViewModel.cs 19 KB

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