/// <summary> /// Provides a method of deleting an alarm schedule /// </summary> /// <param name="schedule"></param> public static void Delete(Models.AlarmSchedule schedule) { if (schedule == null) { return; } string schedulePath = Path.Combine(_schedulesPath, string.Format("{0}.json", schedule.Name)); File.Delete(schedulePath); }
/// <summary> /// Provides a method for saving an alarm schedule /// </summary> /// <param name="schedule"></param> public static void Save(Models.AlarmSchedule schedule) { if (schedule == null) { return; } string schedulPath = Path.Combine(_schedulesPath, string.Format("{0}.json", schedule.Name)); using (FileStream fs = new FileStream(schedulPath, FileMode.Create, FileAccess.Write, FileShare.Write)) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Models.AlarmSchedule)); ser.WriteObject(fs, schedule); } }
//========================================================= // Methods //========================================================= /// <summary> /// Creates a new schedule based on the current selected alarms /// </summary> public async void CreateNewSchedule() { MetroDialogSettings settings = new MetroDialogSettings(); settings.AffirmativeButtonText = "Create"; settings.AnimateHide = true; settings.AnimateShow = true; settings.DefaultButtonFocus = MessageDialogResult.Affirmative; settings.NegativeButtonText = "Cancel"; string scheduleName = await MainWindow.View.ShowInputAsync("Create New Schedule", "Enter the name you would like to use for the new schedule", settings); var list = Controller.Master.AlarmScheduleCollection.Where(ap => ap.Name == scheduleName); if (list.Count() > 0) { settings.AffirmativeButtonText = "Ok"; await MainWindow.View.ShowMessageAsync("Create Schedule Error", "Cannot create a sachedule with the same name as an existing one", MessageDialogStyle.Affirmative, settings); this._eventAggregator.GetEvent <PushStatusMessageEvent>().Publish("Cannot create a sachedule with the same name as an existing one"); } else { if (scheduleName == null) { return; } Models.AlarmSchedule schedule = new Models.AlarmSchedule(Controller.Master.AlarmItemCollection.ToList()); if (scheduleName.Length > 0) { schedule.Name = scheduleName; AlarmScheduleRepository.Save(schedule); } Controller.Master.AlarmScheduleCollection.Add(schedule); ////settings.AffirmativeButtonText = "Ok"; //await MainWindow.View.ShowMessageAsync("Schedule Created", string.Format("Schedule has been created and saved for {0}", scheduleName), MessageDialogStyle.Affirmative, settings); this._eventAggregator.GetEvent <PushStatusMessageEvent>().Publish(string.Format("Schedule has been created and saved for {0}", scheduleName)); Controller.Master.AlarmScheduleCollection = new ObservableCollection <Models.AlarmSchedule>((new AlarmScheduleRepository()).GetAlarmSchedules()); this.SelectedSchedule = Controller.Master.AlarmScheduleCollection.Where(p => p.Name == schedule.Name).First(); } }