Beispiel #1
0
 private void AddJobs(IEnumerable <IJobConfiguration> jobs, JobProvider provider)
 {
     if (jobs != null)
     {
         foreach (IJobConfiguration configuration in jobs)
         {
             Type jobType = Type.GetType(configuration.Type, false, true);
             if (jobType == null)
             {
                 throw new ConfigurationErrorsException(string.Format("Could not load type '{0}' for job '{1}'.", configuration.Type, configuration.Name));
             }
             JobLockProvider jobLockProvider = this._defaultJobLockProvider;
             if (!string.IsNullOrEmpty(configuration.JobLockProvider))
             {
                 jobLockProvider = this._jobLockProviders[configuration.JobLockProvider];
                 if (jobLockProvider == null)
                 {
                     Type type = Type.GetType(configuration.JobLockProvider, false, true);
                     if (type == null)
                     {
                         throw new ConfigurationErrorsException(string.Format("Could not load job lock type '{0}' for job '{1}'.", configuration.JobLockProvider, configuration.Name));
                     }
                     jobLockProvider = Activator.CreateInstance(type) as JobLockProvider;
                 }
                 if (jobLockProvider == null)
                 {
                     throw new ConfigurationErrorsException(string.Format("Could not find job lock provider '{0}' for job '{1}'.", configuration.JobLockProvider, configuration.Name));
                 }
             }
             JobHistoryProvider jobHistoryProvider = null;
             if (!string.IsNullOrEmpty(configuration.JobHistoryProvider))
             {
                 Type type3 = Type.GetType(configuration.JobHistoryProvider, false, true);
                 if (type3 == null)
                 {
                     throw new ConfigurationErrorsException(string.Format("Could not load job history type '{0}' for job '{1}'.", configuration.JobHistoryProvider, configuration.Name));
                 }
                 jobHistoryProvider = Activator.CreateInstance(type3) as JobHistoryProvider;
             }
             Job item = new Job(configuration, jobType, jobLockProvider, jobHistoryProvider);
             this._jobs.Add(item);
             if (provider != null)
             {
                 JobCollection jobs2;
                 if (!this._providerJobs.TryGetValue(provider, out jobs2))
                 {
                     jobs2 = new JobCollection();
                     this._providerJobs.Add(provider, jobs2);
                 }
                 jobs2.Add(item);
             }
         }
     }
 }
Beispiel #2
0
        public JobCollection GetJobsByGroup(string group)
        {
            JobCollection jobs = new JobCollection();

            lock (_initLock)
            {
                foreach (Job job in this._jobs)
                {
                    if (job.Group == group)
                    {
                        jobs.Add(job);
                    }
                }
            }
            return(jobs);
        }
Beispiel #3
0
        private void OnJobProviderCallback(object state)
        {
            bool flag = false;

            lock (_initLock)
            {
                foreach (JobProvider provider in this._jobProviders)
                {
                    if (provider.IsReloadRequired(this._lastInitilize))
                    {
                        JobCollection jobs;
                        Trace.TraceInformation("Reload jobs for provider {0}.", new object[] { provider.ToString() });
                        if (!this._providerJobs.TryGetValue(provider, out jobs))
                        {
                            jobs = new JobCollection();
                            this._providerJobs.Add(provider, jobs);
                        }
                        foreach (Job job in jobs)
                        {
                            job.Stop(true);
                            this._jobs.Remove(job);
                        }
                        jobs.Clear();
                        this.AddJobs(provider.GetJobs(), provider);
                        flag = true;
                        foreach (Job job2 in jobs)
                        {
                            job2.Start();
                        }
                    }
                }
            }
            if (flag)
            {
                this._lastInitilize = DateTime.Now;
            }
        }