Пример #1
0
        public static SchedulerPlanning CreatePlan()
        {
            SchedulerPlanning p = new SchedulerPlanning();

            p.Planning = SchedulerPlanningType.None;
            return(p);
        }
Пример #2
0
        public static SchedulerPlanning CreatePlan(DateTime OneTime)
        {
            SchedulerPlanning p = new SchedulerPlanning();

            p.Planning  = SchedulerPlanningType.OneTime;
            p.StartDate = OneTime;
            return(p);
        }
Пример #3
0
        public static SchedulerPlanning CreatePlan(DateTime StartTime, int RecurrenceDays)
        {
            SchedulerPlanning p = new SchedulerPlanning();

            p.Planning   = SchedulerPlanningType.Daily;
            p.StartDate  = StartTime;
            p.Recurrence = RecurrenceDays;
            return(p);
        }
Пример #4
0
        public static SchedulerPlanning CreatePlan(DateTime StartTime, List <int> Days, List <int> Months)
        {
            SchedulerPlanning p = new SchedulerPlanning();

            p.Planning      = SchedulerPlanningType.Monthly;
            p.StartDate     = StartTime;
            p.RecurInMonths = Months;
            p.RecurInDay    = Days;
            return(p);
        }
Пример #5
0
        public static SchedulerPlanning CreatePlan(DateTime StartTime, int RecurrenceWeeks, List <DayOfWeek> Days)
        {
            SchedulerPlanning p = new SchedulerPlanning();

            p.Planning        = SchedulerPlanningType.Weekly;
            p.StartDate       = StartTime;
            p.Recurrence      = RecurrenceWeeks;
            p.RecurInWeekDays = Days;
            return(p);
        }
Пример #6
0
        public static string Explain(SchedulerPlanning Plan)
        {
            if (Plan == null)
            {
                Plan = Scheduler.Nix;
            }

            string s = "<Invalid>";

            switch (Plan.Planning)
            {
            case SchedulerPlanningType.None:
                s = "No schedule";
                break;

            case SchedulerPlanningType.OneTime:
                s = "Once at " + Plan.StartDate.ToLocalTime().ToLongDateString() + " " + Plan.StartDate.ToLocalTime().ToLongTimeString();
                break;

            case SchedulerPlanningType.Daily:
                if (Plan.Recurrence == null)
                {
                    break;
                }
                s = "Starting from " + Plan.StartDate.ToLocalTime().ToLongDateString() + " " + Plan.StartDate.ToLocalTime().ToLongTimeString() + ", every " +
                    Plan.Recurrence.ToString() + " day" + (Plan.Recurrence == 1 ? "" : "s");
                break;

            case SchedulerPlanningType.Weekly:
                if (Plan.Recurrence == null)
                {
                    break;
                }
                if (Plan.RecurInWeekDays == null || Plan.RecurInWeekDays.Count == 0)
                {
                    break;
                }
                s = "Starting from " + Plan.StartDate.ToLocalTime().ToLongDateString() + " " + Plan.StartDate.ToLocalTime().ToLongTimeString() + ", every " +
                    Plan.Recurrence.ToString() + " week" + (Plan.Recurrence == 1 ? "" : "s") + " on ";
                foreach (DayOfWeek dow in Plan.RecurInWeekDays)
                {
                    s += Thread.CurrentThread.CurrentCulture.DateTimeFormat.GetDayName(dow) + ", ";
                }
                if (s.EndsWith(", ") == true)
                {
                    s = s.Substring(0, s.Length - 2);
                }
                break;

            case SchedulerPlanningType.Monthly:
                if (Plan.RecurInDay == null || Plan.RecurInDay.Count == 0)
                {
                    break;
                }
                if (Plan.RecurInMonths == null || Plan.RecurInMonths.Count == 0)
                {
                    break;
                }
                s = "Starting from " + Plan.StartDate.ToLocalTime().ToLongDateString() + " " + Plan.StartDate.ToLocalTime().ToLongTimeString() + ", every ";
                foreach (int Month in Plan.RecurInMonths)
                {
                    s += Thread.CurrentThread.CurrentCulture.DateTimeFormat.GetMonthName(Month) + ", ";
                }
                if (s.EndsWith(", ") == true)
                {
                    s = s.Substring(0, s.Length - 2);
                }
                s += " on these day" + (Plan.RecurInDay.Count == 1 ? "" : "s") + " ";
                foreach (int days in Plan.RecurInDay)
                {
                    s += days.ToString() + ", ";
                }
                if (s.EndsWith(", ") == true)
                {
                    s = s.Substring(0, s.Length - 2);
                }
                break;
            }

            return(s);
        }
