private void OnAdd() { AddMode = true; CanEditFields = true; CanUseDatagrid = false; SelectedSchedule = new ScheduleModel { Day = DateTime.Now.DayOfWeek, Description = "", AudioLocation = "", PlayerLocation = Global.PlayerLocation, StartTime = new TimeSpan(0, 0, 0), IsChecked = false }; ScheduleCollection.Add(SelectedSchedule); }
private void OnNewAddDateTimeSpanCommand() { currentPeriod = new Period(); currentPeriod.Begin = BeginDate.Date.Add(TimeSpan.Parse(startTime)); //TODO: Add TryCatch and Log currentPeriod.End = EndDate.Date.Add(TimeSpan.Parse(endTime)); currentPeriod.RepeatType = SelectedRepeatType; if (scheduler == null) { scheduler = new Scheduler(); } scheduler.Schedule = ScheduleCollection; if (currentPeriod.End > currentPeriod.Begin) { // if(ScheduleCollection != null && ScheduleCollection.Count > 0) // { // for(int i = ScheduleCollection.Count; i > 0; i--) // { // if( // scheduler.Exist(currentPeriod) // ) // { // if(new MessageBoxViewModel { // Caption = "Already in list", // Message = "This period overlaps", // Buttons = MessageBoxButton.YesNo, // Image = MessageBoxImage.Information // } // .Show(this.Dialogs) == MessageBoxResult.Yes) // { // ScheduleCollection.Add(currentPeriod); // return; // } // else // return; // } // } // ScheduleCollection.Add(currentPeriod); // return; // } // else if(ScheduleCollection != null) ScheduleCollection.Add(currentPeriod); } }
private ScheduleCollection CloneCollection([NotNull][ItemNotNull] ScheduleCollection collection) { ScheduleCollection newCollection = new ScheduleCollection(); foreach (ScheduleElement element in collection) { newCollection.Add(new ScheduleElement { Name = element.Name, Options = element.Options, Type = element.Type, Parameters = CloneCollection(element.Parameters) }); } return(newCollection); }
private ScheduleCollection CloneCollection([NotNull][ItemNotNull] ScheduleCollection collection) { ScheduleCollection newCollection = new ScheduleCollection(); foreach (ScheduleElement element in collection) { newCollection.Add(new ScheduleElement { Name = element.Name, Options = element.Options, Type = element.Type, Parameters = CloneCollection(element.Parameters) }); } return newCollection; }
/// <summary> /// Returns all of the schedules defined for the current /// application. The collection returned is read-only. /// </summary> public static ScheduleCollection GetSchedules() { if (_schedules == null) { lock (_schedulesSyncLock) { if (_schedules == null) { ScheduleCollection schedules = new ScheduleCollection(); if (Configuration != null) { foreach (ScheduleSettings settings in Configuration.ScheduleSettings) { ScheduleBase schedule = ScheduleFactory.CreateSchedule(settings); schedules.Add(schedule); } } _schedules = schedules; } } } return ScheduleCollection.ReadOnly(ScheduleCollection.FixedSize(_schedules)); }
/// <summary> /// Initalize Schedules NextRunTime While Run Time. /// </summary> /// <param name="schedules"></param> /// <returns></returns> private static IEnumerable <Schedule> CalculateNextRun(IEnumerable <Schedule> schedules) { foreach (var schedule in schedules) { //calc null nextruntime schedule if (schedule.CalculateNextRunTime == null) { if (schedule.DelayRunFor > TimeSpan.Zero) { //delayed Job schedule.NextRun = Now.Add(schedule.DelayRunFor); _schedules.Add(schedule); } else { //run now yield return(schedule); } var hasAdded = false; foreach (var child in schedule.AdditionalSchedules.Where(x => x.CalculateNextRunTime != null)) { var nextRun = child.CalculateNextRunTime(Now.Add(child.DelayRunFor).AddMilliseconds(1)); if (!hasAdded || schedule.NextRun > nextRun) { schedule.NextRun = nextRun; hasAdded = true; } } } else { schedule.NextRun = schedule.CalculateNextRunTime(Now.Add(schedule.DelayRunFor)); _schedules.Add(schedule); } foreach (var childSchedule in schedule.AdditionalSchedules) { if (childSchedule.CalculateNextRunTime == null) { if (childSchedule.DelayRunFor > TimeSpan.Zero) { //delayed Job childSchedule.NextRun = Now.Add(childSchedule.DelayRunFor); _schedules.Add(childSchedule); } else { //run now yield return(childSchedule); continue; } } else { childSchedule.NextRun = childSchedule.CalculateNextRunTime(Now.Add(childSchedule.DelayRunFor)); _schedules.Add(childSchedule); } } } }