1.介绍

中文意义就是每日时间间隔计划生成

2.API讲解

(1)WithInterval、WithIntervalInHours、WithIntervalInMinutes、WithIntervalInSeconds

WithInterval:指定要生成触发器的时间单位和间隔。

WithIntervalInHours:指定要生成触发器的间隔按小时来

WithIntervalInMinutes:指定要生成触发器的间隔按分钟来

WithIntervalInSeconds:指定要生成触发器的间隔按秒来

和前面的SimpleSceduleBuilder、CalendarIntervalScheduleBuilder一样的

(2)OnDaysOfTheWeek、OnMondayThroughFriday、OnSaturdayAndSunday、OnEveryDay

OnDaysOfTheWeek:设置触发器一周中的哪几天

OnMondayThroughFriday:从星期一到星期五

OnSaturdayAndSunday:周六和周日

OnEveryDay:每天

每天10:00到23:10.00的每一分钟执行一次

  var trigger = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(
w => w.OnEveryDay() //设置每天
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(, )) //设置每天开始于几点
.EndingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(, , )) //设置每日结束于几点
.WithIntervalInMinutes()//间隔分钟
).Build();

一周当中的星期二和星期三每秒执行一次

            List<DayOfWeek> dayOfWeeks = new List<DayOfWeek>();

            dayOfWeeks.Add(DayOfWeek.Wednesday);

            dayOfWeeks.Add(DayOfWeek.Tuesday);

            trigger = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(
w=>w.OnDaysOfTheWeek(dayOfWeeks)//.OnDaysOfTheWeek(new DayOfWeek[2] { DayOfWeek.Wednesday,DayOfWeek.Tuesday})
.WithIntervalInSeconds()
).Build();

 源码实现

  /// <summary>
/// Set the trigger to fire on the given days of the week.
/// </summary>
/// <param name="onDaysOfWeek">a Set containing the integers representing the days of the week, defined by <see cref="DayOfWeek.Sunday"/> - <see cref="DayOfWeek.Saturday"/>.
/// </param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnDaysOfTheWeek(IReadOnlyCollection<DayOfWeek> onDaysOfWeek)
{
if (onDaysOfWeek == null || onDaysOfWeek.Count == )
{
throw new ArgumentException("Days of week must be an non-empty set.");
} foreach (DayOfWeek day in onDaysOfWeek)
{
if (!AllDaysOfTheWeek.Contains(day))
{
throw new ArgumentException("Invalid value for day of week: " + day);
}
} daysOfWeek = new HashSet<DayOfWeek>(onDaysOfWeek);
return this;
} /// <summary>
/// Set the trigger to fire on the given days of the week.
/// </summary>
/// <param name="onDaysOfWeek">a variable length list of week days representing the days of the week</param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnDaysOfTheWeek(params DayOfWeek[] onDaysOfWeek)
{
return OnDaysOfTheWeek((IReadOnlyCollection<DayOfWeek>) onDaysOfWeek);
} /// <summary>
/// Set the trigger to fire on the days from Monday through Friday.
/// </summary>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnMondayThroughFriday()
{
daysOfWeek = new HashSet<DayOfWeek>(MondayThroughFriday);
return this;
} /// <summary>
/// Set the trigger to fire on the days Saturday and Sunday.
/// </summary>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnSaturdayAndSunday()
{
daysOfWeek = new HashSet<DayOfWeek>(SaturdayAndSunday);
return this;
} /// <summary>
/// Set the trigger to fire on all days of the week.
/// </summary>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnEveryDay()
{
daysOfWeek = new HashSet<DayOfWeek>(AllDaysOfTheWeek);
return this;
}

(3)StartingDailyAt、EndingDailyAt

StartingDailyAt:开始时间于

EndingDailyAt:结束时间于

源码实现

        /// <summary>
