private void _monitoringDataService_AlarmDataUpdated(object sender, AlarmDataEventArgs e)
        {
            var alarmStr = e.Data as string;

            if (!string.IsNullOrEmpty(alarmStr))
            {
                var alarmInfo = JsonConvert.DeserializeObject <AlarmInfo>(alarmStr);
                if (alarmInfo != null)
                {
                    var action = new Action(() =>
                    {
                        _soundPlayer = new System.Media.SoundPlayer();
                        _soundPlayer.SoundLocation = Alarm_Sound_FilePath;
                        _soundPlayer.PlayLooping();
                    });
                    action.BeginInvoke(null, null);

                    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (AlarmList.Count > ALARM_LIST_MAX_COUNT)
                        {
                            AlarmList.RemoveAt(AlarmList.Count - 1);
                        }
                        AlarmList.Add(alarmInfo);
                        CurrentAlarmInfo = alarmInfo;
                        IsShow           = true;
                        NotifiyAlarm();
                    }));
                }
            }
        }
Ejemplo n.º 2
0
 private void OnDataChange(ConveyorBasicInfo info, string name)
 {
     try
     {
         if (info != null)
         {
             if (info.ActiveAlarms != null)
             {
                 var alarmToDel = from a in AlarmList
                                  where a.Unit == name && !info.ActiveAlarms.Contains(Convert.ToInt32(a.AlarmID))
                                  select a;
                 alarmToDel.ToList().ForEach(p => AlarmList.Remove(p));
                 var alarmToAdd = from a in info.ActiveAlarms
                                  where  AlarmList.FirstOrDefault(p => p.Unit == name && p.AlarmID == a.ToString("000000")) == null
                                  select new AlarmViewModel
                 {
                     AlarmID     = a.ToString("000000"),
                     Unit        = name,
                     Severity    = EnumAlarmSeverity.Error,
                     Status      = EnumAlarmStatus.Active,
                     Text        = ResourceReader.GetString(string.Format("ALARM_{0}", a.ToString("000000"))),
                     ArrivedTime = DateTime.Now,
                     AckTime     = null
                 };
                 alarmToAdd.ToList().ForEach(p => AlarmList.Add(p));
             }
         }
     }
     catch (Exception e)
     {
         _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception, e.Message);
         throw new Exception(string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
     }
 }
Ejemplo n.º 3
0
        public AlarmManagerViewModel()
        {
            DeleteCommand = new RelayCommand(
                x => AlarmList.Remove(SelectedAlarmDetail),
                x => AlarmList.Any() && SelectedAlarmDetail != null
                );

            AddCommand = new RelayCommand(
                x => AlarmList.Add(new AlarmItemViewModel
            {
                AlarmName = $"{DefaultAlarmName} {AlarmList.Count + 1}",
                Type      = AlarmType.Min
            }
                                   ),
                x => AlarmList.Count < 10
                );
        }
Ejemplo n.º 4
0
 public void Handle(AlarmItem message)
 {
     if (!message.Value)
     {
         if (AlarmList.Any(x => x.Address == message.Address))
         {
             var a = AlarmList.Where(x => x.Address == message.Address);
             foreach (var v in a)
             {
                 AlarmList.Remove(v);
             }
         }
     }
     else
     {
         AlarmList.Add(message);
     }
 }
Ejemplo n.º 5
0
        //=============================================================================
        //Timed events
        //=============================================================================
        #region Timed Events
        private async void _dispatchTimer_TickAsync(object sender, object e)
        {
            try
            {
                // Get room data
                await HomeHub.GetData();

                await zwaveHomeHub.GetAsync();

                ;

                //=============================================================
                // Alarms
                //=============================================================
                #region Alarms
                HomeHub.TempAlarmVal     = MinimumTemperature;
                HomeHub.HumidityAlarmVal = MaximumHumidity;

                AlarmHandler(HomeHub.RoomData.Livingroom, "Livingroom");
                AlarmHandler(HomeHub.RoomData.MasterBedroom, "Master Bedroom");
                //AlarmHandler(HomeHub.RoomData.Bedroom, "Bedroom");



                void AlarmHandler(EnvironmentSensor.Room room, string roomName)
                {
                    //Humidity Alarm
                    if (HomeHub.HumidityAlarm(room.Humidity))
                    {
                        if (!AlarmList.Contains(roomName + " humidity alarm"))
                        {
                            AlarmList.Add(roomName + " humidity alarm");
                        }
                    }
                    else
                    {
                        AlarmList.Remove(roomName + " humidity alarm");
                    }

                    //Temperature alarm
                    if (HomeHub.TempAlarm(room.Temp))
                    {
                        if (!AlarmList.Contains(roomName + " temperature alarm"))
                        {
                            AlarmList.Add(roomName + " temperature alarm");
                        }
                    }
                    else
                    {
                        AlarmList.Remove(roomName + " temperature alarm");
                    }

                    if (AlarmList != null && AlarmList.Count != 0)
                    {
                        AlarmIndicatorShow = Visibility.Visible;
                    }
                    else
                    {
                        AlarmIndicatorShow = Visibility.Collapsed;
                    }
                }


                #endregion

                //=============================================================
                // Living Room Environment
                //=============================================================
                #region Livingroom Environment
                //Update Display
                LivingRoomTemperature =
                    Math.Round(HomeHub.RoomData.Livingroom.Temp) + "°C";
                LivingRoomTemperatureScaled =
                    HomeHub.LivingRoomScaledTemp;
                LivingRoomHumidityScaled =
                    HomeHub.RoomData.Livingroom.Humidity;
                LivingRoomHumidity =
                    Math.Round(HomeHub.RoomData.Livingroom.Humidity) + "%";
                #endregion

                //=============================================================
                // Master Bedroom Environment
                //=============================================================
                #region Master Bedroom Environment
                //Update Display
                MasterBedroomTemperature =
                    Math.Round(HomeHub.RoomData.MasterBedroom.Temp) + "°C";
                MasterBedroomTemperatureScaled =
                    HomeHub.MasterBedroomScaledTemp;
                MasterBedroomHumidityScaled =
                    HomeHub.RoomData.MasterBedroom.Humidity;
                MasterBedroomHumidity =
                    Math.Round(HomeHub.RoomData.MasterBedroom.Humidity) + "%";
                #endregion
            }
            // log any exception that occurs
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 6
0
 public void AddAlarm(Alarm alarm)
 {
     AlarmList.Add(alarm);
     SortAlarms();
 }