Esempio n. 1
0
        private void ScheduleScript(CronshopScript script)
        {
            Assembly assembly = LoadAssembly(script);

            if (assembly == null)
            {
                return;
            }

            // find implementations of CronshopJob
            IEnumerable<Type> types = assembly.GetTypes()
                .Where(t => typeof (CronshopJob).IsAssignableFrom(t) && !t.IsAbstract);

            foreach (Type type in types)
            {
                JobConfigurator configurator;

                // create the instance to get the schedule
                using (var instance = (CronshopJob) Activator.CreateInstance(type))
                {
                    configurator = new JobConfigurator();
                    instance.Configure(configurator);
                }

                string name = JobInfo.BuildJobName(script, type);

                var detail = new JobDetailImpl(name, CronshopDefaultGroup, type) {Durable = true};

                Scheduler.AddJob(detail, false);
                Console.WriteLine("ScheduleJob: " + detail.Key);

                var triggers = new List<ITrigger>();

                foreach (string cron in configurator.Crons)
                {
                    var trigger = new CronTriggerImpl(name + @"." + Guid.NewGuid(), CronshopDefaultGroup, cron)
                                      {
                                          JobKey = detail.Key,
                                          MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing,
                                      };

                    triggers.Add(trigger);

                    Scheduler.ScheduleJob(trigger);
                }

                _jobs.Add(detail.Key, new JobInfo(script, detail, triggers));
            }
        }
Esempio n. 2
0
 public abstract void Configure(JobConfigurator config);