Ejemplo n.º 1
0
        /// <inheritdoc/>
        public void AddJob(IJob jobObject, JobStartType startType = JobStartType.Immediate)
        {
            if (this.IsJobRegistered(jobObject.GetType()))
            {
                return; // Job is already added
            }
            var ji = new JobExecutionInfo(jobObject, startType, new object[0]);

            this.m_jobs.Add(ji);
            if (startType == JobStartType.Immediate)
            {
                this.m_threadPool.QueueUserWorkItem(this.RunJob, ji);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start the timer
        /// </summary>
        public bool Start()
        {
            Trace.TraceInformation("Starting timer service...");

            // Invoke the starting event handler
            this.Starting?.Invoke(this, EventArgs.Empty);

            foreach (var configuration in this.m_configuration.Jobs)
            {
                var job = configuration.Type.CreateInjected() as IJob;
                var ji  = new JobExecutionInfo(job, configuration.StartType, configuration.Parameters);
                this.m_tracer.TraceInfo("Adding {0} from configuration (start type of {0})", ji.Job.Name, configuration.StartType);
                this.m_jobs.Add(ji);

                if (configuration.Schedule?.Any() == true)
                {
                    this.m_jobScheduleManager.Clear(job);
                    configuration.Schedule.ForEach(s => this.m_jobScheduleManager.Add(job, s));
                }

                if (configuration.StartType == JobStartType.Immediate)
                {
                    this.m_threadPool.QueueUserWorkItem(this.RunJob, ji);
                }
            }

            // Setup timers based on the jobs
            this.m_systemTimer          = new System.Timers.Timer(300000); // timer runs every 5 minutes
            this.m_systemTimer.Elapsed += SystemJobTimer;
            this.m_systemTimer.Enabled  = true;
            this.m_systemTimer.Start();
            this.Started?.Invoke(this, EventArgs.Empty);

            Trace.TraceInformation("Timer service started successfully");
            return(true);
        }