Example #1
0
        public void CalculateNextRunDate()
        {
            switch (Interval)
            {
            case Interval.Day:
                NextRun = NextRun.AddDays(1);
                break;

            case Interval.Week:
                NextRun = NextRun.AddDays(7);
                break;

            case Interval.Month:
                NextRun = NextRun.AddMonths(1);
                break;
            }
        }
        public void Next()
        {
            switch (Type)
            {
            case ScheduleType.ByInterval:
                NextRun += Time;
                if (ShouldRun())
                {
                    NextRun = DateTime.UtcNow;
                }
                break;

            case ScheduleType.Daily:
                do
                {
                    NextRun = NextRun.AddDays(1);
                } while (ShouldRun());
                break;

            default:
                break;
            }
        }
        public ScheduleInfo(ScheduleType type, TimeSpan time, IRegularAsync action)
        {
            Type   = type;
            Time   = time;
            Action = action;
            switch (Type)
            {
            case ScheduleType.ByInterval:
                NextRun = DateTime.UtcNow;
                break;

            case ScheduleType.Daily:
                NextRun = DateTime.UtcNow.Date + time;
                if (ShouldRun())
                {
                    NextRun = NextRun.AddDays(1);
                }
                break;

            default:
                throw new ArgumentException("类型不对", nameof(type));
            }
        }