/// <summary> /// Gets the next execution date for the given schedule. /// </summary> /// <param name="schedule">The schedule to get the next execution date for.</param> /// <param name="now">The reference time to compare schedule dates to.</param> /// <returns>The schedule's next execution date.</returns> public static DateTime GetNextExecuteDate(ScheduleConfigurationElement schedule, DateTime now) { if (now < schedule.StartDate) { return schedule.StartDate; } /* * TODO: The only repeat type is Daily right now. */ int days = (int)Math.Ceiling(now.Subtract(schedule.StartDate).TotalDays); return schedule.StartDate.AddDays(days); }
/// <summary> /// Fires an event for this instance. /// </summary> /// <param name="handler">The event handler to fire.</param> /// <param name="schedule">The schedule to fire the event for.</param> /// <param name="target">The target to fire the event for, if applicable.</param> /// <param name="exception">The exeption to fire the event for, if applicable.</param> private void Fire(EventHandler<ScheduleEventArgs> handler, ScheduleConfigurationElement schedule, DatabaseTargetConfigurationElement target, Exception exception) { if (handler != null) { ScheduleEventArgs args = new ScheduleEventArgs() { ErrorException = exception, Name = schedule.Name, RepeatType = schedule.Repeat, StartDate = schedule.StartDate }; if (target != null) { args.OperationType = target is DatabaseRestoreTargetConfigurationElement ? ScheduleOperationType.Restore : ScheduleOperationType.Backup; args.TargetName = target.Name; } handler(this, args); } }
/// <summary> /// Gets the next execution date for the given schedule. /// </summary> /// <param name="schedule">The schedule to get the next execution date for.</param> /// <returns>The schedule's next execution date.</returns> public static DateTime GetNextExecuteDate(ScheduleConfigurationElement schedule) { return GetNextExecuteDate(schedule, DateTime.Now); }