Exemple #1
0
        public ActionResult AddJob(AddJobViewModel model)
        {
            try
            {
                var type       = JobUtil.Create(model.NameSpace, string.Format("{0}.{1}", model.NameSpace, model.ClassName));
                var properties = new Dictionary <string, object>();
                if (model.TriggerProperties != null)
                {
                    foreach (var keyVal in model.TriggerProperties)
                    {
                        try
                        {
                            string[] splitted = keyVal.Split('=');
                            properties.Add(splitted[0].Replace(" ", ""), splitted[1]);
                        }
                        catch (Exception) {}
                    }
                }
                Scheduler.Instance.AddJob(model.JobName, model.JobGroup, model.JobName, model.JobGroup,
                                          model.CronExpression, type, model.IsDurable, properties);
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, responseMessage = ex.Message }));
            }

            return(Json(new { success = true }));
        }
        static void Main(string[] args)
        {
            var conn = new Connection
            {
                Port          = 555,
                SchedulerName = "QuartzScheduler",
                ServerName    = "localhost"
            };

            IJobScheduler jobScheduler = JobSchedulerFactory.CreateJobScheduler(conn);

            // var lis=jobScheduler.GetCurrentlyExecutingJobs();
            var metadata = jobScheduler.GetMetaData();

            jobScheduler.GetAllJobs();
            jobScheduler.ScheduleJob("LongJob", "LongJob", "0 0/1 * 1/1 * ? *");
            jobScheduler.DeleteJob("LongJob", "LongJob");

            var type = JobUtil.Create("QuartzScheduler.Test.LongTimeJob", "QuartzScheduler.Test.LongTimeJob.LongJob");

            jobScheduler.PauseJob("SampleJob", "SampleJob");
            jobScheduler.UnscheduleJob("SampleJob", "SampleJob");
            jobScheduler.ScheduleJob("SampleJob", "SampleJob", "0/10 * * * * ?");

            //jobScheduler.AddJob("SampleJob", "SampleJob", "0 0/1 * 1/1 * ? *", type, true, jobData);

            //jobScheduler.UnscheduleJob("SampleJob", "SampleJob");
            //jobScheduler.ScheduleJob("SampleJob", "SampleJob", "10 * * * * ?");

            //jobScheduler.PauseTrigger("SampleJob", "SampleJob");
            //jobScheduler.ResumeTrigger("SampleJob", "SampleJob");

            //jobScheduler.Shutdown(true);

            //jobScheduler.TriggerJob("SampleJob", "SampleJob");

            var list = jobScheduler.GetAllJobs();
        }