/// The TimeOfDay for this trigger to start firing each day.
/// </summary>
/// <param name="timeOfDayUtc"></param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder StartingDailyAt(TimeOfDay timeOfDayUtc)
{
startTimeOfDayUtc = timeOfDayUtc ?? throw new ArgumentException("Start time of day cannot be null!");
return this;
} /// <summary>
/// The TimeOfDay for this trigger to end firing each day.
/// </summary>
/// <param name="timeOfDayUtc"></param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder EndingDailyAt(TimeOfDay timeOfDayUtc)
{
endTimeOfDayUtc = timeOfDayUtc;
return this;
}

(4)EndingDailyAfterCount

EndingDailyAfterCount:使用count、interval和StarTimeOfDay计算并设置EndTimeOfDay。

源码实现

       /// <summary>
/// Calculate and set the EndTimeOfDay using count, interval and StarTimeOfDay. This means
/// that these must be set before this method is call.
/// </summary>
/// <param name="count"></param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder EndingDailyAfterCount(int count)
{
if (count <= )
{
throw new ArgumentException("Ending daily after count must be a positive number!");
} if (startTimeOfDayUtc == null)
{
throw new ArgumentException("You must set the StartDailyAt() before calling this EndingDailyAfterCount()!");
} DateTimeOffset today = SystemTime.UtcNow();
DateTimeOffset startTimeOfDayDate = startTimeOfDayUtc.GetTimeOfDayForDate(today).Value;
DateTimeOffset maxEndTimeOfDayDate = TimeOfDay.HourMinuteAndSecondOfDay(, , ).GetTimeOfDayForDate(today).Value; //apply proper offsets according to timezone
TimeZoneInfo targetTimeZone = timeZone ?? TimeZoneInfo.Local;
startTimeOfDayDate = new DateTimeOffset(startTimeOfDayDate.DateTime, TimeZoneUtil.GetUtcOffset(startTimeOfDayDate.DateTime, targetTimeZone));
maxEndTimeOfDayDate = new DateTimeOffset(maxEndTimeOfDayDate.DateTime, TimeZoneUtil.GetUtcOffset(maxEndTimeOfDayDate.DateTime, targetTimeZone)); TimeSpan remainingMillisInDay = maxEndTimeOfDayDate - startTimeOfDayDate;
TimeSpan intervalInMillis;
if (intervalUnit == IntervalUnit.Second)
{
intervalInMillis = TimeSpan.FromSeconds(interval);
}
else if (intervalUnit == IntervalUnit.Minute)
{
intervalInMillis = TimeSpan.FromMinutes(interval);
}
else if (intervalUnit == IntervalUnit.Hour)
{
intervalInMillis = TimeSpan.FromHours(interval);
}
else
{
throw new ArgumentException("The IntervalUnit: " + intervalUnit + " is invalid for this trigger.");
} if (remainingMillisInDay < intervalInMillis)
{
throw new ArgumentException("The startTimeOfDay is too late with given Interval and IntervalUnit values.");
} long maxNumOfCount = remainingMillisInDay.Ticks / intervalInMillis.Ticks;
if (count > maxNumOfCount)
{
throw new ArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
} TimeSpan incrementInMillis = TimeSpan.FromTicks((count - ) * intervalInMillis.Ticks);
DateTimeOffset endTimeOfDayDate = startTimeOfDayDate.Add(incrementInMillis); if (endTimeOfDayDate > maxEndTimeOfDayDate)
{
throw new ArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
} DateTime cal = SystemTime.UtcNow().Date;
cal = cal.Add(endTimeOfDayDate.TimeOfDay);
endTimeOfDayUtc = TimeOfDay.HourMinuteAndSecondOfDay(cal.Hour, cal.Minute, cal.Second);
return this;
}

