Ejemplo n.º 1
0
        public DateTime GetNextOccurrence(DateTime baseTime)
        {
            var nextScheduleTime = new ScheduleTime(baseTime.AddSeconds(1));

            return GetNextOccurrence(nextScheduleTime);
        }
Ejemplo n.º 2
0
 private void WrapToNextMinute(ScheduleTime next)
 {
     next.Minute++;
     next.Second = SecondField.GetFirst().Value;
 }
Ejemplo n.º 3
0
 private void WrapToNextYear(ScheduleTime next)
 {
     next.Year++;
     next.Month = MonthField.GetFirst().Value;
     next.Day = DayOfMonthField.GetFirst().Value;
     next.Hour = HourField.GetFirst().Value;
     next.Minute = MinuteField.GetFirst().Value;
 }
Ejemplo n.º 4
0
 private void WrapToNextDay(ScheduleTime next)
 {
     next.Day++;
     next.Hour = HourField.GetFirst().Value;
     next.Minute = MinuteField.GetFirst().Value;
 }
Ejemplo n.º 5
0
 private void WrapToNextHour(ScheduleTime next)
 {
     next.Hour++;
     next.Minute = MinuteField.GetFirst().Value;
 }
Ejemplo n.º 6
0
        private void CalculateNextScheduledMinute(ScheduleTime next)
        {
            CronValue scheduledMinute = MinuteField.GetNext(next.Minute);

            if (scheduledMinute == CronValue.Wrapped)
            {
                WrapToNextHour(next);
            }
            else if (scheduledMinute.Value > next.Minute)
            {
                SetStartOfMinute(next, scheduledMinute);
            }
            else
            {
                next.Minute = scheduledMinute.Value;
            }
        }
Ejemplo n.º 7
0
 private DateTime TryCorrectScheduleForDaysInMonth(ScheduleTime nextScheduleTime)
 {
     try
     {
         return CorrectScheduleForDaysInMonth(nextScheduleTime);
     }
     catch (ArgumentOutOfRangeException ex)
     {
         throw new CronException(ErrorMessages.NoScheduleFound, ex);
     }
 }
Ejemplo n.º 8
0
 private void SetStartOfHour(ScheduleTime next, CronValue scheduledHour)
 {
     next.Hour = scheduledHour.Value;
     next.Minute = MinuteField.GetFirst().Value;
 }
Ejemplo n.º 9
0
 private void SetStartOfMinute(ScheduleTime next, CronValue scheduledMinute)
 {
     next.Minute = scheduledMinute.Value;
     next.Second = SecondField.GetFirst().Value;
 }
Ejemplo n.º 10
0
        private DateTime GetNextOccurrence(ScheduleTime nextScheduleTime)
        {
            CalculateNextScheduledSecond(nextScheduleTime);
            CalculateNextScheduledMinute(nextScheduleTime);
            CalculateNextScheduledHour(nextScheduleTime);
            CalculateNextScheduledDay(nextScheduleTime);
            CalculateNextScheduledMonth(nextScheduleTime);

            var nextTime = TryCorrectScheduleForDaysInMonth(nextScheduleTime);
            return CorrectScheduleForDayOfWeek(nextTime);
        }
Ejemplo n.º 11
0
 private void SetStartOfDay(ScheduleTime next, CronValue scheduledDay)
 {
     next.Day = scheduledDay.Value;
     next.Hour = HourField.GetFirst().Value;
     next.Minute = MinuteField.GetFirst().Value;
 }
Ejemplo n.º 12
0
        private DateTime CorrectScheduleForDaysInMonth(ScheduleTime nextScheduleTime)
        {
            for (int i = 0; i <= MaxDayInMonthFixAttempts; i++)
            {
                if (MonthContainsDate(nextScheduleTime))
                {
                    return nextScheduleTime.ToDateTime();
                }

                WrapToNextMonth(nextScheduleTime);
                CalculateNextScheduledMonth(nextScheduleTime);
            }

            throw new CronException(ErrorMessages.NoScheduleFound);
        }
Ejemplo n.º 13
0
        private void CalculateNextScheduledSecond(ScheduleTime next)
        {
            CronValue scheduledSecond = SecondField.GetNext(next.Second);

            if (scheduledSecond == CronValue.Wrapped)
            {
                WrapToNextMinute(next);
            }
            else
            {
                next.Second = scheduledSecond.Value;
            }
        }
Ejemplo n.º 14
0
        private void CalculateNextScheduledMonth(ScheduleTime next)
        {
            CronValue scheduledMonth = MonthField.GetNext(next.Month);

            if (scheduledMonth == CronValue.Wrapped)
            {
                WrapToNextYear(next);
            }
            else if (scheduledMonth.Value > next.Month)
            {
                SetStartOfMonth(next, scheduledMonth);
            }
            else
            {
                next.Month = scheduledMonth.Value;
            }
        }
Ejemplo n.º 15
0
 private static bool MonthContainsDate(ScheduleTime nextScheduleTime)
 {
     return nextScheduleTime.Day <= Calendar.GetDaysInMonth(nextScheduleTime.Year, nextScheduleTime.Month);
 }
Ejemplo n.º 16
0
 private void SetStartOfMonth(ScheduleTime next, CronValue scheduledMonth)
 {
     next.Month = scheduledMonth.Value;
     next.Day = DayOfMonthField.GetFirst().Value;
     next.Hour = HourField.GetFirst().Value;
     next.Minute = MinuteField.GetFirst().Value;
 }
Ejemplo n.º 17
0
        private void CalculateNextScheduledDay(ScheduleTime next)
        {
            CronValue scheduledDay = DayOfMonthField.GetNext(next.Day);

            if (scheduledDay == CronValue.Wrapped)
            {
                WrapToNextMonth(next);
            }
            else if (scheduledDay.Value > next.Day)
            {
                SetStartOfDay(next, scheduledDay);
            }
            else
            {
                next.Day = scheduledDay.Value;
            }
        }
Ejemplo n.º 18
0
        private void CalculateNextScheduledHour(ScheduleTime next)
        {
            CronValue scheduledHour = HourField.GetNext(next.Hour);

            if (scheduledHour == CronValue.Wrapped)
            {
                WrapToNextDay(next);
            }
            else if (scheduledHour.Value > next.Hour)
            {
                SetStartOfHour(next, scheduledHour);
            }
            else
            {
                next.Hour = scheduledHour.Value;
            }
        }