/// <summary>
        /// Registers the given alarm to the given host.
        /// </summary>
        /// <param name="host">Host.</param>
        /// <param name="alarm">Alarm.</param>
        /// <returns>True if the alarm was registered to the host.</returns>
        public bool RegisterAlarmToHost(object host, IAlarm alarm)
        {
            if (HostHasAlarmOfType(alarm.GetType(), host))
            {
                Log.E(this, "Object " + host + " already has an alarm of type " + alarm.GetType().Name);
                return(false);
            }
            HashSet <IAlarm> alarms = null;

            if (__alarmMapping.ContainsKey(host))
            {
                alarms = __alarmMapping[host];
            }
            else
            {
                __alarmMapping[host] = alarms = new HashSet <IAlarm>();
            }

            alarm.id = ++alarmIdCounter;
            __idAlarmMapping.Add(alarm.id, alarm);
            alarms.Add(alarm);
            alarm.onAlarmEvent += OnAlarmEvent;


            return(true);
        }
Exemplo n.º 2
0
 public void UpdateAlarms(IAlarm alarm)
 {
     if (alarm.GetType().BaseType.Equals(typeof(AuthorAlarm)))
     {
         UpdateStateOfAuthorAlarm((AuthorAlarm)alarm);
     }
     else
     {
         UpdateStateOfEntityAlarm((EntityAlarm)alarm);
     }
 }
Exemplo n.º 3
0
 public void AddAlarm(IAlarm alarm)
 {
     try
     {
         using (Context ctx = new Context())
         {
             if (alarm.GetType().Equals(typeof(AuthorAlarm)))
             {
                 ctx.AuthorAlarms.Add((AuthorAlarm)alarm);
             }
             else
             {
                 EntityAlarm sentimentAlarm = (EntityAlarm)alarm;
                 ctx.Entities.Attach(sentimentAlarm.Entity);
                 ctx.SentimentAlarms.Add(sentimentAlarm);
             }
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new DataBaseException("Error agregando alarma.", ex);
     }
 }