예제 #1
0
 bool IsTimeToAlarm(Alarm alarm)
 {
     Time t = GetCurrentTime();
     return (alarm.AlarmTime.Hour == t.Hour && alarm.AlarmTime.Minutes == t.Minutes);
 }
예제 #2
0
 private void Save()
 {
     if (newAlarm != Alarm.Empty)
     {
         file.Add(newAlarm);
         newAlarm = Alarm.Empty;
     }
     if(file.IsValidForSaving())
         file.Save();
 }
예제 #3
0
        public void Change(string name, Alarm newalarm)
        {
            Alarm old = default(Alarm);
            foreach (Alarm alarm in _Alarms)
            {
                if (alarm.Name == name)
                {
                    old = alarm;
                    break;
                }
            }

            _Alarms.Remove(old);
            _Alarms.Add(newalarm);
        }
예제 #4
0
        /// <summary>
        /// Loads and returns a AlarmsFile.
        /// </summary>
        /// <param name="filename">File to load</param>
        /// <returns>AlarmsFile with FileName.</returns>
        public static AlarmsFile Load(string filename)
        {
            AlarmsFile file = new AlarmsFile();
            try
            {
                using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.OpenOrCreate)))
                {
                    Alarm alarm = new Alarm();
                    alarm.AlarmTime = new Time();
                    int readat = 0;
                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        switch (readat)
                        {
                            case 0:
                                alarm.Name = reader.ReadString();
                                readat++;
                                break;
                            case 1:
                                alarm.Enabled = reader.ReadBoolean();
                                readat++;
                                break;
                            case 2:
                                alarm.AlarmTime.Hour = reader.ReadInt32();
                                readat++;
                                break;
                            case 3:
                                alarm.AlarmTime.Minutes = reader.ReadInt32();
                                readat++;
                                break;
                            case 4:
                                alarm.AlarmTime.Seconds = reader.ReadInt32();
                                readat++;
                                break;
                            case 5:
                                alarm.RepeatDays = (DayOfWeek)reader.ReadInt32();

                                file.Add(alarm);
                                readat = 0;
                                alarm = new Alarm();
                                alarm.AlarmTime = new Time();
                                break;

                        }
                    }
                }
            }
            catch { }
            return file;
        }
예제 #5
0
 public void Add(Alarm alarm)
 {
     _Alarms.Add(alarm);
 }