예제 #1
0
        public static void NextRun(string schedule, DateTime current, out DateTime nextRun)
        {
            if (schedule.Trim() == string.Empty || schedule.Trim() == Constants.TimerScheduleWhenPublished)
            {
                nextRun = new DateTime(3000, 1, 1);
                return;
            }

            schedule = TrimEndAndEnsureDoubleDigits(schedule);

            string[]     scheduleParts = schedule.Split(' ');
            scheduleType schType       = scheduleType.Invalid;

            List <string> hoursInSchedule;
            List <string> daysInSchedule;
            List <string> weekdaysInSchedule;
            string        ordinalInSchedule;

            ValidateAndSeparateScheduleParts(scheduleParts, out schType, out hoursInSchedule, out daysInSchedule, out weekdaysInSchedule, out ordinalInSchedule);

            TimeSpan ts = new TimeSpan(0, 0, 0, 0);

            switch (schType)
            {
            case scheduleType.TimeOnly:
                // daily at the same hours
                CalculateNextTimeSpan(current, hoursInSchedule.ToArray(), out ts);
                break;

            case scheduleType.TimeDays:
                // on those days of the month at those hours
                CalculateNextDayOfMonthSpan(current, hoursInSchedule.ToArray(), daysInSchedule.ToArray(), out ts);
                break;

            case scheduleType.TimeOrdinalWeekday:
                // on the nth weekday of the month
                CalculateNextWeekdayOfMonthSpan(current, hoursInSchedule.ToArray(), ordinalInSchedule, weekdaysInSchedule[0], out nextRun);
                return;

            case scheduleType.TimeWeekdays:
                // on those days of the week at those hours
                CalculateNextWeekDaySpan(current, hoursInSchedule.ToArray(), weekdaysInSchedule.ToArray(), out ts);
                break;
            }

            if (!schType.Equals(scheduleType.Invalid))
            {
                nextRun = current.Add(ts);
            }
            else
            {
                nextRun = new DateTime(3000, 1, 1);
            }
        }
예제 #2
0
        public static bool ValidateSchedule(string schedule)
        {
            if (schedule == string.Empty)
            {
                return(true);
            }

            schedule = TrimEndAndEnsureDoubleDigits(schedule);

            List <string> hoursInSchedule;
            List <string> daysInSchedule;
            List <string> weekdaysInSchedule;
            string        ordinalInSchedule;

            string[]     scheduleParts = schedule.Split(' ');
            scheduleType schType       = scheduleType.Invalid;

            ValidateAndSeparateScheduleParts(scheduleParts, out schType, out hoursInSchedule, out daysInSchedule, out weekdaysInSchedule, out ordinalInSchedule);

            return(!schType.Equals(scheduleType.Invalid));
        }