Beispiel #1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                //0 0 12 * * ?	 每天12点触发
                //0 15 10 ? * *	 每天10点15分触发
                //0 15 10 * * ?	 每天10点15分触发
                //0 15 10 * * ? *	 每天10点15分触发
                //0 15 10 * * ? 2005	 2005年每天10点15分触发
                //0 * 14 * * ?	 每天下午的 2点到2点59分每分触发
                //0 0/5 14 * * ?	 每天下午的 2点到2点59分(整点开始,每隔5分触发)
                //0 0/5 14,18 * * ?	 每天下午的 2点到2点59分(整点开始,每隔5分触发)
                //每天下午的 18点到18点59分(整点开始,每隔5分触发)
                //0 0-5 14 * * ?	 每天下午的 2点到2点05分每分触发
                //0 10,44 14 ? 3 WED	 3月分每周三下午的 2点10分和2点44分触发
                //0 15 10 ? * MON-FRI	 从周一到周五每天上午的10点15分触发
                //0 15 10 15 * ?	 每月15号上午10点15分触发
                //0 15 10 L * ?	 每月最后一天的10点15分触发
                //0 15 10 ? * 6L	 每月最后一周的星期五的10点15分触发
                //0 15 10 ? * 6L 2002-2005	 从2002年到2005年每月最后一周的星期五的10点15分触发
                //0 15 10 ? * 6#3	 每月的第三周的星期五开始触发
                //0 0 12 1/5 * ?	 每月的第一个中午开始每隔5天触发一次
                //0 11 11 11 11 ?	 每年的11月11号 11点11分触发(光棍节)

                //发邮件工作任务
                JobDetail m_TimingMailJobDetail1 = new JobDetail("打印测试文件", Guid.NewGuid().ToString("N"), typeof(RegularMailJob.RegularMail_T2));
                JobDetail m_TimingMailJobDetail2 = new JobDetail("打印测试文件", Guid.NewGuid().ToString("N"), typeof(RegularMailJob.RegularMail_T2));
                JobDetail m_TimingMailJobDetail3 = new JobDetail("打印测试文件", Guid.NewGuid().ToString("N"), typeof(RegularMailJob.RegularMail_T2));
                //Trigger m_TimingMailTrigger = new SimpleTrigger(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), m_TimingMailJobDetail.Name, m_TimingMailJobDetail.Group, DateTime.UtcNow, null, 0, TimeSpan.FromDays(7));

                //CronTrigger trigger = new CronTrigger("打印", "group1", "0/30 * * * * ?");


                //从周一到周五每天上午的10点15分触发
                CronTrigger trigger1 = new CronTrigger("打印1", "group1", "0 20 15 ? * MON-FRI");

                CronTrigger trigger2 = new CronTrigger("打印2", "group2", "0 25 15 ? * MON-FRI");

                CronTrigger trigger3 = new CronTrigger("打印3", "group3", "0 15 15 ? * MON-FRI");


                SchedulerManager.GetScheduler().ScheduleJob(m_TimingMailJobDetail1, trigger1);
                log.Info("任务:" + m_TimingMailJobDetail1.FullName + " 已经调度成功!");
                SchedulerManager.GetScheduler().ScheduleJob(m_TimingMailJobDetail2, trigger2);
                log.Info("任务:" + m_TimingMailJobDetail2.FullName + " 已经调度成功!");
                SchedulerManager.GetScheduler().ScheduleJob(m_TimingMailJobDetail3, trigger3);
                log.Info("任务:" + m_TimingMailJobDetail3.FullName + " 已经调度成功!");



                SchedulerManager.GetScheduler().Start();

                log.Info("service started ok");
            }
            catch (Exception ex)
            {
                log.Error("service started fail", ex);
                this.Stop();
            }
        }
        public Trigger GetTrigger()
        {
            //TODO:先判断触发器\组名是不是重复
            if (SchedulerManager.GetScheduler() != null)
            {
                foreach (string groupName in SchedulerManager.GetScheduler().TriggerGroupNames)
                {
                    if (groupName == txtTriggerGroup.Text)
                    {
                        foreach (string triggerName in SchedulerManager.GetScheduler().GetTriggerNames(groupName))
                        {
                            if (triggerName == txtTriggerName.Text)
                            {
                                MessageBox.Show("触发器组名、触发器名不能同时重复,请修改");
                                tabControl.SelectedTab = tabPageSelection;
                                return(null);
                            }
                        }
                    }
                }
            }

            switch (tabControl.SelectedIndex)
            {
            //现有触发器
            case 1:
                return(GetTriggerAvailable());

            //每天
            default:
            case 2:
                return(GetTriggerEveryDay());

            //每周
            case 3:
                return(GetTriggerEveryWeek());

            //每月
            case 4:
                return(GetTriggerEveryMonth());

            //每年
            case 5:
                return(GetTriggerEveryYear());

            //农历
            case 6:
                return(GetTriggerTraditionalHoliday());

            //国际节假日
            case 7:
                return(GetTriggerInterHoliday());

            //高级
            case 8:
                return(GetTriggerAdvance());
            }
        }
