Exemplo 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();
 }
Exemplo 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);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Deep copy alarm record
 /// </summary>
 /// <param name="bindableAlarmRecord">Alarm record to deep copy</param>
 /// <seealso cref="AlarmRecord">
 public void DeepCopy(AlarmRecord Record, bool includeUID = true)
 {
     // All properties should be copied to this alarm record object
     ScheduledDateTime = Record.ScheduledDateTime;
     WeekFlag          = Record.WeekFlag;
     AlarmState        = Record.AlarmState;
     IsSerialized      = Record.IsSerialized;
     if (includeUID)
     {
         DateCreated   = Record.DateCreated;
         NativeAlarmID = Record.NativeAlarmID;
     }
 }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Determines whether ObservableAlarmList contains an alarm which is scheduled at the same time.
 /// </summary>
 /// <param name="duplicate">AlarmRecord</param>
 /// <returns> true if a same alarm is found in the list; otherwise, false.</returns>
 public static bool CheckAlarmExist(ref AlarmRecord duplicate)
 {
     foreach (AlarmRecord item in AlarmModel.ObservableAlarmList)
     {
         // Check scheduled time and alarm name
         if (item.ScheduledDateTime.Equals(AlarmModel.BindableAlarmRecord.ScheduledDateTime))
         {
             // a same alarm is found.
             duplicate.DeepCopy(item);
             return(true);
         }
     }
     // there's no same alarm.
     duplicate = null;
     return(false);
 }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
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;
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// AlarmModel constructor
 /// </summary>
 public AlarmModel()
 {
     ObservableAlarmList   = new ObservableCollection <AlarmRecord>();
     AlarmRecordDictionary = AlarmPersistentHandler.DeserializeAlarmRecord();
     BindableAlarmRecord   = new AlarmRecord();
     if (AlarmRecordDictionary == null)
     {
         AlarmRecordDictionary = new Dictionary <string, AlarmRecord>();
     }
     else
     {
         foreach (var alarmItem in AlarmRecordDictionary)
         {
             Console.WriteLine("alarmItem key:" + alarmItem.Key);
             // Key is DateCreated
             var keyString = alarmItem.Key;
             // Retrieve alarm record
             AlarmRecord retrieved = alarmItem.Value;
             Console.WriteLine("retrieved:" + retrieved.ToString());
             // Add the retrieved alarm to list for AlarmListUI
             ObservableAlarmList.Add(retrieved);
         }
     }
 }
Exemplo n.º 9
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;
                }
            }
        }