/// <summary> /// Releases the unmanaged resources used by the <see cref="ServiceHelper"/> object and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!m_disposed) { try { // This will be done regardless of whether the object is finalized or disposed. if (disposing) { // This will be done only when the object is disposed by calling Dispose(). SaveSettings(); if (m_statusLog != null) { m_statusLog.LogException -= m_statusLog_LogException; m_statusLog.Dispose(); } m_statusLog = null; if (m_processScheduler != null) { m_processScheduler.ScheduleDue -= m_scheduler_ScheduleDue; m_processScheduler.Dispose(); } m_processScheduler = null; if (m_errorLogger != null) { m_errorLogger.Dispose(); } m_errorLogger = null; if (m_performanceMonitor != null) { m_performanceMonitor.Dispose(); } m_performanceMonitor = null; if (m_remoteCommandProcess != null) { m_remoteCommandProcess.ErrorDataReceived -= m_remoteCommandProcess_ErrorDataReceived; m_remoteCommandProcess.OutputDataReceived -= m_remoteCommandProcess_OutputDataReceived; if (!m_remoteCommandProcess.HasExited) m_remoteCommandProcess.Kill(); m_remoteCommandProcess.Dispose(); } m_remoteCommandProcess = null; // Service processes are created and owned by remoting server, so we dispose them if (m_processes != null) { foreach (ServiceProcess process in m_processes) { process.StateChanged -= process_StateChanged; process.Dispose(); } m_processes.Clear(); } m_processes = null; // Detach any remoting server events, we don't own this component so we don't dispose it RemotingServer = null; } } finally { base.Dispose(disposing); // Call base class Dispose(). m_disposed = true; // Prevent duplicate dispose. } } }
/// <summary> /// Initializes a new instance of the <see cref="ServiceHelper"/> class. /// </summary> public ServiceHelper() : base() { m_logStatusUpdates = DefaultLogStatusUpdates; m_monitorServiceHealth = DefaultMonitorServiceHealth; m_requestHistoryLimit = DefaultRequestHistoryLimit; m_queryableSettingsCategories = DefaultQueryableSettingsCategories; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_processes = new List<ServiceProcess>(); m_remoteClients = new List<ClientInfo>(); m_clientRequestHistory = new List<ClientRequest.Info>(); m_serviceComponents = new List<ISupportLifecycle>(); m_clientRequestHandlers = new List<ClientRequestHandler>(); m_componentEnabledStates = new Dictionary<ISupportLifecycle, bool>(); m_telnetPassword = "******"; // Components m_statusLog = new LogFile(); m_statusLog.LogException += m_statusLog_LogException; m_statusLog.FileName = "StatusLog.txt"; m_statusLog.SettingsCategory = "StatusLog"; m_processScheduler = new ScheduleManager(); m_processScheduler.ScheduleDue += m_scheduler_ScheduleDue; m_processScheduler.SettingsCategory = "ProcessScheduler"; m_errorLogger = new ErrorLogger(); m_errorLogger.ExitOnUnhandledException = false; m_errorLogger.SettingsCategory = "ErrorLogger"; m_errorLogger.ErrorLog.SettingsCategory = "ErrorLog"; }
/// <summary> /// Initializes a new instance of the <see cref="ErrorLogger"/> class. /// </summary> public ErrorLogger() : base() { m_logToUI = DefaultLogToUI; m_logToFile = DefaultLogToFile; m_logToEmail = DefaultLogToEmail; m_logToEventLog = DefaultLogToEventLog; m_logToScreenshot = DefaultLogToScreenshot; m_smtpServer = DefaultSmtpServer; m_contactName = DefaultContactName; m_contactEmail = DefaultContactEmail; m_contactPhone = DefaultContactPhone; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_handleUnhandledException = DefaultHandleUnhandledException; m_exitOnUnhandledException = DefaultExitOnUnhandledException; // Initialize delegate methods. m_errorTextMethod = GetErrorText; m_scopeTextMethod = GetScopeText; m_actionTextMethod = GetActionText; m_moreInfoTextMethod = GetMoreInfoText; // Initialize the error log file. m_errorLog = new LogFile(); m_errorLog.FileName = "ErrorLog.txt"; // Initialize all logger methods. m_loggers = new List<Action<Exception>>(); m_loggers.Add(ExceptionToScreenshot); m_loggers.Add(ExceptionToEventLog); m_loggers.Add(ExceptionToEmail); m_loggers.Add(ExceptionToFile); m_loggers.Add(ExceptionToUI); }