Example #1
0
        public object ServiceInit()
        {
            ILog log = ServiceUtils.GetLogger("quartz.job.log");

            log.Info("------- Initializing ----------------------");
            try
            {
                ISchedulerFactory          sf        = new StdSchedulerFactory();
                IScheduler                 sched     = sf.GetScheduler();
                JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(true, true);
                processor.ProcessFileAndScheduleJobs(string.Format("{0}/Config/Job.xml", AppDomain.CurrentDomain.BaseDirectory), sched, true);
                sched.Start();
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(null);
        }
Example #2
0
        public void Start()
        {
            _logger.Debug("启动 JobEngine....");

            try
            {
                var path      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "quartz_jobs.xml");
                var sf        = new StdSchedulerFactory();
                var processor = new JobSchedulingDataProcessor(true, true);
                _scheduledJobs = sf.GetScheduler();
                processor.ProcessFileAndScheduleJobs(path, _scheduledJobs, false);
                _scheduledJobs.Start();

                _logger.Debug("启动 JobEngine 完成.");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                _logger.Error(ex.StackTrace);
            }
        }
        private void ProcessFile(JobFile jobFile)
        {
            if ((jobFile == null) || (jobFile.FileFound == false))
            {
                return;
            }

            JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(Validating, ValidatingSchema);

            try
            {
                processor.ProcessFileAndScheduleJobs(
                    jobFile.FilePath,
                    jobFile.FilePath, // systemId
                    scheduler,
                    OverwriteExistingJobs);
            }
            catch (Exception e)
            {
                Log.Error("Error scheduling jobs: " + e.Message, e);
            }
        }
 public void SetUp()
 {
     mockery       = new MockRepository();
     processor     = new JobSchedulingDataProcessor(true, true);
     mockScheduler = (IScheduler)mockery.DynamicMock(typeof(IScheduler));
 }
        /// <summary>
        /// Register jobs and triggers (within a transaction, if possible).
        /// </summary>
        protected virtual void RegisterJobsAndTriggers()
        {
            ITransactionStatus transactionStatus = null;

            if (transactionManager != null)
            {
                transactionStatus = transactionManager.GetTransaction(new DefaultTransactionDefinition());
            }
            try
            {
                if (jobSchedulingDataLocations != null)
                {
                    JobSchedulingDataProcessor dataProcessor = new JobSchedulingDataProcessor(true, true);
                    for (int i = 0; i < this.jobSchedulingDataLocations.Length; i++)
                    {
                        dataProcessor.ProcessFileAndScheduleJobs(
                            jobSchedulingDataLocations[i], GetScheduler(), overwriteExistingJobs);
                    }
                }

                // Register JobDetails.
                if (jobDetails != null)
                {
                    foreach (JobDetail jobDetail in jobDetails)
                    {
                        AddJobToScheduler(jobDetail);
                    }
                }
                else
                {
                    // Create empty list for easier checks when registering triggers.
                    jobDetails = new LinkedList();
                }

                // Register Calendars.
                if (calendars != null)
                {
                    foreach (DictionaryEntry entry in calendars)
                    {
                        string    calendarName = (string)entry.Key;
                        ICalendar calendar     = (ICalendar)entry.Value;
                        GetScheduler().AddCalendar(calendarName, calendar, true, true);
                    }
                }

                // Register Triggers.
                if (triggers != null)
                {
                    foreach (Trigger trigger in triggers)
                    {
                        AddTriggerToScheduler(trigger);
                    }
                }
            }

            catch (Exception ex)
            {
                if (transactionStatus != null)
                {
                    try
                    {
                        transactionManager.Rollback(transactionStatus);
                    }
                    catch (TransactionException)
                    {
                        logger.Error("Job registration exception overridden by rollback exception", ex);
                        throw;
                    }
                }
                if (ex is SchedulerException)
                {
                    throw;
                }
                throw new SchedulerException("Registration of jobs and triggers failed: " + ex.Message);
            }

            if (transactionStatus != null)
            {
                transactionManager.Commit(transactionStatus);
            }
        }
        private void ProcessFile(JobFile jobFile)
        {
            if ((jobFile == null) || (jobFile.FileFound == false))
            {
                return;
            }

            JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(Validating, ValidatingSchema);

            try
            {
                processor.ProcessFileAndScheduleJobs(
                    jobFile.FilePath,
                    jobFile.FilePath, // systemId 
                    scheduler,
                    OverwriteExistingJobs);
            }
            catch (Exception e)
            {
                Log.Error("Error scheduling jobs: " + e.Message, e);
            }
        }