예제 #1
0
        /// <summary>
        /// Cancel native alarm
        /// and then remove AlarmRecord from ObservableAlarmList and AlarmRecordDictionary
        /// </summary>
        /// <param name="alarm">AlarmRecord</param>
        public static void DeleteAlarm(AlarmRecord alarm)
        {
            Console.WriteLine("DeleteAlarm:" + alarm.ToString());
            // Cancel the native alarm
            AlarmNativeHandler.DeleteAlarm(alarm);
            string UID = alarm.GetUniqueIdentifier();

            // Delete alarm from dictionary
            AlarmModel.AlarmRecordDictionary.Remove(UID);
            // Delete alarm from List
            for (int i = AlarmModel.ObservableAlarmList.Count - 1; i >= 0; i--)
            {
                if (AlarmModel.ObservableAlarmList[i].GetUniqueIdentifier() == UID)
                {
                    ObservableAlarmList.RemoveAt(i);
                    break;
                }
            }

            AlarmModel.SaveDictionary();
        }
예제 #2
0
        /// <summary>
        /// Update AlarmRecord Dictionary and ObservableAlarmList
        /// </summary>
        /// <param name="UID">AlarmRecord unique ID</param>
        /// <param name="NativeAlarmID">Native AlarmID</param>
        /// <param name="active">active state of AlarmRecord</param>
        private static void UpdateDictionaryAndList(string UID, int NativeAlarmID, bool active)
        {
            for (int i = 0; i < AlarmModel.ObservableAlarmList.Count; i++)
            {
                AlarmRecord item = AlarmModel.ObservableAlarmList[i];
                if (item.GetUniqueIdentifier() == UID)
                {
                    AlarmModel.AlarmRecordDictionary.Remove(UID);
                    item.NativeAlarmID = NativeAlarmID;
                    if (active)
                    {
                        item.AlarmState = AlarmStates.Active;
                    }
                    else
                    {
                        item.AlarmState = AlarmStates.Inactive;
                    }

                    AlarmModel.AlarmRecordDictionary.Add(UID, item);
                    AlarmModel.SaveDictionary();
                    break;
                }
            }
        }