Quartz.Net系列(九):Trigger之DailyTimeIntervalScheduleBuilder详解的更多相关文章

  1. SpringBoot系列(十二)过滤器配置详解

    SpringBoot(十二)过滤器详解 往期精彩推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件 ...

  2. 深入浅出Mybatis系列(四)---配置详解之typeAliases别名(mybatis源码篇)

    上篇文章<深入浅出Mybatis系列(三)---配置详解之properties与environments(mybatis源码篇)> 介绍了properties与environments, ...

  3. Android Studio系列教程五--Gradle命令详解与导入第三方包

    Android Studio系列教程五--Gradle命令详解与导入第三方包 2015 年 01 月 05 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://s ...

  4. Android 颜色渲染(九) PorterDuff及Xfermode详解

    版权声明:本文为博主原创文章,未经博主允许不得转载. Android 颜色渲染(九)  PorterDuff及Xfermode详解 之前已经讲过了除ComposeShader之外Shader的全部子类 ...

  5. 构建安全的Xml Web Service系列之wse之错误代码详解

    原文:构建安全的Xml Web Service系列之wse之错误代码详解 WSE3.0现在还没有中文版的可以下载,使用英文版的过程中,难免会遇到各种各样的错误,而面对一堆毫无头绪的错误异常,常常会感到 ...

  6. [js高手之路] es6系列教程 - 对象功能扩展详解

    第一:字面量对象的方法,支持缩写形式 //es6之前,这么写 var User = { name : 'ghostwu', showName : function(){ return this.nam ...

  7. “全栈2019”Java多线程第十九章:死锁详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  8. “全栈2019”Java异常第十九章:RuntimeException详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java异 ...

  9. “全栈2019”Java第二十九章:数组详解(中篇)

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

随机推荐

  1. AD17无法复制原理图到Word的解决方法

    标题: 解决AD17无法复制原理图到WORD 作者: 梦幻之心星 347369787@QQ.com 标签: [AD, Word, 原理图] 目录: 软件 日期: 2019-3-17 目录 前提说明: ...

  2. Java实现 蓝桥杯VIP 基础练习 龟兔赛跑预测

    题目描述 话说这个世界上有各种各样的兔子和乌龟,但是 研究发现,所有的兔子和乌龟都有一个共同的特点--喜欢赛跑.于是世界上各个角落都不断在发生着乌龟和兔子的比赛,小华对此很感兴趣,于是决定研究不同兔 ...

  3. Java实现 LeetCode 127 单词接龙

    127. 单词接龙 给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度.转换需遵循如下规则: 每次转换只能改变一个字 ...

  4. 第三届蓝桥杯JavaB组国(决)赛真题

    解题代码部分来自网友,如果有不对的地方,欢迎各位大佬评论 题目1.数量周期 [结果填空](满分9分) 复杂现象背后的推动力,可能是极其简单的原理.科学的目标之一就是发现纷繁复杂的自然现象背后的简单法则 ...

  5. Java实现 蓝桥杯 算法提高 字符串压缩

    试题 算法提高 字符串压缩 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 编写一个程序,输入一个字符串,然后采用如下的规则对该字符串当中的每一个字符进行压缩: (1) 如果该字符是 ...

  6. Java实现约瑟夫环问题

    约瑟夫环问题起源于一个犹太故事.约瑟夫环问题的大意如下: 罗马人攻占了桥塔帕特,41个人藏在一个山洞中躲过了这场浩劫.这41个人中,包括历史学家Josephus(约瑟夫)和他的一个朋友.剩余的39个人 ...

  7. java代码(15) ---java8 Function 、Consumer 、Supplier

    Java8 Function.Consumer.Supplier 有关JDK8新特性之前还有三篇博客: 1,java代码(1)---Java8 Lambda 2,java代码(2)---Java8 S ...

  8. cocos2dx 实现遮罩

    参考博文:http://blog.csdn.net/myarrow/article/details/19913653 参考博文:http://blog.csdn.net/song_hui_xiang/ ...

  9. AWS 创建redis 集群模式遇到的问题

    问题描述 前几天在aws 平台创建了Redis 集群模式,但是链接集群的时候发现无法连接,返回信息超时. 通过参数组创建redis的时候提示报错:Replication group with spec ...

  10. 解决:Error:java: 无效的源发行版: 12

    一. spring cloud项目启动.遇到问题: 二. 解决,共两个地方. 第一个位置: Shift/Ctrl/Alt/S 快捷键一起按 Modules选择你的项目(以及父级项目,如果有的话)-&g ...