private static int NotificationAlarmsCompare(NotificationAlarm a, NotificationAlarm b) { if (a.State > b.State) { return -1; } else if (a.State < b.State) { return 1; } else { if (a.Ack && !b.Ack) { return 1; } else if (!a.Ack && b.Ack) { return -1; } return 0; } }
public void UpdateAlarm(Unit unit, IAlarm alarm) { lock (Alarms) { List<NotificationAlarm> alarms = new List<NotificationAlarm>(Alarms); foreach (var notificationAlarm in alarms) { if (notificationAlarm.Unit.Uri.Equals(unit.Uri) && notificationAlarm.Code.Equals(alarm.Code)) { if (notificationAlarm.State != alarm.State) { if (alarm.State == ParamState.Idle) { Alarms.Remove(notificationAlarm); if (GeneralAlarmsStateChangedEvent != null) { GeneralAlarmsStateChangedEvent(this); } CanPlayShortNotification = true; return; } notificationAlarm.State = alarm.State; notificationAlarm.Ack = false; if (GeneralAlarmsStateChangedEvent != null) { GeneralAlarmsStateChangedEvent(this); } CanPlayShortNotification = true; if (notificationAlarm.State == ParamState.C) { LongNotificationTimer.Stop(); LongNotificationTimer.Interval = 3000; LongNotificationTimer.Start(); } } return; } } if (alarm.State > ParamState.Idle) { NotificationAlarm notificationAlarm = new NotificationAlarm(unit, alarm, false); Alarms.Add(notificationAlarm); if (GeneralAlarmsStateChangedEvent != null) { GeneralAlarmsStateChangedEvent(this); } CanPlayShortNotification = true; if (notificationAlarm.State == ParamState.C) { LongNotificationTimer.Stop(); LongNotificationTimer.Interval = 3000; LongNotificationTimer.Start(); } } } }