Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JobRunner"/> class.
        /// </summary>
        public JobRunner(IJobConfiguration configuration, Type jobType, JobLockProvider jobLockProvider, JobHistoryProvider jobHistoryProvider, IDependencyResolver dependencyResolver)
        {
            _id = Guid.NewGuid().ToString("N").Substring(0, 10).ToLower();
            _isBusy = new Synchronized<bool>();
            _lastResult = new Synchronized<string>();
            _lastRunStartTime = new Synchronized<DateTime>();
            _lastRunFinishTime = new Synchronized<DateTime>();
            _lastStatus = new Synchronized<JobStatus>();
            _nextRunTime = new Synchronized<DateTime>();
            _status = new Synchronized<JobStatus>();
            _runLock = new object();
            _name = configuration.Name;
            _description = configuration.Description;
            _group = configuration.Group;
            _interval = configuration.Interval;
            _isTimeOfDay = configuration.IsTimeOfDay;
            _keepAlive = configuration.KeepAlive;
            _arguments = configuration.Arguments;

            _jobType = jobType;
            _jobLockProvider = jobLockProvider ?? new DefaultJobLockProvider();
            _dependencyResolver = dependencyResolver ?? new DefaultDependencyResolver();
            _jobHistoryProvider = jobHistoryProvider;

            _instance = null;
            _timer = new Timer(OnTimerCallback);

            if (_jobHistoryProvider != null)
                _jobHistoryProvider.RestoreHistory(this);

            Trace.TraceInformation("Job {0} created on {1}.", Name, Environment.MachineName);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="JobRunner"/> class.
        /// </summary>
        public JobRunner(IJobConfiguration configuration, Type jobType, JobLockProvider jobLockProvider, JobHistoryProvider jobHistoryProvider, IDependencyResolver dependencyResolver)
        {
            _id                = Guid.NewGuid().ToString("N").Substring(0, 10).ToLower();
            _isBusy            = new Synchronized <bool>();
            _lastResult        = new Synchronized <string>();
            _lastRunStartTime  = new Synchronized <DateTime>();
            _lastRunFinishTime = new Synchronized <DateTime>();
            _lastStatus        = new Synchronized <JobStatus>();
            _nextRunTime       = new Synchronized <DateTime>();
            _status            = new Synchronized <JobStatus>();
            _runLock           = new object();
            _name              = configuration.Name;
            _description       = configuration.Description;
            _group             = configuration.Group;
            _interval          = configuration.Interval;
            _isTimeOfDay       = configuration.IsTimeOfDay;
            _keepAlive         = configuration.KeepAlive;
            _arguments         = configuration.Arguments;

            _jobType            = jobType;
            _jobLockProvider    = jobLockProvider ?? new DefaultJobLockProvider();
            _dependencyResolver = dependencyResolver ?? new DefaultDependencyResolver();
            _jobHistoryProvider = jobHistoryProvider;

            _instance = null;
            _timer    = new Timer(OnTimerCallback);

            if (_jobHistoryProvider != null)
            {
                _jobHistoryProvider.RestoreHistory(this);
            }

            Trace.TraceInformation("Job {0} created on {1}.", Name, Environment.MachineName);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="JobManager"/> class.
 /// </summary>
 internal JobManager()
 {
     _id = Guid.NewGuid().ToString("N").Substring(0, 10).ToLower();
     _providerJobs = new Dictionary<JobProvider, JobCollection>();
     _jobLockProviders = new JobLockProviderCollection();
     _defaultJobLockProvider = new DefaultJobLockProvider();
     _jobProviders = new JobProviderCollection();
     _jobs = new JobCollection();
     _jobProviderTimer = new Timer(OnJobProviderCallback);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="JobManager"/> class.
 /// </summary>
 internal JobManager()
 {
     _id                     = Guid.NewGuid().ToString("N").Substring(0, 10).ToLower();
     _providerJobs           = new Dictionary <JobProvider, JobCollection>();
     _jobLockProviders       = new JobLockProviderCollection();
     _defaultJobLockProvider = new DefaultJobLockProvider();
     _jobProviders           = new JobProviderCollection();
     _jobs                   = new JobCollection();
     _jobProviderTimer       = new Timer(OnJobProviderCallback);
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JobLock"/> class.
 /// </summary>
 /// <param name="provider">The lock provider to call when disposing.</param>
 /// <param name="lockName">Name of the lock.</param>
 /// <param name="lockAcquired">if set to <c>true</c> lock was acquired.</param>
 public JobLock(JobLockProvider provider, string lockName, bool lockAcquired)
 {
     _lockAcquired = lockAcquired;
     _lockName     = lockName;
     _provider     = provider;
 }
        private void AddJobs(IEnumerable <IJobConfiguration> jobs, JobProvider provider)
        {
            if (jobs == null)
            {
                return;
            }

            foreach (var jobConfiguration in jobs)
            {
                Type jobType = Type.GetType(jobConfiguration.Type, false, true);
                if (jobType == null)
                {
                    throw new ConfigurationErrorsException(
                              String.Format("Could not load type '{0}' for job '{1}'.",
                                            jobConfiguration.Type, jobConfiguration.Name));
                }

                JobLockProvider jobLockProvider = _defaultJobLockProvider;

                if (!String.IsNullOrEmpty(jobConfiguration.JobLockProvider))
                {
                    // first try getting from provider collection
                    jobLockProvider = _jobLockProviders[jobConfiguration.JobLockProvider];
                    if (jobLockProvider == null)
                    {
                        // next, try loading type
                        Type lockType = Type.GetType(jobConfiguration.JobLockProvider, false, true);
                        if (lockType == null)
                        {
                            throw new ConfigurationErrorsException(
                                      String.Format("Could not load job lock type '{0}' for job '{1}'.",
                                                    jobConfiguration.JobLockProvider, jobConfiguration.Name));
                        }

                        jobLockProvider = _dependencyResolver.GetService <JobLockProvider>();
                    }

                    // if not found in provider collection or couldn't create type.
                    if (jobLockProvider == null)
                    {
                        throw new ConfigurationErrorsException(
                                  String.Format("Could not find job lock provider '{0}' for job '{1}'.", jobConfiguration.JobLockProvider, jobConfiguration.Name));
                    }
                }

                JobHistoryProvider jobHistoryProvider = null;
                if (!String.IsNullOrEmpty(jobConfiguration.JobHistoryProvider))
                {
                    Type historyType = Type.GetType(jobConfiguration.JobHistoryProvider, false, true);
                    if (historyType == null)
                    {
                        throw new ConfigurationErrorsException(
                                  String.Format("Could not load job history type '{0}' for job '{1}'.", jobConfiguration.JobHistoryProvider, jobConfiguration.Name));
                    }

                    jobHistoryProvider = _dependencyResolver.GetService <JobHistoryProvider>();
                }

                var j = new JobRunner(jobConfiguration, jobType, jobLockProvider, jobHistoryProvider, _dependencyResolver);
                _jobs.Add(j);

                // keep track of jobs for providers so they can be sync'd later
                if (provider == null)
                {
                    continue;
                }

                JobCollection providerJobs;
                if (!_providerJobs.TryGetValue(provider, out providerJobs))
                {
                    providerJobs = new JobCollection();
                    _providerJobs.Add(provider, providerJobs);
                }
                providerJobs.Add(j);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="JobLock"/> class.
 /// </summary>
 /// <param name="provider">The lock provider to call when disposing.</param>
 /// <param name="lockName">Name of the lock.</param>
 /// <param name="lockAcquired">if set to <c>true</c> lock was acquired.</param>
 public JobLock(JobLockProvider provider, string lockName, bool lockAcquired)
 {
     _lockAcquired = lockAcquired;
     _lockName = lockName;
     _provider = provider;
 }