private IEnumerable <DateTime> _GetMonthlyDOMInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { // Create DateTime instances for each occurrence. IEnumerable <int> intervals = _GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd); // Create DateTime instances for each occurrence. // This is the only item type where the item date is absolute rather // than relative to the start date. DateTime startDate = scheduleItem.StartDate; if (scheduleItem.DayDate != LastDay) { DateTime instance = new DateTime(startDate.Year, startDate.Month, scheduleItem.DayDate) + scheduleItem.RunStartTime; return (from interval in intervals select instance.AddMonths(interval *scheduleItem.DateUnitCount)); } else { // If the item's DayDate value is LastDay, adjust each for the last day of // the month. // Start with an initial date based on the item start date. Day of the // month is unimportant. DateTime instance = new DateTime(startDate.Year, startDate.Month, 1); return(intervals.Select <int, DateTime>(interval => { // Offset the initial date by an appropriate number of months. DateTime offsetInstance = instance.AddMonths(interval * scheduleItem.DateUnitCount); // With the date now being in the correct year and month, create a // new date with the day set correctly. return new DateTime(offsetInstance.Year, offsetInstance.Month, DateTime.DaysInMonth(offsetInstance.Year, offsetInstance.Month)) + scheduleItem.RunStartTime; })); } }
private DateTime _GetDOWLatestOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate) { int iterations = (monthDate.Month - scheduleItem.StartDate.Month + (monthDate.Year - scheduleItem.StartDate.Year) * 12) / scheduleItem.DateUnitCount; DateTime lastItemMonth = scheduleItem.StartDate.AddMonths(iterations * scheduleItem.DateUnitCount); return(_GetDOWOccurrenceDate(scheduleItem, lastItemMonth)); }
private bool _WindowIsValidForItem(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { double windowStartRepetitions = _GetWindowStartRepetitions(scheduleItem, windowStart); double windowEndRepetitions = _GetWindowEndRepetitions(scheduleItem, windowEnd); // The window could potentially cross a time frame (day/week/month) boundary. return(_IncludesIntegerBoundary(windowStartRepetitions, windowEndRepetitions)); }
protected void RaiseScheduledItemCompleted(IScheduleItem <T> scheduleItem) { Task.Run(() => { ScheduledItemCompletedEventArgs <T> reached = new ScheduledItemCompletedEventArgs <T>(scheduleItem); ScheduledItemCompleted?.Invoke(this, reached); }); }
/// <summary> /// Gets the last DateTime occurrence of the item between the item's start and the provided month/year date. /// </summary> /// <param name="scheduleItem"></param> /// <param name="monthDate">Month and year, day of the month is not considered.</param> /// <returns>Returned DateTime may occur before the provided DateTime.</returns> private DateTime _GetDOMLatestOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate) { int iterations = (monthDate.Month - scheduleItem.StartDate.Month + (monthDate.Year - scheduleItem.StartDate.Year) * 12) / scheduleItem.DateUnitCount; int day = scheduleItem.DayDate == LastDay?DateTime.DaysInMonth(monthDate.Year, monthDate.Month) : scheduleItem.DayDate; DateTime lastItem = scheduleItem.StartDate.AddMonths(iterations * scheduleItem.DateUnitCount); return(new DateTime(lastItem.Year, lastItem.Month, day)); }
/// <summary> /// Runs the specified scheduled item if it's due to be triggered. /// </summary> /// <param name="scheduledItem">The scheduled item.</param> private void RunIfTriggered(IScheduleItem scheduledItem) { // TODO: locate correct code for identifying the interval... DateTime moment = _momentProvider.GetCurrent(); //if (scheduledItem.ShouldRun(moment, Schedule.Interval)) //{ // RunTask(scheduledItem); //} }
/// <summary> /// Provides a readable text summary of a schedule item. /// </summary> /// <param name="scheduleItem"></param> /// <returns></returns> public string GetItemSummary(IScheduleItem scheduleItem) { StringBuilder sb = new StringBuilder(); RecurrenceType recurrenceType = (RecurrenceType) scheduleItem.RecurrenceType; string unit = string.Empty; switch (recurrenceType) { case RecurrenceType.Daily: unit = "day"; break; case RecurrenceType.Weekly: unit = "week"; break; case RecurrenceType.MonthlyDateOfMonth: unit = "month"; break; case RecurrenceType.MonthlyDayOfWeek: unit = "month"; break; } sb.Append("Every "); if (scheduleItem.DateUnitCount > 1) { sb.AppendFormat(" {0} {1}s", scheduleItem.DateUnitCount, unit); } else { sb.Append(unit); } switch (recurrenceType) { case RecurrenceType.Daily: // Nothing to do break; case RecurrenceType.Weekly: sb.Append(" on " + (DayOfWeek.Sunday + scheduleItem.DayDate).ToString()); break; case RecurrenceType.MonthlyDateOfMonth: if (scheduleItem.DayDate != LastDay) { sb.Append(" on the " + _AppendCount(scheduleItem.DayDate)); } else { sb.Append(" on the last day of the month "); } break; case RecurrenceType.MonthlyDayOfWeek: sb.AppendFormat(" on the {0} {1}", _AppendCount(scheduleItem.DayCount), (DayOfWeek.Sunday + scheduleItem.DayDate).ToString()); break; } sb.AppendFormat(" at " + scheduleItem.RunStartTime.ToString("hh:mm tt")); sb.AppendFormat(" starting on " + scheduleItem.StartDate.ToShortDateString()); return sb.ToString(); }
private IEnumerable <DateTime> _GetDailyInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { IEnumerable <int> intervals = _GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd); // Create DateTime instances for each occurrence. DateTime instance = scheduleItem.StartDate + scheduleItem.RunStartTime; return (from interval in intervals select instance.AddDays(interval *scheduleItem.DateUnitCount)); }
private int _GetDayOfWeekAdjustment(IScheduleItem scheduleItem) { // The start date of the item may not fall on the same day of the week // that the item occurs on. if ((int)scheduleItem.StartDate.DayOfWeek != scheduleItem.DayDate) { return(7 - Math.Abs((int)scheduleItem.StartDate.DayOfWeek - scheduleItem.DayDate)); } return(0); }
private bool _IsWeeklyValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { if (_WindowIsValidForItem(scheduleItem, windowStart, windowEnd)) { // The window could potentially cross a day boundary. // The item is valid if the window crosses into the item's day. return((int)windowStart.DayOfWeek == scheduleItem.DayDate || (int)windowEnd.DayOfWeek == scheduleItem.DayDate); } return(false); }
private IEnumerable <DateTime> _GetMonthlyDOWInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { // Create DateTime instances for each occurrence. List <int> intervals = new List <int>(_GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd)); // Start in the month of the item's start date. DateTime instance = _GetDOWOccurrenceDate(scheduleItem, scheduleItem.StartDate); return (from interval in intervals select _GetDOWOccurrenceDate(scheduleItem, instance.AddMonths(interval *scheduleItem.DateUnitCount))); }
private IEnumerable <DateTime> _GetWeeklyInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { IEnumerable <int> intervals = _GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd); // Create DateTime instances for each occurrence. DateTime instance = scheduleItem.StartDate + scheduleItem.RunStartTime; // Need to start on the correct day of the week at/after the item start date. instance = instance.AddDays(_GetDayOfWeekAdjustment(scheduleItem)); return (from interval in intervals select instance.AddDays(7 *interval *scheduleItem.DateUnitCount)); }
public void GetScheduleItem() { IScheduleItem scheduleItem = _scheduleService.GetScheduleItem("2826018c-69cc-4ead-946b-70bb5a47ab02"); Assert.IsNotNull(scheduleItem); Assert.AreEqual(scheduleItem.ScheduleType, ScheduleType.Daily); Assert.AreEqual(scheduleItem.Type, ItemType.Script); IScheduleItem failingScheduleItem = _scheduleService.GetScheduleItem("99"); Assert.IsNull(failingScheduleItem); }
private void SchedulerForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && scheduleDayView.SelectedItem != null) { if (MessageBox.Show("Delete scheduled run of \"" + System.IO.Path.GetFileName(scheduleDayView.SelectedItem.FilePath) + "\"?", "Vixen Scheduler", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { IScheduleItem item = scheduleDayView.SelectedItem; _data.Items.Remove(item); _RefreshView(); } } }
private IEnumerable <int> _GetItemOccurenceIntervals(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { double windowStartRepetitions = _GetWindowStartRepetitions(scheduleItem, windowStart); double windowEndRepetitions = _GetWindowEndRepetitions(scheduleItem, windowEnd); // The window could potentially cross a time frame (day/week/month) boundary. bool windowIsValid = _IncludesIntegerBoundary(windowStartRepetitions, windowEndRepetitions); if (windowIsValid) { return(_GetWindowOccurrenceIndexes(windowStartRepetitions, windowEndRepetitions)); } return(Enumerable.Empty <int>()); }
private bool _IsMonthlyDOWValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { if (_WindowIsValidForItem(scheduleItem, windowStart, windowEnd)) { // The window could potentially cross a day boundary. // The item is valid if the window crosses into the item's day. if ((int)windowStart.DayOfWeek == scheduleItem.DayDate || (int)windowEnd.DayOfWeek == scheduleItem.DayDate) { // Window crosses the correct day. // Does it cross the correct iteration of the day? return (_IterationOfDayOfWeek(windowStart.Day) == scheduleItem.DayCount || _IterationOfDayOfWeek(windowEnd.Day) == scheduleItem.DayCount); } } return(false); }
private void SchedulerForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && scheduleDayView.SelectedItem != null) { //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible) MessageBoxForm.msgIcon = SystemIcons.Question; //this is used if you want to add a system icon to the message form. var messageBox = new MessageBoxForm("Delete scheduled run of \"" + System.IO.Path.GetFileName(scheduleDayView.SelectedItem.FilePath) + "\"?", "Vixen Scheduler", true, false); messageBox.ShowDialog(); if (messageBox.DialogResult == DialogResult.OK) { IScheduleItem item = scheduleDayView.SelectedItem; _data.Items.Remove(item); _RefreshView(); } } }
/// <summary> /// Build and schedule your own item /// </summary> /// <param name="scheduleItem">the item to schedule</param> /// <returns>the id for the schedule item</returns> public int ScheduleItem(IScheduleItem <T> scheduleItem) { if (scheduleItem == null) { throw new ArgumentOutOfRangeException(nameof(scheduleItem)); } scheduleItem.Timestamp = scheduleItem.StartDateTime; if (scheduleItem.MaxOccurrances == 1) { scheduleItem.EndDateTime = EndDateTime; } int id = Repository.SaveOrchestratorItem(scheduleItem); return(id); }
private bool _IntervalRepeatingQualifier(IScheduleItem item, DateTime dateTime) { // If within the block of time... if (dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < item.RunEndTime) { // Generate interval blocks for (TimeSpan time = item.RunStartTime; time < item.RunEndTime; time += TimeSpan.FromMinutes(item.RepeatIntervalMinutes)) { // Has to be within the scheduled minute. if (dateTime.TimeOfDay >= time && dateTime.TimeOfDay < dateTime.TimeOfDay + TimeSpan.FromMinutes(1)) { return(true); } } } return(false); }
/// <summary> /// This will run the specified task and return whether or not it completed successfully. Any exceptions /// thrown by the worker task are logged and thrown up to the caller if <see cref="throwExceptions"/> is /// set to true, otherwise they are just logged and false is returned. Null tasks always complete with /// a success [true]. /// </summary> /// <param name="scheduledItem">The scheduled item with the worker task to execute.</param> /// <param name="throwExceptions">Flags if exceptions should be thrown up to the caller if they occur.</param> /// <returns>True if the task ran successfully, false otherwise.</returns> public bool RunTask(IScheduleItem scheduledItem, bool throwExceptions = false) { // if we didn't get anything then this counts as a success as we checked it if (scheduledItem == null) { _logger.Warn("Null scheduled item found."); return(false); } if (scheduledItem.Task == null) { _logger.Warn("Null task found. "); return(false); } // run the task and check if there was an issue bool success = false; string taskName = scheduledItem.GetType().FullName; try { _logger.Trace("Executing RunNow task [{0}]...", taskName); // this is deliberately broken to highlight attention. The line below // is invalid because the LastRun time should be managed by the scheduler. scheduledItem.LastRun = _momentProvider.GetCurrent(); success = ((IWorkerTask)scheduledItem.Task).DoWork(); } catch (Exception ex) { // log and determine if we need to rethrow. _logger.Error(ex, "Task [{0}] threw an exception.", taskName); if (throwExceptions) { throw; } } finally { _logger.Trace("[{0}] task completed with a result of [{1}].", taskName, success); } return(success); }
private bool _IsMonthlyDOMValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { if (_WindowIsValidForItem(scheduleItem, windowStart, windowEnd)) { // The window could potentially cross a date boundary. // The item is valid if the window crosses into the item's date. if (scheduleItem.DayDate != LastDay) { return(windowStart.Day == scheduleItem.DayDate || windowEnd.Day == scheduleItem.DayDate); } else { // If the item's DayDate value is LastDay, adjust it for the last day of // the current month. return(windowStart.Day == DateTime.DaysInMonth(windowStart.Year, windowStart.Month) || windowEnd.Day == DateTime.DaysInMonth(windowEnd.Year, windowEnd.Month)); } } return(false); }
private DateTime _GetDOWOccurrenceDate(IScheduleItem scheduleItem, int year, int month) { // An example item occurrence would be: 3rd Tuesday // Get the day of the week for the first day of the month. // (i.e. Month starts on a Thursday) int startingDayOfWeek = (int)new DateTime(year, month, 1).DayOfWeek; // Get the date of the first of the item's day-of-week for the month. // (i.e. Item happens on a Tuesday, get the first Tuesday of the month after the start of the month) int date; if (scheduleItem.DayDate < startingDayOfWeek) { // Item day-of-week is before the start of the month. Move to the next week. date = 7 - (startingDayOfWeek - scheduleItem.DayDate) + 1; } else { date = scheduleItem.DayDate - startingDayOfWeek + 1; } // If there is no day/date count, assume 1. int dayDateCount = Math.Max(1, scheduleItem.DayCount); // Get to the correct iteration of the day of the week. date += (dayDateCount - 1) * 7; // If the date exceeds the number of days in the month, back off one week. // *** Desired behavior? // Make it configurable? (back date off, ignore instance, last day of month) if (date > DateTime.DaysInMonth(year, month)) { date -= 7; } return(new DateTime(year, month, date)); }
private double _GetWindowEndRepetitions(IScheduleItem scheduleItem, DateTime windowEnd) { double value = 0; switch ((RecurrenceType)scheduleItem.RecurrenceType) { case RecurrenceType.Daily: value = (double)(windowEnd.Date - scheduleItem.StartDate.Date).Days / scheduleItem.DateUnitCount; break; case RecurrenceType.Weekly: // Adjust for the start date not being the first day the item occurs. value = (windowEnd.Date - scheduleItem.StartDate.Date).Days - _GetDayOfWeekAdjustment(scheduleItem); value = value / 7 / scheduleItem.DateUnitCount; break; case RecurrenceType.MonthlyDateOfMonth: value = _MonthSpan(scheduleItem.StartDate, windowEnd) / scheduleItem.DateUnitCount; // If the last item occurs after the window, trim it. if (_GetDOMLatestOccurrenceDate(scheduleItem, windowEnd) > windowEnd) { value--; } break; case RecurrenceType.MonthlyDayOfWeek: value = (double)(windowEnd.Month - scheduleItem.StartDate.Month + (windowEnd.Year - scheduleItem.StartDate.Year) * 12) / scheduleItem.DateUnitCount; // If the last item occurs after the window, trim it. if (_GetDOWLatestOccurrenceDate(scheduleItem, windowEnd) > windowEnd) { value--; } break; } return(value); }
private IEnumerable<int> _GetItemOccurenceIntervals(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { double windowStartRepetitions = _GetWindowStartRepetitions(scheduleItem, windowStart); double windowEndRepetitions = _GetWindowEndRepetitions(scheduleItem, windowEnd); // The window could potentially cross a time frame (day/week/month) boundary. bool windowIsValid = _IncludesIntegerBoundary(windowStartRepetitions, windowEndRepetitions); if(windowIsValid) { return _GetWindowOccurrenceIndexes(windowStartRepetitions, windowEndRepetitions); } return Enumerable.Empty<int>(); }
private DateTime _GetDOWOccurrenceDate(IScheduleItem scheduleItem, int year, int month) { // An example item occurrence would be: 3rd Tuesday // Get the day of the week for the first day of the month. // (i.e. Month starts on a Thursday) int startingDayOfWeek = (int)new DateTime(year, month, 1).DayOfWeek; // Get the date of the first of the item's day-of-week for the month. // (i.e. Item happens on a Tuesday, get the first Tuesday of the month after the start of the month) int date; if(scheduleItem.DayDate < startingDayOfWeek) { // Item day-of-week is before the start of the month. Move to the next week. date = 7 - (startingDayOfWeek - scheduleItem.DayDate) + 1; } else { date = scheduleItem.DayDate - startingDayOfWeek + 1; } // If there is no day/date count, assume 1. int dayDateCount = Math.Max(1, scheduleItem.DayCount); // Get to the correct iteration of the day of the week. date += (dayDateCount - 1) * 7; // If the date exceeds the number of days in the month, back off one week. // *** Desired behavior? // Make it configurable? (back date off, ignore instance, last day of month) if(date > DateTime.DaysInMonth(year, month)) { date -= 7; } return new DateTime(year, month, date); }
private DateTime _GetDOWOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate) { return(_GetDOWOccurrenceDate(scheduleItem, monthDate.Year, monthDate.Month)); }
private bool _RepeatingQualifier(IScheduleItem item, DateTime dateTime) { return dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < item.RunEndTime; }
private bool _IsWeeklyValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { if(_WindowIsValidForItem(scheduleItem, windowStart, windowEnd)) { // The window could potentially cross a day boundary. // The item is valid if the window crosses into the item's day. return (int)windowStart.DayOfWeek == scheduleItem.DayDate || (int)windowEnd.DayOfWeek == scheduleItem.DayDate; } return false; }
private bool _IsMonthlyDOWValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { if(_WindowIsValidForItem(scheduleItem, windowStart, windowEnd)) { // The window could potentially cross a day boundary. // The item is valid if the window crosses into the item's day. if((int)windowStart.DayOfWeek == scheduleItem.DayDate || (int)windowEnd.DayOfWeek == scheduleItem.DayDate) { // Window crosses the correct day. // Does it cross the correct iteration of the day? return _IterationOfDayOfWeek(windowStart.Day) == scheduleItem.DayCount || _IterationOfDayOfWeek(windowEnd.Day) == scheduleItem.DayCount; } } return false; }
private bool _IntervalRepeatingQualifier(IScheduleItem item, DateTime dateTime) { // If within the block of time... if(dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < item.RunEndTime) { // Generate interval blocks for(TimeSpan time = item.RunStartTime; time < item.RunEndTime; time += TimeSpan.FromMinutes(item.RepeatIntervalMinutes)) { // Has to be within the scheduled minute. if(dateTime.TimeOfDay >= time && dateTime.TimeOfDay < dateTime.TimeOfDay + TimeSpan.FromMinutes(1)) { return true; } } } return false; }
private IEnumerable<DateTime> _GetWeeklyInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { IEnumerable<int> intervals = _GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd); // Create DateTime instances for each occurrence. DateTime instance = scheduleItem.StartDate + scheduleItem.RunStartTime; // Need to start on the correct day of the week at/after the item start date. instance = instance.AddDays(_GetDayOfWeekAdjustment(scheduleItem)); return from interval in intervals select instance.AddDays(7 * interval * scheduleItem.DateUnitCount); }
private IEnumerable<DateTime> _GetMonthlyDOMInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { // Create DateTime instances for each occurrence. IEnumerable<int> intervals = _GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd); // Create DateTime instances for each occurrence. // This is the only item type where the item date is absolute rather // than relative to the start date. DateTime startDate = scheduleItem.StartDate; if(scheduleItem.DayDate != LastDay) { DateTime instance = new DateTime(startDate.Year, startDate.Month, scheduleItem.DayDate) + scheduleItem.RunStartTime; return from interval in intervals select instance.AddMonths(interval * scheduleItem.DateUnitCount); } else { // If the item's DayDate value is LastDay, adjust each for the last day of // the month. // Start with an initial date based on the item start date. Day of the // month is unimportant. DateTime instance = new DateTime(startDate.Year, startDate.Month, 1); return intervals.Select<int, DateTime>(interval => { // Offset the initial date by an appropriate number of months. DateTime offsetInstance = instance.AddMonths(interval * scheduleItem.DateUnitCount); // With the date now being in the correct year and month, create a // new date with the day set correctly. return new DateTime(offsetInstance.Year, offsetInstance.Month, DateTime.DaysInMonth(offsetInstance.Year, offsetInstance.Month)) + scheduleItem.RunStartTime; }); } }
private bool _IsDailyValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { return(_WindowIsValidForItem(scheduleItem, windowStart, windowEnd)); }
private bool _OneTimeTimeQualifier(IScheduleItem item, DateTime dateTime) { return(dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < (item.RunStartTime + TimeSpan.FromMinutes(1))); }
/// <summary> /// Provides a readable text summary of a schedule item. /// </summary> /// <param name="scheduleItem"></param> /// <returns></returns> public string GetItemSummary(IScheduleItem scheduleItem) { StringBuilder sb = new StringBuilder(); RecurrenceType recurrenceType = (RecurrenceType)scheduleItem.RecurrenceType; string unit = ""; switch (recurrenceType) { case RecurrenceType.Daily: unit = "day"; break; case RecurrenceType.Weekly: unit = "week"; break; case RecurrenceType.MonthlyDateOfMonth: unit = "month"; break; case RecurrenceType.MonthlyDayOfWeek: unit = "month"; break; } sb.Append("Every "); if (scheduleItem.DateUnitCount > 1) { sb.AppendFormat(" {0} {1}s", scheduleItem.DateUnitCount, unit); } else { sb.Append(unit); } switch (recurrenceType) { case RecurrenceType.Daily: // Nothing to do break; case RecurrenceType.Weekly: sb.Append(" on " + (DayOfWeek.Sunday + scheduleItem.DayDate).ToString()); break; case RecurrenceType.MonthlyDateOfMonth: if (scheduleItem.DayDate != LastDay) { sb.Append(" on the " + _AppendCount(scheduleItem.DayDate)); } else { sb.Append(" on the last day of the month "); } break; case RecurrenceType.MonthlyDayOfWeek: sb.AppendFormat(" on the {0} {1}", _AppendCount(scheduleItem.DayCount), (DayOfWeek.Sunday + scheduleItem.DayDate).ToString()); break; } sb.AppendFormat(" at " + scheduleItem.RunStartTime.ToString("hh:mm tt")); sb.AppendFormat(" starting on " + scheduleItem.StartDate.ToShortDateString()); return(sb.ToString()); }
private IEnumerable<DateTime> _GetMonthlyDOWInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { // Create DateTime instances for each occurrence. List<int> intervals = new List<int>(_GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd)); // Start in the month of the item's start date. DateTime instance = _GetDOWOccurrenceDate(scheduleItem, scheduleItem.StartDate); return from interval in intervals select _GetDOWOccurrenceDate(scheduleItem, instance.AddMonths(interval * scheduleItem.DateUnitCount)); }
public ScheduleItemArgs(IScheduleItem item) { Item = item; }
private double _GetWindowStartRepetitions(IScheduleItem scheduleItem, DateTime windowStart) { double value = 0; switch((RecurrenceType)scheduleItem.RecurrenceType) { case RecurrenceType.Daily: value = (double)(windowStart.Date - scheduleItem.StartDate.Date).Days / scheduleItem.DateUnitCount; break; case RecurrenceType.Weekly: // Adjust for the start date not being the first day the item occurs. value = (windowStart.Date - scheduleItem.StartDate.Date).Days - _GetDayOfWeekAdjustment(scheduleItem); value = value / 7 / scheduleItem.DateUnitCount; break; case RecurrenceType.MonthlyDateOfMonth: value = _MonthSpan(scheduleItem.StartDate, windowStart) / scheduleItem.DateUnitCount; // If the first item occurs before the window, trim it. if(scheduleItem.DayDate != LastDay && scheduleItem.DayDate < windowStart.Day) { value++; } break; case RecurrenceType.MonthlyDayOfWeek: value = (double)(windowStart.Month - scheduleItem.StartDate.Month + (windowStart.Year - scheduleItem.StartDate.Year) * 12) / scheduleItem.DateUnitCount; // If the first item occurs before the window, trim it. if(_GetDOWOccurrenceDate(scheduleItem, windowStart) < windowStart) { value++; } break; } return value; }
private IEnumerable<DateTime> _GetDailyInstances(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { IEnumerable<int> intervals = _GetItemOccurenceIntervals(scheduleItem, windowStart, windowEnd); // Create DateTime instances for each occurrence. DateTime instance = scheduleItem.StartDate + scheduleItem.RunStartTime; return from interval in intervals select instance.AddDays(interval * scheduleItem.DateUnitCount); }
private bool _IsMonthlyDOMValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { if(_WindowIsValidForItem(scheduleItem, windowStart, windowEnd)) { // The window could potentially cross a date boundary. // The item is valid if the window crosses into the item's date. if(scheduleItem.DayDate != LastDay) { return windowStart.Day == scheduleItem.DayDate || windowEnd.Day == scheduleItem.DayDate; } else { // If the item's DayDate value is LastDay, adjust it for the last day of // the current month. return windowStart.Day == DateTime.DaysInMonth(windowStart.Year, windowStart.Month) || windowEnd.Day == DateTime.DaysInMonth(windowEnd.Year, windowEnd.Month); } } return false; }
private int _GetDayOfWeekAdjustment(IScheduleItem scheduleItem) { // The start date of the item may not fall on the same day of the week // that the item occurs on. if((int)scheduleItem.StartDate.DayOfWeek != scheduleItem.DayDate) { return 7 - Math.Abs((int)scheduleItem.StartDate.DayOfWeek - scheduleItem.DayDate); } return 0; }
private bool _IsSingleValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { return _WindowIsValidForItem(scheduleItem, windowStart, windowEnd); }
/// <summary> /// Gets the last DateTime occurrence of the item between the item's start and the provided month/year date. /// </summary> /// <param name="scheduleItem"></param> /// <param name="monthDate">Month and year, day of the month is not considered.</param> /// <returns>Returned DateTime may occur before the provided DateTime.</returns> private DateTime _GetDOMLatestOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate) { int iterations = (monthDate.Month - scheduleItem.StartDate.Month + (monthDate.Year - scheduleItem.StartDate.Year) * 12) / scheduleItem.DateUnitCount; int day = scheduleItem.DayDate == LastDay ? DateTime.DaysInMonth(monthDate.Year, monthDate.Month) : scheduleItem.DayDate; DateTime lastItem = scheduleItem.StartDate.AddMonths(iterations * scheduleItem.DateUnitCount); return new DateTime(lastItem.Year, lastItem.Month, day); }
private bool _OneTimeTimeQualifier(IScheduleItem item, DateTime dateTime) { return dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < (item.RunStartTime + TimeSpan.FromMinutes(1)); }
private DateTime _GetDOWLatestOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate) { int iterations = (monthDate.Month - scheduleItem.StartDate.Month + (monthDate.Year - scheduleItem.StartDate.Year) * 12) / scheduleItem.DateUnitCount; DateTime lastItemMonth = scheduleItem.StartDate.AddMonths(iterations * scheduleItem.DateUnitCount); return _GetDOWOccurrenceDate(scheduleItem, lastItemMonth); }
private bool _WindowIsValidForItem(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd) { double windowStartRepetitions = _GetWindowStartRepetitions(scheduleItem, windowStart); double windowEndRepetitions = _GetWindowEndRepetitions(scheduleItem, windowEnd); // The window could potentially cross a time frame (day/week/month) boundary. return _IncludesIntegerBoundary(windowStartRepetitions, windowEndRepetitions); }
private DateTime _GetDOWOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate) { return _GetDOWOccurrenceDate(scheduleItem, monthDate.Year, monthDate.Month); }
private bool MatchOnVariableName(IScheduleItem <T> orchestrateItem, object[] args) { return(orchestrateItem.TriggerVariableName == args[0].ToString()); }
/// <summary> /// Compare this to another Scheduled item /// </summary> /// <param name="other"></param> /// <returns></returns> public int CompareTo(IScheduleItem <T> other) { return(Timestamp.CompareTo(other.Timestamp)); }
/// <summary> /// Compare two Schedule items /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns>int of the comparison</returns> public int Compare(IScheduleItem <T> x, IScheduleItem <T> y) { return(x.CompareTo(y)); }