コード例 #1
0
        public ConfigurationService()
        {
            configurator = new SyncEngineDatabaseConfigurator(IntegrationWindowsService.IntegrationDbConnectionString);

            scheduledJobManager = new ScheduledJobManager(configurator);
        }
コード例 #2
0
        // Start the Windows service.
        protected override void OnStart(string[] onStartArgs)
        {
            try
            {
                // get connection string from connectionStrings in App.config
                GetIntegrationDbConnectionString();

                // test connection to the queue database
                TestIntegrationDbConnection(IntegrationDbConnectionString);

                _dbQueueLogger = new JobQueueDatabaseLogger(IntegrationDbConnectionString);
                _configurator  = new SyncEngineDatabaseConfigurator(IntegrationDbConnectionString);

                JobQueueManager.Configurator = _configurator;

                _serviceConfig = _configurator.GetServiceConfig();

                // reset the logger as a precaution
                SyncEngineLogger.Clear();

                // configure mail notifications, if enabled
                if (_serviceConfig.EnableMailNotifications)
                {
                    ConfigureMailNotifications();
                }

                // add database and text file loggers
                RegisterLoggers();

                // register integrations for the database and text file loggers
                RegisterIntegrations();

                // associate the database logger with the queue manager
                JobQueueLogManager.AddLogger(_dbQueueLogger);

                // recover any job instances from a server or service restart; this will only apply to on-demand job instances
                _dbQueueLogger.RecoverJobInstancesFromQueueLog();

                // add the next run times for each scheduled job; clear any existing scheduled jobs from the queue
                _scheduledJobManager = new ScheduledJobManager(_configurator);
                _scheduledJobManager.QueueScheduledJobs(clearExistingScheduledJobInstancesFromWaitingQueue: true);

                // once a scheduled job is complete (i.e. queue request), queue for the next run time
                JobQueueManager.JobQueueRequestStatusChanged += new EventHandler <JobQueueRequestStatusChangedArgs>((s, e) =>
                {
                    if (e.QueueRequest.Status == JobQueueRequestStatus.Completed &&
                        e.QueueRequest.InvocationSourceType == JobInvocationSourceType.Scheduled)
                    {
                        _scheduledJobManager.QueueJobForNextScheduledRunTime(e.QueueRequest.Job.Id);
                    }
                });

                JobQueueManager.MaxDelayedStartByJobPriority = _configurator.GetJobPriorityConfig();

                JobQueueManager.Start(_serviceConfig.IntervalInSeconds);

                InitializeWebServiceHosts();
            }
            catch (Exception ex)
            {
                EventViewerLogger.WriteToLog(ex);

                SyncEngineLogger.WriteExceptionToLog(ex);

                // stop the service
                this.Stop();
            }
        }