MonitorViewModel.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 int EventId { get; set; }
  23. public string Ceid { get; set; }
  24. public string EventEnum { get; set; }
  25. public string Explaination { get; set; }
  26. public string Solution { get; set; }
  27. public string Source { get; set; }
  28. }
  29. public class MonitorViewModel : ViewModelBase
  30. {
  31. public List<AlarmItem> AlarmEvents { get; set; }
  32. public void UpdateAlarmEvent(List<EventItem> evItems)
  33. {
  34. var alarmEvents = new List<AlarmItem>();
  35. foreach (EventItem item in evItems)
  36. {
  37. var it = new AlarmItem()
  38. {
  39. Type = item.Level == EventLevel.Alarm ? "Alarm" : (item.Level == EventLevel.Information ? "Info" : "Warning"),
  40. OccuringTime = item.OccuringTime.ToString("HH:mm:ss"),
  41. Description = item.Description,
  42. EventEnum = item.EventEnum,
  43. EventId = item.Id,
  44. Explaination = item.Explaination,
  45. Solution = item.Solution,
  46. };
  47. switch (item.Level)
  48. {
  49. case EventLevel.Alarm: it.TextColor = Brushes.Red; break;
  50. case EventLevel.Warning: it.TextColor = Brushes.Yellow; break;
  51. default: it.TextColor = Brushes.White; break;
  52. }
  53. alarmEvents.Add(it);
  54. }
  55. if (AlarmEvents == null || (alarmEvents.Count != AlarmEvents.Count))
  56. {
  57. AlarmEvents = alarmEvents;
  58. }
  59. else
  60. {
  61. bool isEqual = true;
  62. if (alarmEvents.Count == AlarmEvents.Count)
  63. {
  64. for (int i = 0; i < alarmEvents.Count; i++)
  65. {
  66. if (!alarmEvents[i].IsEqualTo(AlarmEvents[i]))
  67. {
  68. isEqual = false;
  69. break;
  70. }
  71. }
  72. }
  73. if (!isEqual)
  74. AlarmEvents = alarmEvents;
  75. }
  76. InvokePropertyChanged("AlarmEvents");
  77. }
  78. }
  79. }