private void Save(object sender, RoutedEventArgs e) { // Make Time Time time = NextDayStartTextBox.Text; // Return if bad format if (time == null) { return; } // Check if int int advanceSchedule; try { advanceSchedule = int.Parse(AdvanceScheduleTextBox.Text); } catch (Exception) { App.ErrorMessage("Days in advance should be a number."); return; } // Change the Setting Setting.AddOrChange("NextDayStart", time); Setting.AddOrChange("AdvanceSchedule", AdvanceScheduleTextBox.Text); App.NextDayStart = time; App.AdvanceSchedule = advanceSchedule; Close(); }
protected override void OnStartup(StartupEventArgs e) { Log("Application started"); // Check if duplicate instance if (!Mutex.WaitOne(0, false)) { ErrorMessage("Audio Scheduler already running. Exiting this duplicate instance."); Log("Attempt to open duplicate instance, exiting"); Current.Shutdown(); } base.OnStartup(e); // Create BaseDirectory if (!Directory.Exists(BaseDirectory)) { InfoMessage("Startup Warning", $"Data folder not found. It will be created at {BaseDirectory}. " + "The data folder may have deleted or misplaced or this is the first time using the program on this computer."); Directory.CreateDirectory(BaseDirectory); } // Create LogDirectory if (!Directory.Exists(LogDirectory)) { Directory.CreateDirectory(LogDirectory); } // Create SoundDirectory if (!Directory.Exists(SoundDirectory)) { Directory.CreateDirectory(SoundDirectory); } // Set default Settings var nextDayStartSetting = Setting.Get("NextDayStart"); if (nextDayStartSetting == null) { Setting.AddOrChange("NextDayStart", "02:00"); nextDayStartSetting = Setting.Get("NextDayStart"); } var advanceScheduleSetting = Setting.Get("AdvanceSchedule"); if (advanceScheduleSetting == null) { Setting.AddOrChange("AdvanceSchedule", "2"); advanceScheduleSetting = Setting.Get("AdvanceSchedule"); } // Get Settings NextDayStart = nextDayStartSetting; AdvanceSchedule = int.Parse(advanceScheduleSetting); // Test database connection try { using (var db = new Context()) { db.Database.OpenConnection(); db.Database.CloseConnection(); } } catch (Exception error) { ErrorMessage("Database connection error. Exiting.", error); Current.Shutdown(); } // Start the Scheduler Scheduler.Start(); Log("Scheduler started"); // Open main window var mainWindow = new MainWindow(); mainWindow.Show(); Log("Main window opened"); }