Beispiel #3
0
        public RegularMailService()
        {
            InitializeComponent();

            //初始化调度器工厂
            ISchedulerFactory sf = SchedulerManager.GetSchedulerFactory();
            //获取默认调度器
            IScheduler scheduler = SchedulerManager.GetScheduler();

            SchedulerManager.GetScheduler().AddGlobalJobListener(SchedulerManager.GetJobListener());
        }
 public void UpdateUI()
 {
     lbTriggersAvailable.Items.Clear();
     foreach (string group in SchedulerManager.GetScheduler().TriggerGroupNames)
     {
         foreach (string trigger in SchedulerManager.GetScheduler().GetTriggerNames(group))
         {
             TriggerAndGroup triggerAndGroup = new TriggerAndGroup(group, trigger);
             lbTriggersAvailable.Items.Add(triggerAndGroup);
         }
     }
 }
 /// <summary>
 /// 从已有的触发器选择
 /// </summary>
 /// <returns></returns>
 private Trigger GetTriggerAvailable()
 {
     if (lbTriggersAvailable.SelectedIndex > -1)
     {
         TriggerAndGroup triggerAndGroup = lbTriggersAvailable.SelectedItem as TriggerAndGroup;
         return(SchedulerManager.GetScheduler().GetTrigger(triggerAndGroup.TriggerName, triggerAndGroup.GroupName));
     }
     else
     {
         MessageBox.Show("请选择现有的触发器,如果没有请添加");
         return(null);
     }
 }
Beispiel #6
0
        protected override void OnStop()
        {
            try
            {
                IScheduler scheduler = SchedulerManager.GetScheduler();
                scheduler.Shutdown(false);

                log.Info("service stopped ok");
            }
            catch (Exception ex)
            {
                log.Error("service stopped fail", ex);
            }
        }
Beispiel #7
0
        public Form1()
        {
            InitializeComponent();

            Control.CheckForIllegalCrossThreadCalls = false;

            //初始化调度器工厂
            ISchedulerFactory sf = SchedulerManager.GetSchedulerFactory();
            //获取默认调度器
            IScheduler scheduler = SchedulerManager.GetScheduler();

            //安装全局任务监视器
            SchedulerManager.GetScheduler().AddGlobalJobListener(SchedulerManager.GetJobListener());
            //启动调度器
            scheduler.Start();
        }
 public JsonResult StartSchedulers(List <string> schedulerInstanceIdList)
 {
     foreach (var schedulerInstanceId in schedulerInstanceIdList)
     {
         ServiceController service = new ServiceController(schedulerInstanceId);
         if (service.Status == ServiceControllerStatus.Stopped)
         {
             service.Start();
             if (SchedulerData.schedulerInstanceIdEquivalentIp.ContainsKey(schedulerInstanceId))
             {
                 SchedulerManager.GetScheduler(schedulerInstanceId);
                 //SchedulerData.schedulerInstanceIdEquivalentIp.Add(schedulerInstanceId,new schedulerInstanceInfo { });//增加服务节点
             }
         }
     }
     return(Json(ResponseDataFactory.CreateAjaxResponseData("1", "服务上线成功", 1)));
 }
Beispiel #9
0
        private void MailExecute()
        {
            //删除日志的工作任务
            DateTime startTime = DateTime.UtcNow.AddSeconds(1);

            //JobDetail m_MailJobDetail = new JobDetail("立即发邮件", Guid.NewGuid().ToString("N"), typeof(TimingMailJob.TimingMailNowJob));
            //JobDetail m_MailJobDetail = new JobDetail("立即发邮件", Guid.NewGuid().ToString("N"), typeof(TimingMailJob.MyTest));
            // jobs can be scheduled before sched.start() has been called

            // get a "nice round" time a few seconds in the future...
            //DateTime ts = TriggerUtils.GetNextGivenSecondDate(null, 15);

            //// job1 will only fire once at date/time "ts"
            JobDetail job = new JobDetail("job1", "group1", typeof(RegularMailJob.RegularMail_T2));
            //SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1");
            //// set its start up time
            //trigger.StartTimeUtc = ts;
            //// set the interval, how often the job should run (10 seconds here)

            //// set the number of execution of this job, set to 10 times.
            //// It will run 10 time and exhaust.
            //trigger.RepeatCount = 100;


            //// schedule it to run!
            //log.Info(string.Format("{0} will run at: {1} and repeat: {2} times, every {3} seconds",
            //    job.FullName, "", trigger.RepeatCount, (10)));
            //log.Info("------- Waiting five minutes... ------------");
            Trigger m_MailTrigger = new SimpleTrigger(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), job.Name, job.Group, startTime, null, 0, TimeSpan.FromDays(7));



            log.Info("Starting service");

            log.Info("------- Scheduling Jobs ----------------");

            //CronTrigger trigger = new CronTrigger("打印", "group1", "0/30 * * * * ?");



            SchedulerManager.GetScheduler().ScheduleJob(job, m_MailTrigger);
        }
Beispiel #10
0
 public CnieltsPipeline2(PipelineOptions options) : base(options)
 {
     _downloadUrlScheduler = SchedulerManager.GetScheduler <Scheduler <string> >("downloadUrlScheduler");
     Options.Scheduler     = SchedulerManager.GetScheduler <Scheduler <string> >("downloadPageScheduler");
 }
Beispiel #11
0
 public CnieltsPipeline3(FileDownloadOptions options) : base(options)
 {
     Options.Scheduler = SchedulerManager.GetScheduler <Scheduler <string> >("downloadUrlScheduler");
 }
Beispiel #12
0
 public ClandarPipeline(ClandarPipelineOptions options) : base(options)
 {
     Options.Scheduler = SchedulerManager.GetScheduler <Scheduler <string> >("urlScheduler");
     _huangliScheduler = SchedulerManager.GetScheduler <Scheduler <HuangliMonth> >("huangliScheduler");
 }
Beispiel #13
0
 public BuilderDatabasePipeline(PipelineOptions options) : base(options)
 {
     _huangliScheduler = SchedulerManager.GetScheduler <Scheduler <HuangliMonth> >("huangliScheduler");
 }
Beispiel #14
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            SchedulerManager.GetScheduler().Shutdown(false);

            e.Cancel = false;
        }