Ejemplo n.º 1
0
        private static async Task InstanceForJobsInGroup(MyJobListener myJobListener, StdSchedulerFactory factory)
        {
            IScheduler sched = await factory.GetScheduler();

            await sched.Start();

            IJobDetail job = JobBuilder.Create <DumbJob>().WithIdentity("firstJob", "group1")
                             .UsingJobData("jobSays", "first")
                             .UsingJobData("myFloatValue", 3.141f)
                             .Build();

            IJobDetail job2 = JobBuilder.Create <HelloJob>().WithIdentity("secondJob", "group1")
                              .Build();

            ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create().WithIdentity("trigger", "group1")
                                     .StartNow()
                                     .WithSimpleSchedule(x => x.WithIntervalInSeconds(2)
                                                         .WithRepeatCount(10))
                                     .Build();

            ISimpleTrigger trigger2 = (ISimpleTrigger)TriggerBuilder.Create().WithIdentity("trigger2", "group1")
                                      .StartNow()
                                      .WithSimpleSchedule(x => x.WithIntervalInSeconds(4)
                                                          .WithRepeatCount(10))
                                      .Build();

            //Adding a JobListener that is interested in all jobs of a particular group:
            sched.ListenerManager.AddJobListener(myJobListener, GroupMatcher <JobKey> .GroupEquals("group1"));

            await sched.ScheduleJob(job, trigger2);

            await sched.ScheduleJob(job2, trigger);
        }
Ejemplo n.º 2
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var myJobListener       = new MyJobListener();
            var myTriggerListener   = new MyTriggerListener();
            var mySchedulerListener = new MySchedulerListener();

            NameValueCollection props = new NameValueCollection()
            {
                { "quartz.serializer.type", "binary" }
            };

            StdSchedulerFactory factory = new StdSchedulerFactory(props);

            // await InstanceForOneJob(myJobListener, factory);
            // await InstanceForJobsInGroup(myJobListener, factory);
            // await InstanceForJobsInDifferentGroups(myJobListener, factory);
            await InstanceForOneTrigger(myTriggerListener, factory);

            //Adding a SchedulerListener:
            //scheduler.ListenerManager.AddSchedulerListener(mySchedulerListener);

            //Removing a SchedulerListener:
            //scheduler.ListenerManager.RemoveSchedulerListener(mySchedListener);

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        private static async Task InstanceForOneJob(MyJobListener myJobListener, StdSchedulerFactory factory)
        {
            IScheduler sched = await factory.GetScheduler();

            await sched.Start();

            IJobDetail job = JobBuilder.Create <DumbJob>().WithIdentity("myJob")
                             .UsingJobData("jobSays", "Hello World!")
                             .UsingJobData("myFloatValue", 3.141f)
                             .Build();

            ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create().WithIdentity("trigger")
                                     .StartNow()
                                     .WithSimpleSchedule(x => x.WithIntervalInSeconds(2)
                                                         .WithRepeatCount(10))
                                     .Build();

            //Adding a JobListener that is interested in a particular job:
            sched.ListenerManager.AddJobListener(myJobListener, KeyMatcher <JobKey> .KeyEquals(new JobKey("myJob")));

            await sched.ScheduleJob(job, trigger);
        }