public ScheduleJobResult ScheduleJob <T>(string jobId, string jobGroup, string cronExpression, Dictionary <string, string> jobData = null, string timeZone = null)
            where T : IJob
        {
            var ret = new ScheduleJobResult();

            // a. build job
            JobBuilder jobBuilder = JobBuilder.Create <T>()
                                    .WithIdentity(jobId, jobGroup);

            if (jobData != null)
            {
                foreach (KeyValuePair <string, string> pair in jobData)
                {
                    jobBuilder.UsingJobData(pair.Key, pair.Value);
                }
            }

            IJobDetail job = jobBuilder.Build();

            ret.Job = job;
            //

            // b. build trigger
            TimeZoneInfo   timeZoneInfo   = string.IsNullOrWhiteSpace(timeZone) ? TimeZoneInfo.Local : TimeZoneInfo.FindSystemTimeZoneById(timeZone);
            TriggerBuilder triggerBuilder = TriggerBuilder.Create()
                                            .WithIdentity(jobId, jobGroup)
                                            .WithCronSchedule(cronExpression, x => x.InTimeZone(timeZoneInfo));

            if (jobData != null)
            {
                foreach (KeyValuePair <string, string> pair in jobData)
                {
                    jobBuilder.UsingJobData(pair.Key, pair.Value);
                }
            }

            ITrigger trigger = triggerBuilder.Build();

            ret.Trigger = trigger;
            //

            // c. schedule job
            if (trigger.GetNextFiringTimes(DateTimeOffset.Now).FirstOrDefault() == default(DateTime))
            {
                ret.Success = false;

                _log.Info($"Job WILL NEVER START for \"{jobId}\"");
            }
            else
            {
                _scheduler.ScheduleJob(job, trigger).Wait();
                ret.Success = true;

                _log.Debug($"Job scheduled OK for \"{jobId}\"");
            }

            return(ret);
        }
        public ScheduleJobResult ScheduleJob <T>(string jobId, string jobGroup, ITrigger trigger, Dictionary <string, string> jobData = null)
            where T : IJob
        {
            var ret = new ScheduleJobResult();

            // a. build job
            JobBuilder jobBuilder = JobBuilder.Create <T>()
                                    .WithIdentity(jobId, jobGroup);

            if (jobData != null)
            {
                foreach (KeyValuePair <string, string> pair in jobData)
                {
                    jobBuilder.UsingJobData(pair.Key, pair.Value);
                }
            }

            IJobDetail job = jobBuilder.Build();

            ret.Job = job;
            //

            // b. use trigger
            ret.Trigger = trigger;
            //

            // c. schedule job
            if (trigger.GetNextFiringTimes(DateTimeOffset.Now).FirstOrDefault() == default(DateTime))
            {
                ret.Success = false;

                _log.Info($"Job WILL NEVER START for \"{jobId}\"");
            }
            else
            {
                _scheduler.ScheduleJob(job, trigger).Wait();
                ret.Success = true;

                _log.Debug($"Job scheduled OK for \"{jobId}\"");
            }

            return(ret);
        }
 public void UnscheduleTask(ScheduleJobResult scheduleJobResult)
 {
     _scheduler.UnscheduleJob(scheduleJobResult.Trigger.Key).Wait();
 }