public void TestDayLightSaving() { var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); var trigger = DailyTimeIntervalScheduleBuilder.Create() .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(22, 15)) .OnEveryDay() .WithIntervalInHours(24) .WithRepeatCount(9999) .InTimeZone(timeZoneInfo) .Build(); var first = trigger.GetFireTimeAfter(new DateTimeOffset(2014, 10, 25, 0, 0, 0, TimeSpan.Zero)); Assert.That(first, Is.EqualTo(new DateTimeOffset(2014, 10, 25, 22, 15, 0, TimeSpan.FromHours(1)))); var second = trigger.GetFireTimeAfter(first); Assert.That(second, Is.EqualTo(new DateTimeOffset(2014, 10, 26, 22, 15, 0, TimeSpan.FromHours(0)))); var third = trigger.GetFireTimeAfter(second); Assert.That(third, Is.EqualTo(new DateTimeOffset(2014, 10, 27, 22, 15, 0, TimeSpan.FromHours(0)))); }
protected override TriggerPropertyBundle GetTriggerPropertyBundle(SimplePropertiesTriggerProperties props) { int repeatCount = (int)props.Long1; int interval = props.Int1; string intervalUnitStr = props.String1; string daysOfWeekStr = props.String2; string timeOfDayStr = props.String3; IntervalUnit intervalUnit = (IntervalUnit)Enum.Parse(typeof(IntervalUnit), intervalUnitStr, true); DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder.Create() .WithInterval(interval, intervalUnit) .WithRepeatCount(repeatCount); if (daysOfWeekStr != null) { ISet <DayOfWeek> daysOfWeek = new HashSet <DayOfWeek>(); string[] nums = daysOfWeekStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (nums.Length > 0) { foreach (String num in nums) { daysOfWeek.Add((DayOfWeek)Int32.Parse(num)); } scheduleBuilder.OnDaysOfTheWeek(daysOfWeek); } } else { scheduleBuilder.OnDaysOfTheWeek(DailyTimeIntervalScheduleBuilder.AllDaysOfTheWeek); } if (timeOfDayStr != null) { string[] nums = timeOfDayStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); TimeOfDay startTimeOfDay; if (nums.Length >= 3) { int hour = Int32.Parse(nums[0]); int min = Int32.Parse(nums[1]); int sec = Int32.Parse(nums[2]); startTimeOfDay = new TimeOfDay(hour, min, sec); } else { startTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0); } scheduleBuilder.StartingDailyAt(startTimeOfDay); TimeOfDay endTimeOfDay; if (nums.Length >= 6) { int hour = Int32.Parse(nums[3]); int min = Int32.Parse(nums[4]); int sec = Int32.Parse(nums[5]); endTimeOfDay = new TimeOfDay(hour, min, sec); } else { endTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59); } scheduleBuilder.EndingDailyAt(endTimeOfDay); } else { scheduleBuilder.StartingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0)); scheduleBuilder.EndingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59)); } int timesTriggered = props.Int2; string[] statePropertyNames = { "timesTriggered" }; object[] statePropertyValues = { timesTriggered }; return(new TriggerPropertyBundle(scheduleBuilder, statePropertyNames, statePropertyValues)); }
public ITrigger GetQuartzTrigger(string JobName, string JobGroup) { var trigger = TriggerBuilder .Create() .WithIdentity(this.Name, this.Group) .ForJob(JobName, JobGroup); switch (this.Period) { case PeriodType.Giornaliero: var dayScheduler = DailyTimeIntervalScheduleBuilder .Create() .OnEveryDay() .InTimeZone(TimeZoneInfo.Local) .StartingDailyAt(new TimeOfDay(this.StartDate.Hour, this.StartDate.Minute, this.StartDate.Second)); if (this.Interval > 0) { dayScheduler.WithInterval(this.Interval, this.IntervalUnit); if (this.LifeUnit == IntervalUnit.Hour) { dayScheduler.EndingDailyAt(new TimeOfDay(this.StartDate.AddHours(this.Life).Hour, this.StartDate.Minute, this.StartDate.Minute)); } else { dayScheduler.EndingDailyAt(new TimeOfDay(this.StartDate.AddMinutes(this.Life).Hour, this.StartDate.AddMinutes(this.Life).Minute, this.StartDate.Minute)); } } else { dayScheduler.WithInterval(24, IntervalUnit.Hour); } trigger.WithSchedule(dayScheduler); break; case PeriodType.Settimanale: var weekScheduler = DailyTimeIntervalScheduleBuilder .Create() .OnDaysOfTheWeek(this.WeekDays.ToArray()) .InTimeZone(TimeZoneInfo.Local) .StartingDailyAt(new TimeOfDay(this.StartDate.Hour, this.StartDate.Minute, this.StartDate.Second)); if (this.Interval > 0) { if (this.IntervalUnit != IntervalUnit.Minute && this.IntervalUnit != IntervalUnit.Hour) { throw new InvalidIntervalUnitException("IntervalUnit (" + this.IntervalUnit.ToString() + ") non accettata per il periodo selezionato (" + this.Period + ")"); } weekScheduler.WithInterval(this.Interval, this.IntervalUnit); if (this.LifeUnit == IntervalUnit.Hour) { weekScheduler.EndingDailyAt(new TimeOfDay(this.StartDate.AddHours(this.Life).Hour, this.StartDate.Minute, this.StartDate.Minute)); } else if (this.LifeUnit == IntervalUnit.Minute) { weekScheduler.EndingDailyAt(new TimeOfDay(this.StartDate.AddMinutes(this.Life).Hour, this.StartDate.AddMinutes(this.Life).Minute, this.StartDate.Minute)); } else { throw new InvalidLifeUnitException("LifeUnit (" + this.LifeUnit.ToString() + ") non accettata per il periodo selezinato (" + this.Period + ")"); } } else { weekScheduler.WithInterval(24, IntervalUnit.Hour); } trigger.WithSchedule(weekScheduler); break; case PeriodType.Mensile: var monthsScheduler = CalendarIntervalScheduleBuilder .Create() .InTimeZone(TimeZoneInfo.Local); if (this.Interval > 0) { if (this.IntervalUnit != IntervalUnit.Day && this.IntervalUnit != IntervalUnit.Week) { throw new InvalidIntervalUnitException("IntervalUnit (" + this.IntervalUnit.ToString() + ") non accettata per il periodo selezionato (" + this.Period + ")"); } trigger.WithCalendarIntervalSchedule(x => { x.WithInterval(this.Interval, this.IntervalUnit); }); if (this.LifeUnit == IntervalUnit.Day) { trigger.EndAt(new DateTimeOffset(this.StartDate.AddDays(this.Life))); } else if (this.LifeUnit == IntervalUnit.Week) { trigger.EndAt(new DateTimeOffset(this.StartDate.AddDays((7 * this.Life)))); } else { throw new InvalidLifeUnitException("LifeUnit (" + this.LifeUnit.ToString() + ") non accettata per il periodo selezinato (" + this.Period + ")"); } } else { monthsScheduler.WithInterval(1, IntervalUnit.Month); } trigger.StartAt(new DateTimeOffset(this.StartDate)); break; case PeriodType.Annuale: var yearScheduler = CalendarIntervalScheduleBuilder .Create() .InTimeZone(TimeZoneInfo.Local); if (this.Interval > 0) { if (this.IntervalUnit != IntervalUnit.Year && this.IntervalUnit != IntervalUnit.Month) { throw new InvalidIntervalUnitException("IntervalUnit (" + this.IntervalUnit.ToString() + ") non accettata per il periodo selezionato (" + this.Period + ")"); } trigger.WithCalendarIntervalSchedule(x => { x.WithInterval(this.Interval, this.IntervalUnit); }); if (this.LifeUnit == IntervalUnit.Year) { trigger.EndAt(new DateTimeOffset(this.StartDate.AddDays(this.Life))); } else if (this.LifeUnit == IntervalUnit.Month) { trigger.EndAt(new DateTimeOffset(this.StartDate.AddDays((30 * this.Life)))); } else { throw new InvalidLifeUnitException("LifeUnit (" + this.LifeUnit.ToString() + ") non accettata per il periodo selezinato (" + this.Period + ")"); } } else { yearScheduler.WithInterval(1, IntervalUnit.Year); } trigger.StartAt(new DateTimeOffset(this.StartDate)); break; default: return(null); } return(trigger.Build()); }
public static async void Start(Task task) { IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); await scheduler.Start(); var nameJob = $"{task.Name}-{task.Oid}-{Guid.NewGuid()}"; IJobDetail job = JobBuilder.Create <ZipArchiveController>() .WithIdentity(nameJob, "CreateZip") .UsingJobData("pathIn", task.CopyDirectory) .UsingJobData("pathOut", task.SaveDirectory) .UsingJobData("taskOid", task.Oid) .Build(); var daysOfWeek = new List <DayOfWeek>(); if (task.IsMonday) { daysOfWeek.Add(DayOfWeek.Monday); } if (task.IsTuesday) { daysOfWeek.Add(DayOfWeek.Tuesday); } if (task.IsWednesday) { daysOfWeek.Add(DayOfWeek.Wednesday); } if (task.IsThursday) { daysOfWeek.Add(DayOfWeek.Thursday); } if (task.IsFriday) { daysOfWeek.Add(DayOfWeek.Friday); } if (task.IsSaturday) { daysOfWeek.Add(DayOfWeek.Saturday); } if (task.IsSunday) { daysOfWeek.Add(DayOfWeek.Sunday); } var date = Convert.ToDateTime(task.Date); var trigger = default(ITrigger); if (daysOfWeek.Count == 0) { trigger = TriggerBuilder.Create() .WithIdentity(nameJob, "CreateZip") .StartAt(DateBuilder.DateOf(date.Hour, date.Minute, date.Second, date.Day, date.Month, date.Year)) .Build(); } else { var dailyTimeInterval = DailyTimeIntervalScheduleBuilder.Create().OnDaysOfTheWeek(daysOfWeek); trigger = TriggerBuilder.Create() .WithIdentity(nameJob, "CreateZip") .StartAt(DateBuilder.DateOf(date.Hour, date.Minute, date.Second, date.Day, date.Month, date.Year)) .WithSchedule(dailyTimeInterval) .WithCalendarIntervalSchedule(x => x .WithIntervalInWeeks(1)) .Build(); } await scheduler.ScheduleJob(job, trigger); }
public static DailyTimeIntervalScheduleBuilder Around(this DailyTimeIntervalScheduleBuilder x, TimeOfDay time) { return(x.OnEveryDay() .StartingDailyAt(time).WithRepeatCount(0) .EndingDailyAt(new TimeOfDay(time.Hour, time.Minute + 5))); }
public static DailyTimeIntervalScheduleBuilder WeekendNights(this DailyTimeIntervalScheduleBuilder x) { return(x.OnDaysOfTheWeek(DayOfWeek.Friday, DayOfWeek.Saturday)); }
public static DailyTimeIntervalScheduleBuilder SchoolNights(this DailyTimeIntervalScheduleBuilder x) { return(x.OnDaysOfTheWeek(DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday)); }