Example #1
0
        public void Execute(IJobExecutionContext context)
        {
            string operateType = context.MergedJobDataMap.GetString("OperateType");

            if (!string.IsNullOrWhiteSpace(operateType))
            {
                switch (operateType)
                {
                    case "Test":
                        Test();
                        break;
                    case "JobCreate":

                        JobTrigger jobTrigger = new JobTrigger()
                        {
                            JobID = 1,
                            JobName = context.MergedJobDataMap.GetString("Job.Name"),
                            JobGroup = context.MergedJobDataMap.GetString("Job.Group"),
                            TriggerName = context.MergedJobDataMap.GetString("Trigger.Name"),
                            TriggerCron = context.MergedJobDataMap.GetString("Trigger.Cron"),
                            TriggerStartAt = context.MergedJobDataMap.GetString("Trigger.StartAt"),
                            ExecAssembly = context.MergedJobDataMap.GetString("Job.ExecAssembly"),
                            ExecClassFullName = context.MergedJobDataMap.GetString("Job.ExecClassFullName"),
                            ExecClassMethod = context.MergedJobDataMap.GetString("Job.ExecClassMethod"),
                        };

                        JobCreate(jobTrigger);

                        break;
                    default:
                        break;
                }
            }
        }
Example #2
0
        public void JobCreate(JobTrigger jobTrigger)
        {
            IJobDetail job = JobBuilder.Create<JobExecute>().WithIdentity(jobTrigger.JobName, jobTrigger.JobGroup).Build();

            job.JobDataMap.Add("Job.ExecAssembly", jobTrigger.ExecAssembly);
            job.JobDataMap.Add("Job.ExecClassFullName", jobTrigger.ExecClassFullName);
            job.JobDataMap.Add("Job.ExecClassMethod", jobTrigger.ExecClassMethod);

            ITrigger trigger = TriggerBuilder.Create().WithIdentity(jobTrigger.TriggerName, jobTrigger.JobGroup).WithCronSchedule(jobTrigger.TriggerCron).StartAt(jobTrigger.TriggerStartAt.ToDateTime()).Build();

            SessionGlobal.SchedulerServer.ScheduleJob(job, trigger);
        }