AlarmViewModel.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.UI.View.Common;
  8. using Aitex.Core.Utilities;
  9. using MECF.Framework.Common.Alarms;
  10. using MECF.Framework.UI.Client.ClientBase;
  11. using System.Linq;
  12. using MECF.Framework.Common.OperationCenter;
  13. using Aitex.Core.Util;
  14. namespace MECF.Framework.UI.Client.CenterViews.Alarms.Alarm
  15. {
  16. public class AlarmViewModel : UiViewModelBase
  17. {
  18. [Subscription("System.AlarmTableID")]
  19. public string CurrentAlarmTable { get; set; }
  20. [IgnorePropertyChange]
  21. public List<AlarmItem> AlarmEvents { get; set; }
  22. public int SelectedIndex { get; set; } = -1;
  23. private AlarmProvider _alarmProvider = new AlarmProvider();
  24. public Dictionary<string, Dictionary<string, EventItem>> AllGroupAlarmDic = new Dictionary<string, Dictionary<string, EventItem>>();
  25. //public List<AlarmDefine> AlarmParameterList { get; set; } = new List<AlarmDefine>();
  26. private string _txtAnalysisText;
  27. private long _currentEventID;
  28. private int _currentEventCount;
  29. private string _currentEventName;
  30. public string TxtAnalysisText
  31. {
  32. get
  33. {
  34. return _txtAnalysisText;
  35. }
  36. set
  37. {
  38. _txtAnalysisText = value;
  39. NotifyOfPropertyChange("TxtAnalysisText");
  40. }
  41. }
  42. private bool _clearIsEnabled;
  43. public bool ClearIsEnabled
  44. {
  45. get => _clearIsEnabled;
  46. set
  47. {
  48. _clearIsEnabled = value;
  49. NotifyOfPropertyChange("ClearIsEnabled");
  50. }
  51. }
  52. private bool _abortIsEnabled;
  53. public bool AbortIsEnabled
  54. {
  55. get => _abortIsEnabled;
  56. set
  57. {
  58. _abortIsEnabled = value;
  59. NotifyOfPropertyChange("AbortIsEnabled");
  60. }
  61. }
  62. private bool _retryIsEnabled;
  63. public bool RetryIsEnabled
  64. {
  65. get => _retryIsEnabled;
  66. set
  67. {
  68. _retryIsEnabled = value;
  69. NotifyOfPropertyChange("RetryIsEnabled");
  70. }
  71. }
  72. private bool _continueIsEnabled;
  73. public bool ContinueIsEnabled
  74. {
  75. get => _continueIsEnabled;
  76. set
  77. {
  78. _continueIsEnabled = value;
  79. NotifyOfPropertyChange("ContinueIsEnabled");
  80. }
  81. }
  82. private bool _stopIsEnabled;
  83. public bool StopIsEnabled
  84. {
  85. get => _stopIsEnabled;
  86. set
  87. {
  88. _stopIsEnabled = value;
  89. NotifyOfPropertyChange("StopIsEnabled");
  90. }
  91. }
  92. private bool _removeIsEnabled;
  93. public bool RemoveIsEnabled
  94. {
  95. get => _removeIsEnabled;
  96. set
  97. {
  98. _removeIsEnabled = value;
  99. NotifyOfPropertyChange("RemoveIsEnabled");
  100. }
  101. }
  102. private bool _aGVRetryIsEnabled;
  103. public bool AGVRetryIsEnabled
  104. {
  105. get => _aGVRetryIsEnabled;
  106. set
  107. {
  108. _aGVRetryIsEnabled = value;
  109. NotifyOfPropertyChange("AGVRetryIsEnabled");
  110. }
  111. }
  112. private string _targetModule;
  113. public string TargetModule
  114. {
  115. get
  116. {
  117. return _targetModule;
  118. }
  119. set
  120. {
  121. _targetModule = value;
  122. NotifyOfPropertyChange("TargetModule");
  123. }
  124. }
  125. public void SetActionIsEnabled(string action)
  126. {
  127. if (action == null || action == "")
  128. {
  129. ClearIsEnabled = false;
  130. AbortIsEnabled = false;
  131. RetryIsEnabled = false;
  132. ContinueIsEnabled = false;
  133. AGVRetryIsEnabled = false;
  134. RemoveIsEnabled = false;
  135. StopIsEnabled = false;
  136. }
  137. else
  138. {
  139. ClearIsEnabled = action.Contains("Clear") ? true : false;
  140. AbortIsEnabled = action.Contains("Abort") ? true : false;
  141. RetryIsEnabled = action.Contains("Retry") ? true : false;
  142. ContinueIsEnabled = action.Contains("Continue") ? true : false;
  143. AGVRetryIsEnabled = action.Contains("AGV RETRY") ? true : false;
  144. StopIsEnabled = action.Contains("Stop") ? true : false;
  145. RemoveIsEnabled = action.Contains("Remove") ? true : false;
  146. }
  147. }
  148. public void DGOnSelectionChanged()
  149. {
  150. //var e = (SelectionChangedEventArgs)obj;
  151. if (SelectedIndex > -1)
  152. {
  153. AlarmItem item = AlarmEvents[SelectedIndex];
  154. //var item = e.AddedItems[0] as AlarmItem;
  155. //var findAlarm = AllGroupAlarmDic[CurrentAlarmTable].Values.Where(x => x.EventEnum == item.EventEnum).FirstOrDefault();
  156. if (item != null)
  157. {
  158. SetActionIsEnabled(item.Action.ToString());
  159. TxtAnalysisText = string.Format("Event Type:{0}\r\n\r\nEvent ID:{1}\r\n\r\nTime:{2}\r\n\r\nDescription:{3}\r\n\r\nCause:{4}\r\n\r\nRecovery:{5}",
  160. item.Type,
  161. item.EventId,
  162. item.OccuringTime,
  163. item.Description,
  164. item.Explaination,
  165. item.Solution
  166. );
  167. }
  168. else
  169. {
  170. SetActionIsEnabled("");
  171. TxtAnalysisText = string.Format("Event Type:{0}\r\n\r\nEvent ID:{1}\r\n\r\nTime:{2}\r\n\r\nDescription:{3}",
  172. item.Type,
  173. item.EventId,
  174. item.OccuringTime,
  175. item.Description
  176. );
  177. }
  178. TargetModule = item.Source;
  179. _currentEventID = item.EventId;
  180. _currentEventCount = item.Count;
  181. _currentEventName = item.EventEnum;
  182. }
  183. }
  184. public AlarmViewModel()
  185. {
  186. Subscribe("System.LiveAlarmEvent");
  187. }
  188. protected override void OnViewLoaded(object view)
  189. {
  190. //var alarmDict = _alarmProvider.GetXmlAlarmList();
  191. //AllGroupAlarmDic = alarmDict;
  192. //foreach (var item in AllGroupAlarmList.Keys)
  193. //{
  194. // foreach (var subitem in AllGroupAlarmList[item].Keys)
  195. // {
  196. // AlarmParameterList.Add(AllGroupAlarmList[item][subitem]);
  197. // }
  198. //}
  199. base.OnViewLoaded(view);
  200. }
  201. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  202. {
  203. if (data.ContainsKey("System.LiveAlarmEvent"))
  204. UpdateAlarmEvent((List<EventItem>)data["System.LiveAlarmEvent"]);
  205. }
  206. public void UpdateAlarmEvent(List<EventItem> evItems)
  207. {
  208. var alarmEvents = new List<AlarmItem>();
  209. foreach (EventItem item in evItems.OrderByDescending(p=>p.OccuringTime))
  210. {
  211. var it = new AlarmItem()
  212. {
  213. Type = item.Level == EventLevel.Alarm ? "Alarm" : (item.Level == EventLevel.Information ? "Info" : "Warning"),
  214. OccuringTime = item.OccuringTime.ToString("yyyy/MM/dd HH:mm:ss"),
  215. Description = item.Description,
  216. EventEnum = item.EventEnum,
  217. EventId = item.Id,
  218. Explaination = item.Explaination,
  219. Solution = item.Solution,
  220. Source = item.Source,
  221. Count = item.Count,
  222. Action = item.Action,
  223. };
  224. switch (item.Level)
  225. {
  226. case EventLevel.Alarm: it.TextColor = Brushes.Red; break;
  227. case EventLevel.Warning: it.TextColor = Brushes.Yellow; break;
  228. default: it.TextColor = Brushes.White; break;
  229. }
  230. alarmEvents.Add(it);
  231. }
  232. if (AlarmEvents == null || (alarmEvents.Count != AlarmEvents.Count))
  233. {
  234. AlarmEvents = alarmEvents;
  235. }
  236. else
  237. {
  238. bool isEqual = true;
  239. if (alarmEvents.Count == AlarmEvents.Count)
  240. {
  241. for (int i = 0; i < alarmEvents.Count; i++)
  242. {
  243. if (!alarmEvents[i].IsEqualTo(AlarmEvents[i]))
  244. {
  245. isEqual = false;
  246. break;
  247. }
  248. }
  249. }
  250. if (!isEqual)
  251. AlarmEvents = alarmEvents;
  252. }
  253. NotifyOfPropertyChange("AlarmEvents");
  254. }
  255. public void AlarmAction(string target, string action)
  256. {
  257. InvokeClient.Instance.Service.DoOperation($"{target}.AlarmAction", action, _currentEventName);
  258. TxtAnalysisText = "";
  259. SetActionIsEnabled("");
  260. }
  261. }
  262. }