private void CancelDeviceAlarm(Device device, AlarmType alarmType)
        {
            using (var ctx = new DatabaseContext())
            {
                DeviceAlarm deviceAlarm = ctx.Alarms.FirstOrDefault(alarm => alarm.DeviceId == device.Id && alarm.AlarmType == alarmType);
                if (deviceAlarm != null)
                {
                    ctx.Alarms.Remove(deviceAlarm);
                    ctx.SaveChanges();

                    logger.Info("Device {0}'s {1} returned to normal status.", device.Name, alarmType);
                }
            }
        }
        private void SetDeviceOnAlarm(Device device, AlarmType alarmType)
        {
            using (var ctx = new DatabaseContext())
            {
                DeviceAlarm deviceAlarm = ctx.Alarms.FirstOrDefault(alarm => alarm.DeviceId == device.Id && alarm.AlarmType == alarmType);
                if (deviceAlarm == null)
                {
                    var alarm = new DeviceAlarm
                    {
                        AlarmType  = alarmType,
                        DeviceId   = device.Id,
                        DeviceName = device.Name,
                        StartDttm  = DateTime.Now
                    };
                    ctx.Alarms.Add(alarm);
                    ctx.SaveChanges();

                    logger.Info("Device {0}'s {1} is in alarm status.", device.Name, alarmType);
                }
            }
        }