public async Task TestScheduling_MinimalConfiguration() { Stream s = ReadJobXmlFromEmbeddedResource("MinimalConfiguration_20.xml"); await processor.ProcessStream(s, null); Assert.IsFalse(processor.OverWriteExistingData); await processor.ScheduleJobs(mockScheduler); }
public void TestScheduling_RichConfiguration() { Stream s = ReadJobXmlFromEmbeddedResource("RichConfiguration_20.xml"); processor.ProcessStream(s, null); Assert.IsFalse(processor.OverWriteExistingData); Assert.IsTrue(processor.IgnoreDuplicates); processor.ScheduleJobs(mockScheduler); mockScheduler.AssertWasCalled(x => x.ScheduleJob(Arg <ITrigger> .Is.NotNull), options => options.Repeat.Times(5)); }
public void TestDirectivesOverwriteWithNoIgnoreDups() { IScheduler scheduler = null; try { StdSchedulerFactory factory = new StdSchedulerFactory(); scheduler = factory.GetScheduler(); // Setup existing job with same names as in xml data. string job1 = Guid.NewGuid().ToString(); IJobDetail job = JobBuilder.Create <NoOpJob>().WithIdentity(job1).Build(); ITrigger trigger = TriggerBuilder.Create().WithIdentity(job1).WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever()).Build(); scheduler.ScheduleJob(job, trigger); string job2 = Guid.NewGuid().ToString(); job = JobBuilder.Create <NoOpJob>().WithIdentity(job2).Build(); trigger = TriggerBuilder.Create().WithIdentity(job2).WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever()).Build(); scheduler.ScheduleJob(job, trigger); // Now load the xml data with directives: overwrite-existing-data=false, ignore-duplicates=true XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper()); processor.ProcessStream(ReadJobXmlFromEmbeddedResource("directives_overwrite_no-ignoredups.xml"), "temp"); Assert.That(scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupEquals("DEFAULT")).Count, Is.EqualTo(2)); Assert.That(scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals("DEFAULT")).Count, Is.EqualTo(2)); } finally { if (scheduler != null) { scheduler.Shutdown(); } } }
/// <summary> /// 启动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnStart_Click(object sender, EventArgs e) { try { await MQTTContext.getInstance(). Initialize(txtServer.Text.Trim(), int.Parse(txtPort.Text.Trim()), notification); if (_scheduler == null) { _scheduler = await StdSchedulerFactory.GetDefaultScheduler(); //任务、触发器执行配置 XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper()); Stream s = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\Quartz.config").BaseStream; await processor.ProcessStream(s, null); await processor.ScheduleJobs(_scheduler); await _scheduler.Start(); } btnStart.Enabled = false; btnStop.Enabled = true; } catch (Exception ex) { showMessage(ex.Message); } }
public void TestRemoveJobTypeNotFound() { NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "TestScheduler"; properties["quartz.scheduler.instanceId"] = "AUTO"; properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"; properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz"; properties["quartz.jobStore.dataSource"] = "default"; properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; properties["quartz.dataSource.default.connectionString"] = "Server=(local);Database=quartz;Trusted_Connection=True;"; properties["quartz.dataSource.default.provider"] = "SqlServer-20"; // First we must get a reference to a scheduler ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler scheduler = sf.GetScheduler(); try { string jobName = Guid.NewGuid().ToString(); IJobDetail jobDetail = JobBuilder.Create <NoOpJob>().WithIdentity(jobName, "DEFAULT").StoreDurably().Build(); ITrigger trigger = TriggerBuilder.Create().WithIdentity(jobName).WithSchedule(CronScheduleBuilder.CronSchedule("* * * * * ?")).Build(); scheduler.ScheduleJob(jobDetail, trigger); ModifyStoredJobType(); XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper()); // when processor.ProcessStream(ReadJobXmlFromEmbeddedResource("MissingJobType.xml"), "temp"); } finally { scheduler.Shutdown(false); } }
// 手動加載配置文件 public void Test03() { XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper()); ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler scheduler = sf.GetScheduler(); Stream s = new StreamReader("~/quartz.xml").BaseStream; processor.ProcessStream(s, null); processor.ScheduleJobs(scheduler); scheduler.Start(); scheduler.Shutdown(); }
public void TestDirectivesOverwriteWithNoIgnoreDups() { IScheduler scheduler = null; try { StdSchedulerFactory factory = new StdSchedulerFactory(); scheduler = factory.GetScheduler(); // Setup existing job with same names as in xml data. string job1 = Guid.NewGuid().ToString(); IJobDetail job = JobBuilder.Create<NoOpJob>().WithIdentity(job1).Build(); ITrigger trigger = TriggerBuilder.Create().WithIdentity(job1).WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever()).Build(); scheduler.ScheduleJob(job, trigger); string job2 = Guid.NewGuid().ToString(); job = JobBuilder.Create<NoOpJob>().WithIdentity(job2).Build(); trigger = TriggerBuilder.Create().WithIdentity(job2).WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever()).Build(); scheduler.ScheduleJob(job, trigger); // Now load the xml data with directives: overwrite-existing-data=false, ignore-duplicates=true XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper()); processor.ProcessStream(ReadJobXmlFromEmbeddedResource("directives_overwrite_no-ignoredups.xml"), "temp"); Assert.That(scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals("DEFAULT")).Count, Is.EqualTo(2)); Assert.That(scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals("DEFAULT")).Count, Is.EqualTo(2)); } finally { if (scheduler != null) { scheduler.Shutdown(); } } }
// 手動加載配置文件 public void Test03() { XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper()); ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler scheduler = sf.GetScheduler(); Stream s = new StreamReader("~/quartz.xml").BaseStream; processor.ProcessStream(s, null); processor.ScheduleJobs(scheduler); scheduler.Start(); scheduler.Shutdown(); }
public void TestRemoveJobTypeNotFound() { NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "TestScheduler"; properties["quartz.scheduler.instanceId"] = "AUTO"; properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"; properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz"; properties["quartz.jobStore.dataSource"] = "default"; properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; properties["quartz.dataSource.default.connectionString"] = "Server=(local);Database=quartz;Trusted_Connection=True;"; properties["quartz.dataSource.default.provider"] = "SqlServer-20"; // First we must get a reference to a scheduler ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler scheduler = sf.GetScheduler(); try { string jobName = Guid.NewGuid().ToString(); IJobDetail jobDetail = JobBuilder.Create<NoOpJob>().WithIdentity(jobName, "DEFAULT").StoreDurably().Build(); ITrigger trigger = TriggerBuilder.Create().WithIdentity(jobName).WithSchedule(CronScheduleBuilder.CronSchedule("* * * * * ?")).Build(); scheduler.ScheduleJob(jobDetail, trigger); ModifyStoredJobType(); XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper()); // when processor.ProcessStream(ReadJobXmlFromEmbeddedResource("MissingJobType.xml"), "temp"); } finally { scheduler.Shutdown(false); } }