AlarmViewModel.cs 9.4 KB

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