MonitorViewModel.cs 2.9 KB

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