bool IsTimeToAlarm(Alarm alarm)
 {
     Time t = GetCurrentTime();
     return (alarm.AlarmTime.Hour == t.Hour && alarm.AlarmTime.Minutes == t.Minutes);
 }
 private void Save()
 {
     if (newAlarm != Alarm.Empty)
     {
         file.Add(newAlarm);
         newAlarm = Alarm.Empty;
     }
     if(file.IsValidForSaving())
         file.Save();
 }
        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);
        }
        /// <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;
        }
 public void Add(Alarm alarm)
 {
     _Alarms.Add(alarm);
 }