Ejemplo n.º 1
0
 public void RemoveEvent(AlarmEvent alarmEvent, int levelSecurity = 0)
 {
     if (alarmEvent.MinUserLevelToRemove > levelSecurity)
     {
         throw new ArgumentException(string.Format("Don't have permission to remove alarm {0}", alarmEvent.AlarmID));
     }
     else
     {
         AlarmEvents.Remove(alarmEvent);
     }
 }
Ejemplo n.º 2
0
 public void ReceiveVariableValues(Dictionary <int, double> variableValue)
 {
     if (TimeProvider == null)
     {
         throw new InvalidOperationException("AlarmManager has no assigment TimeProvider");
     }
     foreach (Alarm alarm in Alarms)
     {
         double newValue;
         if (variableValue.TryGetValue(alarm.VariableID, out newValue))
         {
             AlarmEvent alarmExist = AlarmEvents.FindLast(x => x.AlarmID == alarm.AlarmID);
             if (alarm.Sensor.Check(newValue))
             {
                 if (alarmExist == null)
                 {
                     var newEvent = new AlarmEvent
                     {
                         AlarmID   = alarm.AlarmID,
                         StartTime = TimeProvider.Now,
                         EndTime   = DateTime.MaxValue,
                     };
                     AlarmEvents.Add(newEvent);
                 }
                 else
                 if (alarmExist.EndTime != DateTime.MaxValue)
                 {
                     var newEvent = new AlarmEvent
                     {
                         AlarmID   = alarm.AlarmID,
                         StartTime = TimeProvider.Now,
                         EndTime   = DateTime.MaxValue,
                     };
                     AlarmEvents.Add(newEvent);
                 }
             }
             else
             if (alarmExist != null)
             {
                 if (alarmExist.EndTime == DateTime.MaxValue)
                 {
                     alarmExist.EndTime = TimeProvider.Now;
                 }
             }
         }
     }
 }