private static void ConfigureMailNotifications() { SyncEngineLogger.EnableMailNotifications = _serviceConfig.EnableMailNotifications; if (_serviceConfig.EnableMailNotifications) { try { var fromAddress = new MailAddress(_serviceConfig.FromEmailAddress); var toAddresses = new List <MailAddress>(); foreach (var toAddress in _serviceConfig.ToEmailAddresses) { toAddresses.Add(new MailAddress(toAddress)); } SyncEngineLogger.MailConfig = new MailConfig(fromAddress, toAddresses, _serviceConfig.SmtpHost, _serviceConfig.SmtpPort); SyncEngineLogger.MailConfig.EnableSsl = _serviceConfig.SmtpRequiresSsl; if (!(_serviceConfig.SmtpUsername == null || _serviceConfig.SmtpUsername.Trim() == string.Empty)) { SyncEngineLogger.MailConfig.Credentials = new NetworkCredential(_serviceConfig.SmtpUsername, _serviceConfig.SmtpPassword); } } catch (Exception ex) { EventViewerLogger.WriteToLog(ex); SyncEngineLogger.WriteExceptionToLog(ex); } } }
public static void RefreshServiceConfig() { try { _serviceConfig = _configurator.GetServiceConfig(); JobQueueManager.Stop(); ConfigureMailNotifications(); if (!_serviceConfig.LogToDatabase) { SyncEngineLogger.DeregisterLogger(_databaseLogger); } if (!_serviceConfig.LogToFile) { SyncEngineLogger.DeregisterLogger(_textFileLogger); } JobQueueManager.Start(_serviceConfig.IntervalInSeconds); } catch (Exception ex) { EventViewerLogger.WriteToLog(ex); SyncEngineLogger.WriteExceptionToLog(ex); SyncEngineLogger.WriteToLog(LogEntryType.Warning, "The service config could not be refreshed and will occur the next time the service starts."); } }
public static void RefreshIntegrationInLogger(Guid integrationId) { try { SyncEngineLogger.DeregisterIntegration(integrationId); var integrationToRegister = _configurator.GetIntegrationById(integrationId); SyncEngineLogger.RegisterIntegration(integrationToRegister); } catch (Exception ex) { EventViewerLogger.WriteToLog(ex); SyncEngineLogger.WriteExceptionToLog(ex); SyncEngineLogger.WriteToLog(LogEntryType.Warning, "The integration '{0}' could not be refreshed and will occur the next time the service starts.", integrationId); } }
public static void RefreshJobInLogger(Guid jobId) { try { var integrationToRegister = _configurator.GetIntegrationByJobId(jobId); if (integrationToRegister == null) { throw new Exception(string.Format("No integration exists for job '{0}'.", jobId)); } SyncEngineLogger.DeregisterIntegration(integrationToRegister.Id); SyncEngineLogger.RegisterIntegration(integrationToRegister); } catch (Exception ex) { EventViewerLogger.WriteToLog(ex); SyncEngineLogger.WriteExceptionToLog(ex); SyncEngineLogger.WriteToLog(LogEntryType.Warning, "The job '{0}' could not be refreshed and will occur the next time the service starts.", jobId); } }
// 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(); } }