private static Trigger BuildTrigger(JobItem jobItem)
        {
            Trigger trigger = TriggerBuilder.Build(jobItem.Trigger);

            trigger.Name = string.Format("{0}Trigger", jobItem.Name);
            return(trigger);
        }
        private JobDetail BuildJobDetail(JobItem job)
        {
            JobDetail jobDetail = new JobDetail(job.Name, SchedulerConstants.DefaultGroup, Type.GetType(job.Type));

            jobDetail.JobDataMap.PutAll(job.GetParams());
            jobDetail.JobDataMap.Put("JobName", job.Name);
            return(jobDetail);
        }
        public void Unschedule(string name)
        {
            JobItem job = jobLoader.LoadJob(name);

            if (job != null && job.Enabled)
            {
                logger.Debug("Unschedule Job: " + name);
                Trigger trigger = TriggerBuilder.Build(job.Trigger);
                scheduler.UnscheduleJob(trigger.Name, SchedulerConstants.DefaultGroup);
                job.Enabled = false;
            }
        }
        public void Schedule(string name)
        {
            JobItem job = jobLoader.LoadJob(name);

            if (job != null && !job.Enabled)
            {
                logger.Debug("Schedule Job: " + name);
                JobDetail jobDetail = BuildJobDetail(job);
                Trigger   trigger   = TriggerBuilder.Build(job.Trigger);
                scheduler.ScheduleJob(jobDetail, trigger);
                job.Enabled = true;
            }
        }
        public void Reschedule(string name, Trigger trigger)
        {
            JobItem job = jobLoader.LoadJob(name);

            if (job != null)
            {
                logger.Debug("Reschedule Job: " + name);
                Unschedule(name);
                JobDetail jobDetail = BuildJobDetail(job);
                scheduler.ScheduleJob(jobDetail, trigger);
                job.Enabled = true;
            }
        }
        public DateTime?GetPreviousFireTime(string name)
        {
            JobItem job = jobLoader.LoadJob(name);

            if (job != null)
            {
                Trigger trigger     = TriggerBuilder.Build(job.Trigger);
                Trigger currTrigger = scheduler.GetTrigger(trigger.Name, SchedulerConstants.DefaultGroup);
                if (currTrigger != null)
                {
                    return(trigger.GetPreviousFireTimeUtc());
                }
            }
            return(null);
        }
        public void RunNowJob(string name)
        {
            JobItem job = jobLoader.LoadJob(name);

            if (job != null)
            {
                logger.Debug("Schedule Run Now Job: " + name);

                Trigger trigger = TriggerBuilder.Build(job.Trigger);
                trigger.StartTimeUtc = DateTime.UtcNow;
                if (trigger is SimpleTrigger)
                {
                    ((SimpleTrigger)trigger).SetPreviousFireTime(DateTime.UtcNow);
                }

                Reschedule(name, trigger);
            }
        }