DateTime GetRuntimeForWeekly(DateTime now, WeeklySchedule schedule) { var @ref = new DateTime(now.Year, now.Month, now.Day).AddDays( now.DayOfWeek==DayOfWeek.Sunday? 1 : -((int)now.DayOfWeek-1) ); @ref = @ref.AddDays( AdjustEvery(GetIso8601WeekOfYear(@ref), schedule.Every)*7 ); for (;;) { var time = new DateTime(@ref.Year, @ref.Month, @ref.Day, schedule.RunAt.Hour,schedule.RunAt.Minute,0); var endWeek = new DateTime(@ref.Year, @ref.Month, @ref.Day).AddDays(7); while (time < endWeek) { if (time < now) { time = time.AddDays(1); continue; } switch (time.DayOfWeek) { case DayOfWeek.Monday: if (schedule.JobDays.HasFlag(JobDays.Monday)) return time; break; case DayOfWeek.Tuesday: if (schedule.JobDays.HasFlag(JobDays.Tuesday)) return time; break; case DayOfWeek.Wednesday: if (schedule.JobDays.HasFlag(JobDays.Wednesday)) return time; break; case DayOfWeek.Thursday: if (schedule.JobDays.HasFlag(JobDays.Thursday)) return time; break; case DayOfWeek.Friday: if (schedule.JobDays.HasFlag(JobDays.Friday)) return time; break; case DayOfWeek.Saturday: if (schedule.JobDays.HasFlag(JobDays.Saturday)) return time; break; case DayOfWeek.Sunday: if (schedule.JobDays.HasFlag(JobDays.Sunday)) return time; break; } time = time.AddDays(1); } @ref = @ref.AddDays(schedule.Every*7); } }
public JobSchedule() { ScheduleType = JobScheduleType.Weekly; Daily = new DailySchedule(); Weekly = new WeeklySchedule(); Monthly = new MonthlySchedule(); }