예제 #1
0
        public static bool Set(string schedulerName, string jobsConfigPath, bool isRun, ILogger logger,
                               IJobListener globalJobListener, JobToBeExecuted globalBeforeExecuted,
                               JobWasExecuted globalAfterExecuted)
        {
            schedulerName  = schedulerName.Trim().ToLower();
            jobsConfigPath = jobsConfigPath.Trim().ToLower();

            if (Schedulers.ContainsKey(schedulerName))
            {
                if (jobsConfigPath == Schedulers[schedulerName].JobsConfigPath)
                {
                    throw new Exception("所设置的调度器已经存在,不做任何操作");
                }

                Schedulers[schedulerName].Stop();
                lock (sync)
                {
                    Schedulers.Remove(schedulerName);
                }
            }
            lock (sync)
            {
                Schedulers.Add(schedulerName,
                               new QuartzScheduler(schedulerName, jobsConfigPath, logger, globalJobListener,
                                                   globalBeforeExecuted, globalAfterExecuted));
                if (isRun)
                {
                    Schedulers[schedulerName].Start();
                }
            }
            return(true);
        }
예제 #2
0
 public static bool SetAndRun(string schedulerName, string jobsConfigPath, ILogger logger,
                              IJobListener globalJobListener, JobToBeExecuted globalBeforeExecuted,
                              JobWasExecuted globalAfterExecuted)
 {
     return(Set(schedulerName, jobsConfigPath, true, logger, globalJobListener, globalBeforeExecuted,
                globalAfterExecuted));
 }
예제 #3
0
        public QuartzScheduler(string name, string jobsConfigPath, ILogger logger, IJobListener globalJobListener,
                               JobToBeExecuted globalBeforeExecuted, JobWasExecuted globalAfterExecuted)
        {
            JobsConfigPath = jobsConfigPath;
            JobCfgFileWatch();

            if (logger == null)
            {
                Log = LogCentral.Current;
            }
            else
            {
                Log = logger;
            }

            if (name == null)
            {
                Name = jobsConfigPath;
            }
            else
            {
                Name = name;
            }

            GlobalJobListener    = globalJobListener;
            GlobalBeforeExecuted = globalBeforeExecuted;
            GlobalAfterExecuted  = globalAfterExecuted;

            IsStop = true;
        }
예제 #4
0
        public QuartzJobsListener(string name, JobToBeExecuted beforeExecuted, JobWasExecuted afterExecuted)
        {
            if (Clover.Core.Common.StringHelper.IsEmpty(name))
            {
                Name = "QuartzJobsListener";
            }
            else
            {
                Name = name;
            }

            _beforeExecuted = beforeExecuted;
            _afterExecuted  = afterExecuted;
        }
예제 #5
0
        public void Start(JobToBeExecuted globalBeforeExecuted, JobWasExecuted globalAfterExecuted)
        {
            GlobalBeforeExecuted = globalBeforeExecuted;
            GlobalAfterExecuted  = globalAfterExecuted;
            try
            {
                sched.Start();

                _isStop = false;

                LogCentral.Current.Info("Quartz Task Start Success");
            }
            catch (Exception ex)
            {
                LogCentral.Current.Error("Quartz Task Start Error", ex);

                if (sched.IsShutdown)
                {
                    Start(GlobalBeforeExecuted, GlobalAfterExecuted);
                }
            }
        }
예제 #6
0
        public static bool Add(string schedulerName, string jobsConfigPath, bool isRun, ILogger logger,
                               IJobListener globalJobListener, JobToBeExecuted globalBeforeExecuted,
                               JobWasExecuted globalAfterExecuted)
        {
            schedulerName  = schedulerName.Trim().ToLower();
            jobsConfigPath = jobsConfigPath.Trim().ToLower();

            if (Schedulers.ContainsKey(schedulerName))
            {
                throw new Exception(string.Concat("已存在相同名称的调度器,参数:schedulerName='", schedulerName, "'"));
            }
            lock (sync)
            {
                Schedulers.Add(schedulerName,
                               new QuartzScheduler(schedulerName, jobsConfigPath, logger, globalJobListener,
                                                   globalBeforeExecuted, globalAfterExecuted));
                if (isRun)
                {
                    Schedulers[schedulerName].Start();
                }
            }
            return(true);
        }
예제 #7
0
 public QuartzJobsListener(JobToBeExecuted beforeExecuted, JobWasExecuted afterExecuted) : this(null, beforeExecuted, afterExecuted)
 {
 }
예제 #8
0
 public static void FireJobWasExecutedEvent(object sender, EventArgs args)
 {
     JobWasExecuted?.Invoke(sender, args);
 }