所有方法圖
CalendarIntervalScheduleBuilder方法
在SimpleScheduleBuilder基礎上實現了日、周、月、年
WithInterval:指定要生成觸發器的時間單位和間隔。
WithIntervalInHours:指定要生成觸發器的間隔按小時來
WithIntervalInMinutes:指定要生成觸發器的間隔按分鍾來
WithIntervalInSeconds:指定要生成觸發器的間隔按秒來
WithIntervalInDays:指定要生成觸發器的間隔按日來
WithIntervalInWeeks:指定要生成觸發器的間隔按周來
WithIntervalInMonths:指定要生成觸發器的間隔按月來
WithIntervalInYears:指定要生成觸發器的間隔按年來
var trigger = TriggerBuilder.Create().WithCalendarIntervalSchedule(c=>c .WithInterval(1, IntervalUnit.Millisecond) .WithIntervalInSeconds(1) .WithIntervalInMinutes(1) .WithIntervalInHours(1) .WithIntervalInDays(1) .WithIntervalInWeeks(1) .WithIntervalInMonths(1) .WithIntervalInYears(1)).Build();
注:按最后一個設定時間為准
最后指定給字段interval和intervalUnit,那么前面就會覆蓋
在不指定間隔的時候默認是1,間隔單位是一天
public class CalendarIntervalScheduleBuilder : ScheduleBuilder<ICalendarIntervalTrigger> { private int interval = 1; private IntervalUnit intervalUnit = IntervalUnit.Day; private int misfireInstruction = MisfireInstruction.SmartPolicy; private TimeZoneInfo timeZone; private bool preserveHourOfDayAcrossDaylightSavings; private bool skipDayIfHourDoesNotExist; }
/// <summary> /// Supported interval units used by <see cref="ICalendarIntervalTrigger" />. /// </summary> public enum IntervalUnit { Millisecond, Second, Minute, Hour, Day, Week, Month, Year }
/// <summary> /// Specify the time unit and interval for the Trigger to be produced. /// </summary> /// <remarks> /// </remarks> /// <param name="interval">the interval at which the trigger should repeat.</param> /// <param name="unit"> the time unit (IntervalUnit) of the interval.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithInterval(int interval, IntervalUnit unit) { ValidateInterval(interval); this.interval = interval; intervalUnit = unit; return this; } /// <summary> /// Specify an interval in the IntervalUnit.SECOND that the produced /// Trigger will repeat at. /// </summary> /// <remarks> /// </remarks> /// <param name="intervalInSeconds">the number of seconds at which the trigger should repeat.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithIntervalInSeconds(int intervalInSeconds) { ValidateInterval(intervalInSeconds); interval = intervalInSeconds; intervalUnit = IntervalUnit.Second; return this; } /// <summary> /// Specify an interval in the IntervalUnit.MINUTE that the produced /// Trigger will repeat at. /// </summary> /// <remarks> /// </remarks> /// <param name="intervalInMinutes">the number of minutes at which the trigger should repeat.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithIntervalInMinutes(int intervalInMinutes) { ValidateInterval(intervalInMinutes); interval = intervalInMinutes; intervalUnit = IntervalUnit.Minute; return this; } /// <summary> /// Specify an interval in the IntervalUnit.HOUR that the produced /// Trigger will repeat at. /// </summary> /// <remarks> /// </remarks> /// <param name="intervalInHours">the number of hours at which the trigger should repeat.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithIntervalInHours(int intervalInHours) { ValidateInterval(intervalInHours); interval = intervalInHours; intervalUnit = IntervalUnit.Hour; return this; } /// <summary> /// Specify an interval in the IntervalUnit.DAY that the produced /// Trigger will repeat at. /// </summary> /// <remarks> /// </remarks> /// <param name="intervalInDays">the number of days at which the trigger should repeat.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithIntervalInDays(int intervalInDays) { ValidateInterval(intervalInDays); interval = intervalInDays; intervalUnit = IntervalUnit.Day; return this; } /// <summary> /// Specify an interval in the IntervalUnit.WEEK that the produced /// Trigger will repeat at. /// </summary> /// <remarks> /// </remarks> /// <param name="intervalInWeeks">the number of weeks at which the trigger should repeat.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithIntervalInWeeks(int intervalInWeeks) { ValidateInterval(intervalInWeeks); interval = intervalInWeeks; intervalUnit = IntervalUnit.Week; return this; } /// <summary> /// Specify an interval in the IntervalUnit.MONTH that the produced /// Trigger will repeat at. /// </summary> /// <remarks> /// </remarks> /// <param name="intervalInMonths">the number of months at which the trigger should repeat.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithIntervalInMonths(int intervalInMonths) { ValidateInterval(intervalInMonths); interval = intervalInMonths; intervalUnit = IntervalUnit.Month; return this; } /// <summary> /// Specify an interval in the IntervalUnit.YEAR that the produced /// Trigger will repeat at. /// </summary> /// <remarks> /// </remarks> /// <param name="intervalInYears">the number of years at which the trigger should repeat.</param> /// <returns>the updated CalendarIntervalScheduleBuilder</returns> /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" /> /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" /> public CalendarIntervalScheduleBuilder WithIntervalInYears(int intervalInYears) { ValidateInterval(intervalInYears); interval = intervalInYears; intervalUnit = IntervalUnit.Year; return this; }
InTimeZone:設置時區
var trigger = TriggerBuilder.Create().WithCalendarIntervalSchedule(c => c.InTimeZone(TimeZoneInfo.Local)).Build();