TopViewModel.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.WCF;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.OperationCenter;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Threading;
  17. using Venus_Core;
  18. using Venus_MainPages.Unity;
  19. using Venus_Themes.UserControls;
  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 List<string> m_RtDataKeys=new List<string>();
  28. private Dictionary<string, object> m_RtDataValues;
  29. private string ModuleName;
  30. private ObservableCollection<EventItem> m_EventLogList = new ObservableCollection<EventItem>();
  31. private EventItem m_CurrentEventItem=new EventItem ();
  32. private string m_CurrentEventItemValue;
  33. private object _lockObj = new object();
  34. private int m_EventLogListSelectedIndex;
  35. private Queue<EventItem> alarmQuery = new Queue<EventItem>();//控制alarm log 在 top UI显示
  36. private int logMaxCount = 50;//log在ui最多显示数量
  37. private AITSignalTowerData m_SignalTowerData;
  38. private JetChamber m_SelectedJetChamber = JetChamber.None;
  39. #endregion
  40. #region 属性
  41. public string Title
  42. {
  43. get { return m_Title; }
  44. set { SetProperty(ref m_Title, value); }
  45. }
  46. public string SoftwareVersion
  47. {
  48. get { return m_SoftwareVersion; }
  49. set { SetProperty(ref m_SoftwareVersion, value); }
  50. }
  51. public Dictionary<string, object> RtDataValues
  52. {
  53. get { return m_RtDataValues; }
  54. set { SetProperty(ref m_RtDataValues, value); }
  55. }
  56. public ObservableCollection<EventItem> EventLogList
  57. {
  58. get { return m_EventLogList; }
  59. set { SetProperty(ref m_EventLogList, value); }
  60. }
  61. public EventItem CurrentEventItem
  62. {
  63. get { return m_CurrentEventItem; }
  64. set { SetProperty(ref m_CurrentEventItem, value); }
  65. }
  66. public int EventLogListSelectedIndex
  67. {
  68. get { return m_EventLogListSelectedIndex; }
  69. set { SetProperty(ref m_EventLogListSelectedIndex, value); }
  70. }
  71. public string CurrentEventItemValue
  72. {
  73. get { return m_CurrentEventItemValue; }
  74. set { SetProperty(ref m_CurrentEventItemValue, value); }
  75. }
  76. public AITSignalTowerData SignalTowerData
  77. {
  78. get { return m_SignalTowerData; }
  79. set { SetProperty(ref m_SignalTowerData, value); }
  80. }
  81. #endregion
  82. #region 命令
  83. private DelegateCommand _SwichLanguageCommand;
  84. public DelegateCommand SwichLanguageCommand =>
  85. _SwichLanguageCommand ?? (_SwichLanguageCommand = new DelegateCommand(OnSwitchLanguage));
  86. private DelegateCommand _ResetCommand;
  87. public DelegateCommand ResetCommand =>
  88. _ResetCommand ?? (_ResetCommand = new DelegateCommand(OnReset));
  89. private DelegateCommand _ClearCommand;
  90. public DelegateCommand ClearCommand =>
  91. _ClearCommand ?? (_ClearCommand = new DelegateCommand(OnClear));
  92. private DelegateCommand _SkipCommand;
  93. public DelegateCommand SkipCommand =>
  94. _SkipCommand ?? (_SkipCommand = new DelegateCommand(OnSkip));
  95. private DelegateCommand _BuzzerOffCommand;
  96. public DelegateCommand BuzzerOffCommand =>
  97. _BuzzerOffCommand ?? (_BuzzerOffCommand = new DelegateCommand(OnBuzzerOff));
  98. #endregion
  99. #region 构造函数
  100. public TopViewModel()
  101. {
  102. JetChamber selectedChamber = (JetChamber)(Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig("System.ChamberSelect")));
  103. Title = selectedChamber.ToString();
  104. m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  105. ModuleName = "PMA";
  106. addDataKeys();
  107. DispatcherTimer timer = new DispatcherTimer();
  108. timer.Interval = TimeSpan.FromSeconds(1);
  109. timer.Tick += timer_Tick;
  110. timer.Start();
  111. EventClient.Instance.OnEvent += Instance_OnEvent;
  112. EventClient.Instance.Start();
  113. }
  114. #endregion
  115. #region 方法
  116. void timer_Tick(object sender, EventArgs e)
  117. {
  118. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  119. SignalTowerData = CommonFunction.GetValue<AITSignalTowerData>(RtDataValues, $"{ModuleName}.SignalTower.DeviceData");
  120. }
  121. private void OnSwitchLanguage()
  122. {
  123. List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
  124. foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
  125. {
  126. if (dictionary.Source != null)
  127. {
  128. dictionaryList.Add(dictionary);
  129. }
  130. }
  131. string requestedCulture1 = @"/Venus_Themes;component/Languages/StringResources.en-US.xaml";
  132. string requestedCulture2 = @"/Venus_Themes;component/Languages/StringResources.zh-CN.xaml";
  133. ResourceDictionary resourceDictionary1 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture1));
  134. ResourceDictionary resourceDictionary2 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture2));
  135. if (dictionaryList.IndexOf(resourceDictionary1) < dictionaryList.IndexOf(resourceDictionary2))
  136. {
  137. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary1);
  138. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
  139. }
  140. else
  141. {
  142. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary2);
  143. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2);
  144. }
  145. }
  146. private void OnReset()
  147. {
  148. InvokeClient.Instance.Service.DoOperation("System.Reset");
  149. }
  150. private void addDataKeys()
  151. {
  152. m_RtDataKeys.Add("PMA.FsmState");
  153. m_RtDataKeys.Add("PMB.FsmState");
  154. m_RtDataKeys.Add("PMC.FsmState");
  155. m_RtDataKeys.Add("PMD.FsmState");
  156. m_RtDataKeys.Add("TM.FsmState");
  157. m_RtDataKeys.Add("LLA.FsmState");
  158. m_RtDataKeys.Add("LLB.FsmState");
  159. m_RtDataKeys.Add("EFEM.FsmState");
  160. m_RtDataKeys.Add("SYSTEM.FsmState");
  161. m_RtDataKeys.Add("PMA.IsSlitDoorClosed");
  162. m_RtDataKeys.Add($"{ModuleName}.SignalTower.DeviceData");
  163. }
  164. private void Instance_OnEvent(EventItem eventItem)
  165. {
  166. GlobalEvents.Instance.OnEventItemRaiseChanged(eventItem);
  167. switch (eventItem.Type)
  168. {
  169. case EventType.EventUI_Notify:
  170. Application.Current.Dispatcher.Invoke(delegate
  171. {
  172. EventLogList.Insert(0,eventItem);
  173. if (EventLogList.Count > logMaxCount)
  174. {
  175. EventLogList.RemoveAt(EventLogList.Count-1);
  176. }
  177. if (eventItem.Level == EventLevel.Alarm)
  178. {
  179. alarmQuery.Enqueue(eventItem);
  180. }
  181. if (alarmQuery.Count > 0)
  182. {
  183. CurrentEventItem = alarmQuery.First();
  184. }
  185. else
  186. {
  187. CurrentEventItem = eventItem;
  188. }
  189. EventLogListSelectedIndex = 0;
  190. });
  191. break;
  192. case EventType.Dialog_Nofity:
  193. //PopDialog(obj);
  194. break;
  195. case EventType.KickOut_Notify:
  196. break;
  197. case EventType.Sound_Notify:
  198. break;
  199. case EventType.UIMessage_Notify:
  200. //PopUIMessage(obj);
  201. break;
  202. }
  203. }
  204. private void OnClear()
  205. {
  206. CurrentEventItem = null;
  207. alarmQuery.Clear();
  208. EventLogList.Clear();
  209. }
  210. private void OnSkip()
  211. {
  212. if (alarmQuery.Count > 0)
  213. {
  214. alarmQuery.Dequeue();
  215. if (alarmQuery.Count > 0)
  216. {
  217. CurrentEventItem = alarmQuery.First();
  218. }
  219. else
  220. {
  221. CurrentEventItem = null;
  222. }
  223. }
  224. }
  225. private void OnBuzzerOff()
  226. {
  227. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SignalTower.SwitchOffBuzzer");
  228. }
  229. #endregion
  230. }
  231. }