MonitorViewModel.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Media;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.UI.MVVM;
  8. namespace Aitex.Core.UI.View.Common
  9. {
  10. public class AlarmItem
  11. {
  12. public string OccuringTime { get; set; }
  13. public string Description { get; set; }
  14. public Brush TextColor { get; set; }
  15. public string Type { get; set; }
  16. public bool IsEqualTo(AlarmItem item)
  17. {
  18. return item.OccuringTime == OccuringTime &&
  19. item.Description == Description &&
  20. item.Type == Type;
  21. }
  22. public long EventId { get; set; }
  23. public int Count { get; set; }
  24. public string Ceid { get; set; }
  25. public string EventEnum { get; set; }
  26. public string Explaination { get; set; }
  27. public string Solution { get; set; }
  28. public string Source { get; set; }
  29. public EventAction Action { get; set; }
  30. }
  31. public class MonitorViewModel : ViewModelBase
  32. {
  33. public List<AlarmItem> AlarmEvents { get; set; }
  34. public void UpdateAlarmEvent(List<EventItem> evItems)
  35. {
  36. var alarmEvents = new List<AlarmItem>();
  37. foreach (EventItem item in evItems)
  38. {
  39. var it = new AlarmItem()
  40. {
  41. Type = item.Level == EventLevel.Alarm ? "Alarm" : (item.Level == EventLevel.Information ? "Info" : "Warning"),
  42. OccuringTime = item.OccuringTime.ToString("HH:mm:ss"),
  43. Description = item.Description,
  44. EventEnum = item.EventEnum,
  45. EventId = item.Id,
  46. Explaination = item.Explaination,
  47. Solution = item.Solution,
  48. Action = item.Action
  49. };
  50. switch (item.Level)
  51. {
  52. case EventLevel.Alarm: it.TextColor = Brushes.Red; break;
  53. case EventLevel.Warning: it.TextColor = Brushes.Yellow; break;
  54. default: it.TextColor = Brushes.White; break;
  55. }
  56. alarmEvents.Add(it);
  57. }
  58. if (AlarmEvents == null || (alarmEvents.Count != AlarmEvents.Count))
  59. {
  60. AlarmEvents = alarmEvents;
  61. }
  62. else
  63. {
  64. bool isEqual = true;
  65. if (alarmEvents.Count == AlarmEvents.Count)
  66. {
  67. for (int i = 0; i < alarmEvents.Count; i++)
  68. {
  69. if (!alarmEvents[i].IsEqualTo(AlarmEvents[i]))
  70. {
  71. isEqual = false;
  72. break;
  73. }
  74. }
  75. }
  76. if (!isEqual)
  77. AlarmEvents = alarmEvents;
  78. }
  79. InvokePropertyChanged("AlarmEvents");
  80. }
  81. }
  82. }