Пример #7
0
        public static DateTime?GetNextRunDate(DateTime LastRunTime, SchedulerPlanning Plan)
        {
            if (Plan.Planning == SchedulerPlanningType.None)
            {
                return(null);
            }
            if (Plan.Planning == SchedulerPlanningType.OneTime)
            {
                if (Plan.StartDate >= LastRunTime)
                {
                    return(Plan.StartDate);
                }
                return(null);
            }
            if (Plan.Planning == SchedulerPlanningType.Daily)
            {
                if (Plan.StartDate >= LastRunTime)
                {
                    return(Plan.StartDate);
                }
                if (Plan.Recurrence == null || Plan.Recurrence < 1)
                {
                    return(null);
                }
                DateTime DT = Plan.StartDate;
                while (LastRunTime >= DT)
                {
                    DT = DT.AddDays(Plan.Recurrence.Value);
                }
                return(DT);
            }
            if (Plan.Planning == SchedulerPlanningType.Weekly)
            {
                if (Plan.StartDate >= LastRunTime)
                {
                    return(SetToNextDay(Plan.StartDate.AddDays(-1), Plan.RecurInWeekDays));
                }
                if (Plan.Recurrence == null || Plan.Recurrence < 1)
                {
                    return(null);
                }
                DateTime DT = Plan.StartDate;
                if (SetToNextDay(DT, Plan.RecurInWeekDays) == null)
                {
                    return(null);
                }
                DT = SetToNextDay(DT, Plan.RecurInWeekDays).Value;
                int CurrentWeekNumber = GetWeekNumber(DT);
                while (LastRunTime >= DT)
                {
                    DateTime nDT = SetToNextDay(DT, Plan.RecurInWeekDays).Value;
                    if (CurrentWeekNumber != GetWeekNumber(nDT))
                    {
                        switch (nDT.DayOfWeek)
                        {
                        case DayOfWeek.Monday: nDT = nDT.AddDays(7); break;

                        case DayOfWeek.Tuesday: nDT = nDT.AddDays(6); break;

                        case DayOfWeek.Wednesday: nDT = nDT.AddDays(5); break;

                        case DayOfWeek.Thursday: nDT = nDT.AddDays(4); break;

                        case DayOfWeek.Friday: nDT = nDT.AddDays(3); break;

                        case DayOfWeek.Saturday: nDT = nDT.AddDays(2); break;

                        case DayOfWeek.Sunday: nDT = nDT.AddDays(1); break;
                        }
                        nDT = nDT.AddDays(7 * (Plan.Recurrence.Value - 1));
                        nDT = nDT.AddDays(-1);
                        nDT = SetToNextDay(nDT, Plan.RecurInWeekDays).Value;
                        DT  = nDT;
                    }
                    else
                    {
                        DT = nDT;
                    }
                }
                return(DT);
            }
            if (Plan.Planning == SchedulerPlanningType.Monthly)
            {
                if (Plan.StartDate >= LastRunTime)
                {
                    return(SetToNextDay(Plan.StartDate.AddDays(-1), Plan.RecurInDay, Plan.RecurInMonths));
                }
                DateTime DT = Plan.StartDate;
                if (SetToNextDay(DT, Plan.RecurInDay, Plan.RecurInMonths) == null)
                {
                    return(null);
                }
                while (LastRunTime >= DT)
                {
                    DT = SetToNextDay(DT, Plan.RecurInDay, Plan.RecurInMonths).Value;
                }
                return(DT);
            }

            return(null);
        }