public MainForm()
        {
            InitializeComponent();

            file = AlarmsFile.Load(ALARMS_FILE);
            file2 = ParentalControlsCredentialsFile.Load(CREDENTIALS_FILE);
        }
Exemple #2
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);
        }
 void WorkerThreadFunc()
 {
     AlarmsFile file = new AlarmsFile();
     file.FileName = (string)ParentalControlsRegistry.GetRegistryKey().GetValue("AlarmFile", "");
     while (!_shutdownEvent.WaitOne(0))
     {
         if (file.IsValidForSaving())
         {
             foreach (Alarm alarm in file.Alarms)
             {
                 if (alarm.RepeatDays.HasFlag(GetCurrentDay()) && IsTimeToAlarm(alarm))
                 {
                     if (ShowBlocker())
                     {
                         Time a = GetCurrentTime();
                         Console.WriteLine("The Alarm Blocker showed at {0}:{1} {2}.", a.Hour, a.Minutes, (a.Hour > 12 ? "PM" : "AM"));
                     }
                 }
             }
         }
         Thread.Sleep(waitTime);
     }
 }
        /// <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;
        }