/// <summary> /// Initializes a new instance of the <see cref="T:LFNet.Common.Scheduler.Job" /> class. /// </summary> public Job(IJobConfiguration configuration, Type jobType, JobLockProvider jobLockProvider, JobHistoryProvider jobHistoryProvider) { this._id = Guid.NewGuid().ToString("N").Substring(0, 10).ToLower(); this._isBusy = new Synchronized <bool>(); this._lastResult = new Synchronized <string>(); this._lastRunStartTime = new Synchronized <DateTime>(); this._lastRunFinishTime = new Synchronized <DateTime>(); this._lastStatus = new Synchronized <JobStatus>(); this._nextRunTime = new Synchronized <DateTime>(); this._status = new Synchronized <JobStatus>(); this._runLock = new object(); this._name = configuration.Name; this._description = configuration.Description; this._group = configuration.Group; this._interval = configuration.Interval; this._isTimeOfDay = configuration.IsTimeOfDay; this._keepAlive = configuration.KeepAlive; this._arguments = configuration.Arguments; this._jobType = jobType; this._jobLockProvider = jobLockProvider ?? new DefaultJobLockProvider(); this._jobHistoryProvider = jobHistoryProvider; this._instance = null; this._timer = new Timer(new TimerCallback(this.OnTimerCallback)); if (this._jobHistoryProvider != null) { this._jobHistoryProvider.RestoreHistory(this); } }
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); } } } }