Ejemplo n.º 1
0
 /// <summary>
 /// Ractivate AlarmRecord
 /// </summary>
 /// <param name="record">AlarmRecord for reactivating</param>
 public static void ReactivatelAlarm(AlarmRecord record)
 {
     //1. register native alarm
     int NativeAlarmID = AlarmNativeHandler.CreateAlarm(record);
     //2. Update NativeAlarmID and AlarmState
     string UID = record.GetUniqueIdentifier();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Cancel native alarm
        /// and then deactivate AlarmRecord from AlarmRecordDictionary
        /// </summary>
        /// <param name="record">AlarmRecord</param>
        public static void DeactivatelAlarm(AlarmRecord record)
        {
            //1. cancel native alarm
            AlarmNativeHandler.DeleteAlarm(record);
            //2. Make AlarmRecord's AlarmState
            string UID = record.GetUniqueIdentifier();

            UpdateDictionaryAndList(UID, 0, false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create native alarm
        /// </summary>
        public static void CreateAlarm()
        {
            // create a native alarm using AlarmModel.BindableAlarmRecord
            // After then, update Native alarm ID.
            BindableAlarmRecord.NativeAlarmID = AlarmNativeHandler.CreateAlarm(BindableAlarmRecord);

            AlarmRecord record = new AlarmRecord();

            record.DeepCopy(BindableAlarmRecord);
            ObservableAlarmList.Add(record);
            AlarmRecordDictionary.Add(record.GetUniqueIdentifier(), record);
            SaveDictionary();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update alarm record
        /// </summary>
        /// <param name="record">AlarmRecord</param>
        public static void UpdateAlarm(AlarmRecord record)
        {
            var obj = record;

            // Update native alarm
            AlarmNativeHandler.UpdateAlarm(ref obj);
            record = obj;
            string alarmUID = record.GetUniqueIdentifier();

            // Update list
            for (int i = 0; i < ObservableAlarmList.Count; i++)
            {
                AlarmRecord item = ObservableAlarmList[i];
                if (item.GetUniqueIdentifier() == alarmUID)
                {
                    Console.WriteLine("Found AlarmRecord(UID: " + item.GetUniqueIdentifier() + ") in ObservableAlarmList.");
                    AlarmRecordDictionary.Remove(alarmUID);
                    item.DeepCopy(record);
                    AlarmRecordDictionary.Add(alarmUID, item);
                    SaveDictionary();
                    break;
                }
            }
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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;
                }
            }
        }