AlarmViewModel.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections.Generic;
  2. using System.Windows.Media;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.UI.View.Common;
  5. using Aitex.Core.Utilities;
  6. using MECF.Framework.UI.Client.ClientBase;
  7. namespace MECF.Framework.UI.Client.CenterViews.Alarms.Alarm
  8. {
  9. public class AlarmViewModel : UiViewModelBase
  10. {
  11. [IgnorePropertyChange]
  12. public List<AlarmItem> AlarmEvents { get; set; }
  13. public AlarmViewModel()
  14. {
  15. Subscribe("System.LiveAlarmEvent");
  16. }
  17. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  18. {
  19. if (data.ContainsKey("System.LiveAlarmEvent"))
  20. UpdateAlarmEvent((List<EventItem>)data["System.LiveAlarmEvent"]);
  21. }
  22. public void UpdateAlarmEvent(List<EventItem> evItems)
  23. {
  24. var alarmEvents = new List<AlarmItem>();
  25. foreach (EventItem item in evItems)
  26. {
  27. var it = new AlarmItem()
  28. {
  29. Type = item.Level == EventLevel.Alarm ? "Alarm" : (item.Level == EventLevel.Information ? "Info" : "Warning"),
  30. OccuringTime = item.OccuringTime.ToString(),//item.OccuringTime.ToString("HH:mm:ss"),
  31. Description = item.Description,
  32. EventEnum = item.EventEnum,
  33. EventId = item.Id,
  34. Explaination = item.Explaination,
  35. Solution = item.Solution,
  36. };
  37. switch (item.Level)
  38. {
  39. case EventLevel.Alarm: it.TextColor = Brushes.Red; break;
  40. case EventLevel.Warning: it.TextColor = Brushes.Yellow; break;
  41. default: it.TextColor = Brushes.White; break;
  42. }
  43. alarmEvents.Add(it);
  44. }
  45. if (AlarmEvents == null || (alarmEvents.Count != AlarmEvents.Count))
  46. {
  47. AlarmEvents = alarmEvents;
  48. }
  49. else
  50. {
  51. bool isEqual = true;
  52. if (alarmEvents.Count == AlarmEvents.Count)
  53. {
  54. for (int i = 0; i < alarmEvents.Count; i++)
  55. {
  56. if (!alarmEvents[i].IsEqualTo(AlarmEvents[i]))
  57. {
  58. isEqual = false;
  59. break;
  60. }
  61. }
  62. }
  63. if (!isEqual)
  64. AlarmEvents = alarmEvents;
  65. }
  66. NotifyOfPropertyChange("AlarmEvents");
  67. }
  68. }
  69. }