Пример #1
0
        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;
                }));
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
 protected void RaiseScheduledItemCompleted(IScheduleItem <T> scheduleItem)
 {
     Task.Run(() =>
     {
         ScheduledItemCompletedEventArgs <T> reached = new ScheduledItemCompletedEventArgs <T>(scheduleItem);
         ScheduledItemCompleted?.Invoke(this, reached);
     });
 }
Пример #5
0
        /// <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));
        }
Пример #6
0
 /// <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);
     //}
 }
Пример #7
0
		/// <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();
		}
Пример #8
0
        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));
        }
Пример #9
0
 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);
 }
Пример #10
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);
 }
Пример #11
0
        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)));
        }
Пример #12
0
        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);
        }
Пример #14
0
 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();
         }
     }
 }
Пример #15
0
        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>());
        }
Пример #16
0
 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);
 }
Пример #17
0
 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();
         }
     }
 }
Пример #18
0
        /// <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);
        }
Пример #19
0
        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);
        }
Пример #20
0
        /// <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);
        }
Пример #21
0
 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);
 }
Пример #22
0
        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));
        }
Пример #23
0
        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);
        }
Пример #24
0
        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>();
        }
Пример #25
0
        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);
        }
Пример #26
0
 private DateTime _GetDOWOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate)
 {
     return(_GetDOWOccurrenceDate(scheduleItem, monthDate.Year, monthDate.Month));
 }
Пример #27
0
 private bool _RepeatingQualifier(IScheduleItem item, DateTime dateTime)
 {
     return dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < item.RunEndTime;
 }
Пример #28
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;
 }
Пример #29
0
 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;
 }
Пример #30
0
        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;
        }
Пример #31
0
 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);
 }
Пример #32
0
        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;
                });
            }
        }
Пример #33
0
 private bool _IsDailyValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd)
 {
     return(_WindowIsValidForItem(scheduleItem, windowStart, windowEnd));
 }
Пример #34
0
 private bool _OneTimeTimeQualifier(IScheduleItem item, DateTime dateTime)
 {
     return(dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < (item.RunStartTime + TimeSpan.FromMinutes(1)));
 }
Пример #35
0
        /// <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());
        }
Пример #36
0
 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));
 }
Пример #37
0
 public ScheduleItemArgs(IScheduleItem item)
 {
     Item = item;
 }
Пример #38
0
        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;
        }
Пример #39
0
 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);
 }
Пример #40
0
 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;
 }
Пример #41
0
 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;
 }
Пример #42
0
 private bool _IsSingleValid(IScheduleItem scheduleItem, DateTime windowStart, DateTime windowEnd)
 {
     return _WindowIsValidForItem(scheduleItem, windowStart, windowEnd);
 }
Пример #43
0
 /// <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);
 }
Пример #44
0
 private bool _OneTimeTimeQualifier(IScheduleItem item, DateTime dateTime)
 {
     return dateTime.TimeOfDay >= item.RunStartTime && dateTime.TimeOfDay < (item.RunStartTime + TimeSpan.FromMinutes(1));
 }
Пример #45
0
 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);
 }
Пример #46
0
        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);
        }
Пример #47
0
 private DateTime _GetDOWOccurrenceDate(IScheduleItem scheduleItem, DateTime monthDate)
 {
     return _GetDOWOccurrenceDate(scheduleItem, monthDate.Year, monthDate.Month);
 }
Пример #48
0
 private bool MatchOnVariableName(IScheduleItem <T> orchestrateItem, object[] args)
 {
     return(orchestrateItem.TriggerVariableName == args[0].ToString());
 }
Пример #49
0
 /// <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));
 }
Пример #50
0
 public ScheduleItemArgs(IScheduleItem item)
 {
     Item = item;
 }
Пример #51
0
 /// <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));
 }