MonitorViewModel.cs 2.9 KB

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