Example #1
0
 public static bool Add(IJobExecutor jobExecutor)
 {
     if (jobExecutor != null)
     {
         psJobExecutors.Add(jobExecutor.GetType().Name, jobExecutor);
     }
     return(true);
 }
        /// <summary>
        /// Schedules the next run of the given job. Deletes existing instances before planning new one.
        /// </summary>
        /// <param name="userConnection">The user connection.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="jobExecutor">The job executor.</param>
        /// <param name="executionPeriod">Periodicity of the given job's trigger (minutes).</param>
        public static void ScheduleNextRun(UserConnection userConnection, string jobName, IJobExecutor jobExecutor,
                                           int executionPeriod)
        {
            if (executionPeriod < 0)
            {
                return;
            }
            IAppSchedulerWraper schedulerWrapper = SchedulerWraper;
            IScheduler          scheduler        = schedulerWrapper.Instance;
            SysUserInfo         currentUser      = userConnection.CurrentUser;
            string     className = jobExecutor.GetType().AssemblyQualifiedName;
            IJobDetail job       = schedulerWrapper.CreateClassJob(className, jobName, userConnection.Workspace.Name,
                                                                   currentUser.Name, null, true);
            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity(className + "Trigger")
                               .StartAt(DateTimeOffset.Now.AddMinutes(executionPeriod))
                               .Build();

            scheduler.ScheduleJob(job, new Quartz.Collection.HashSet <ITrigger> {
                trigger
            }, true);
        }