posts - 84,  comments - 880,  trackbacks - 7
公告

也许在你的日常生活中总是离不开能够辅助你安排日程计划和约会提醒的软件或工具,还有在企业应用的开发中也经常会用到自动调度某个程序或任务执行的软件。这些工具或系统很多,比如Windows的计划与任务,Outlook, Project, SqlServer上Job,还有DTS等,但是可能发现还不是那么灵活,比如不能指定比较复杂的时间规则,最小的时间精度不够,不能很方便的集成在其他的程序里,等等。而且现有的那些软件或工具一般都是有窗体界面的,有时候你希望你的Web应用程序里也有自动调度的功能的话就得自己写了。

为了解决上面的问题,自己用C#写了个Scheduling组件。主要具有如下的特性:
1。 dll的形势发布,可以很好的与其他.net应用程序集成,其他程序可以直接在代码里调用组件的类库;
2。灵活的XML配置,通过已经提供的几种ScheduleRule,ScheduleFilter,CalendarDirective/Constraint等就可以组合搭配出很复杂的时间调度的规则;
3。可扩展性比较好,以后还可以继续实现自己的IScheduleRule,IPredictableScheduleRule,IScheduleFilter,ICalendarConstraint等,以满足自己特殊的需求。

今天在这里先列出几个简单的调度规则的例子(未完待续):
 

A1. 在一个或多个具体的日期时间点执行:

<appointment date="2005-10-15 10:00:00|2005-10-16 10:00:00|2005-10-18 17:00:00" />

A2. 从程序的运行开始计时,分别在经过1357秒的时候执行:

<appointment start="now" time="0:0:1|0:0:3|0:0:5|0:0:7" />

R1. 从程序的运行开始每隔1个小时执行一次,最多执行100次:

<repeat start="now" unit="hour" count="100" />

R2. 200611日开始,每隔三天执行一次:

<repeat start="2006-1-1 0:0:0" interval="3" unit="day" />

S1. 2004315号到200635号之间的每年的每月的星期一到星期五,从上午9点每隔两小时到下午17点,分钟数为02040分的时候执行:

<sequence begin="2004-3-15" end="2006-3-15"
        year="*"
        month="*"
        weekday="1;;5"
        hour="9;2;17"
        minute="0,20,40"
        second="0"
        />

S2. 年是5的倍数,月是3的倍数,天是6的倍数,小时是奇数,分钟是偶数,秒数为30的时候执行:

<sequence
        year=";5;"
        month=";3;"
        day=";6;"
        hour="1;2;"
        minute="0;2;"
        second="30"
/>

S3. 每个整点的时候执行:

<sequence
        hour="*"
        minute="0"
        second="0"
/>

C1. 每天临晨0点和中午12点的时候执行:

<calendar>
        <day>
                <time appoint="0:0:0|12:0:0" />
        </day>
</
calendar>

C2. 每个星期周一至周五的上午9点和下午17点执行:

<calendar>
        <week>
                <day from="1" to="5">
                        <time appoint="9:0:0|17:0:0" />
                </day>
        </week>
</
calendar>

C2. 每个星期周一至周五的上午9点或者下午17点执行(如果程序在9点前执行,那么就会在9点触发,那天的17点将不再执行;否则如何9点时错过了没有能够触发,17点的时候将会执行):

<calendar>
        <week>
                <day from="1" to="5" directive="any">
                        <time appoint="9:0:0" />
                        <time appoint="17:0:0" />
                </day>
        </week>
</
calendar>

C3. 再接着上面的例子,如果你希望程序这个星期是在上午9点前打开的,那么整个星期都在每天上午9点执行,否则就整个星期都在下午17点执行:

<calendar>
        <week directive="any">
                <day from="1" to="5">
                        <time appoint="9:0:0" />
                </day>
                <day from="1" to="5">
                        <time appoint="17:0:0" />
                </day>
        </week>
</
calendar>

C4. 或者你也可以让一个星期从周一到周三上午9点执行,剩下的周四到周五下午17点执行:

<calendar>
        <week>
                <day from="1" to="3">
                        <time appoint="9:0:0" />
                </day>
                <day from="4" to="5">
                        <time appoint="17:0:0" />
                </day>
        </week>
</
calendar>

C5. 在每个星期天的每个小时整点的时候都执行:

<calendar>
        <week>
                <day appoint="0">
                        <hour />
                </day>
        </week>
</
calendar>

C6. 双休的每天晚上都2000以后每隔10秒钟运行一次:

<calendar>
        <week>
                <day appoint="6,0">
                        <hour from="20">
                                <second interval="10" />
                        </hour>
                </day>
        </week>
</
calendar>

C7. 始终每隔2秒钟运行一次:

<calendar>
        <second interval="2" />
</
calendar>

C8. 200512月份的每天晚上22点运行:

<calendar>
        <year appoint="2005">
                <month appoint="12">
                        <day>
                                <hour appoint="22" />
                        </day>
                </month>
        </year>
</
calendar>

C9. 每年的第四个季度的第三个月的810:20:00运行:

<calendar>
        <year>
                <quarter appoint="4">
                        <month appoint="3">
                                <day appoint="8">
                                        <time appoint="10:20:00" />
                                </day>
                        </month>
                </quarter>
        </year>
</
calendar>

C10. 我们接下来对整年都进行一次规划,整个规则按照年、月、日的形势缩进组织,整个看起来就像一个日历一样:

<calendar>
        <year>
                <month appoint="1">
                        <day appoint="1">...</day>
                        <day appoint="6">...</day>
                        <day appoint="11">...</day>
                        <day appoint="18">...</day>
                        <day appoint="20">...</day>
                        <day appoint="26">...</day>
                </month>
                <month appoint="2">
                        <day appoint="3">...</day>
                        <day appoint="28">...</day>
                </month>
                <month appoint="3">
                        <day appoint="5">...</day>
                        <day appoint="12">...</day>
                        <day appoint="19">...</day>
                </month>
                <month appoint="4">
                        <day appoint="10">...</day>
                </month>
                <month appoint="5">
                        <day appoint="9">...</day>
                        <day appoint="15">...</day>
                        <day appoint="17">...</day>
                </month>
                <month appoint="6">
                        <day appoint="10">...</day>
                        <day appoint="20">...</day>
                        <day appoint="23">...</day>
                        <day appoint="30">...</day>
                </month>
                <month appoint="7">
                        <day appoint="1">...</day>
                        <day appoint="7">...</day>
                </month>
                <month appoint="8">
                        <day appoint="8">...</day>
                        <day appoint="18">...</day>
                        <day appoint="28">...</day>
                        <day appoint="31">...</day>
                </month>
                <month appoint="9">
                        <day appoint="9">...</day>
                </month>
                <month appoint="10">
                </month>
                <month appoint="11">
                        <day appoint="11">...</day>
                </month>
                <month appoint="12">
                        <day appoint="20">...</day>
                        <day appoint="31">...</day>
                </month>
        </year>
</
calendar>


--------------------------------------
(二)http://www.cnblogs.com/Laser_Lu/archive/2006/01/03/310306.html 


posted on 2005-12-30 22:45 Laser.NET 阅读(...) 评论(...) 编辑 收藏
无觅相关文章插件,快速提升流量