Ejemplo n.º 1
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadDeviceDefs", "Reloads the device definitions file", ReloadDeviceDefsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated  += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded   += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.Initialize();

            // Set up fault location engine
            m_faultLocationEngine = new FaultLocationEngine();
            m_faultLocationEngine.StatusMessage    += FaultLocationEngine_StatusMessage;
            m_faultLocationEngine.ProcessException += FaultLocationEngine_ProcessException;
            m_faultLocationEngine.Start();
        }
Ejemplo n.º 2
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadDeviceDefs", "Reloads the device definitions file", ReloadDeviceDefsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.Initialize();

            // Set up fault location engine
            m_faultLocationEngine = new FaultLocationEngine();
            m_faultLocationEngine.StatusMessage += FaultLocationEngine_StatusMessage;
            m_faultLocationEngine.ProcessException += FaultLocationEngine_ProcessException;
            m_faultLocationEngine.Start();
        }
Ejemplo n.º 3
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            ServiceHelperAppender serviceHelperAppender;
            RollingFileAppender   fileAppender;
            ServiceProcess        process;

            // Set current working directory to fix relative paths
            Directory.SetCurrentDirectory(FilePath.GetAbsolutePath(""));

            // Set up logging
            serviceHelperAppender = new ServiceHelperAppender(m_serviceHelper);

            fileAppender = new RollingFileAppender();
            fileAppender.StaticLogFileName            = false;
            fileAppender.AppendToFile                 = true;
            fileAppender.RollingStyle                 = RollingFileAppender.RollingMode.Composite;
            fileAppender.MaxSizeRollBackups           = 10;
            fileAppender.PreserveLogFileNameExtension = true;
            fileAppender.MaximumFileSize              = "1MB";
            fileAppender.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            try
            {
                if (!Directory.Exists("Debug"))
                {
                    Directory.CreateDirectory("Debug");
                }

                fileAppender.File = @"Debug\openEAS.log";
            }
            catch (Exception ex)
            {
                fileAppender.File = "openEAS.log";
                m_serviceHelper.ErrorLogger.Log(ex);
            }

            fileAppender.ActivateOptions();
            BasicConfigurator.Configure(serviceHelperAppender, fileAppender);
            // Set up the analysis engine
            m_extensibleDisturbanceAnalysisEngine    = new SandBoxEngine();
            AppDomain.CurrentDomain.AssemblyResolve += m_extensibleDisturbanceAnalysisEngine.AssemblyResolveHandler;

            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ProcessLatestData, "ProcessLatestData", "* * * * *");
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadSystemSettings", "Reloads system settings from the database", ReloadSystemSettingsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated  += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded   += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded;
            m_serviceHelper.UpdatedStatus     += UpdatedStatusHandler;

            m_serviceMonitors.Initialize();


            // Process latest data at startup
            process = m_serviceHelper.FindProcess("ProcessLatestData");

            if ((object)process != null)
            {
                process.Start();
            }

            bool webUI = false;

            while (!webUI)
            {
                webUI = TryStartWebUI();
            }
        }
Ejemplo n.º 4
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            ServiceHelperAppender serviceHelperAppender;
            RollingFileAppender   debugLogAppender;

            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;

            // Set current working directory to fix relative paths
            Directory.SetCurrentDirectory(FilePath.GetAbsolutePath(""));

            // Set up logging
            serviceHelperAppender = new ServiceHelperAppender(m_serviceHelper);

            debugLogAppender = new RollingFileAppender();
            debugLogAppender.StaticLogFileName            = false;
            debugLogAppender.AppendToFile                 = true;
            debugLogAppender.RollingStyle                 = RollingFileAppender.RollingMode.Composite;
            debugLogAppender.MaxSizeRollBackups           = 10;
            debugLogAppender.PreserveLogFileNameExtension = true;
            debugLogAppender.MaximumFileSize              = "1MB";
            debugLogAppender.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            try
            {
                if (!Directory.Exists("Debug"))
                {
                    Directory.CreateDirectory("Debug");
                }

                debugLogAppender.File = @"Debug\SystemCenter.log";
            }
            catch (Exception ex)
            {
                debugLogAppender.File = "SystemCenter.log";
                m_serviceHelper.ErrorLogger.Log(ex);
            }

            debugLogAppender.ActivateOptions();
            BasicConfigurator.Configure(serviceHelperAppender, debugLogAppender);

            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.AddScheduledProcess(ReloadConfigurationHandler, "ReloadConfiguration", "0 0 * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadSystemSettings", "Reloads system settings from the database", ReloadSystemSettingsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("EngineStatus", "Displays status information about the XDA engine", EngineStatusHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));
            m_serviceHelper.UpdatedStatus   += UpdatedStatusHandler;
            m_serviceHelper.LoggedException += LoggedExceptionHandler;

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated       += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded        += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded      += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.AdapterLoadException += (obj, args) => HandleException(args.Argument);
            m_serviceMonitors.Initialize();

            string systemSettingsConnectionString = LoadSystemSettings();

            // Set up the system center engine
            m_systemCenterEngine = new SystemCenterEngine();

            // Set up separate thread to start the engine
            m_startEngineThread = new Thread(() =>
            {
                const int RetryDelay = 1000;
                const int SleepTime  = 200;
                const int LoopCount  = RetryDelay / SleepTime;

                bool engineStarted = false;
                bool webUIStarted  = false;

                while (true)
                {
                    engineStarted = engineStarted || TryStartEngine();
                    webUIStarted  = webUIStarted || TryStartWebUI();

                    if (engineStarted && webUIStarted)
                    {
                        break;
                    }

                    for (int i = 0; i < LoopCount; i++)
                    {
                        if (m_serviceStopping)
                        {
                            return;
                        }

                        Thread.Sleep(SleepTime);
                    }
                }
            });

            m_startEngineThread.Start();
        }
Ejemplo n.º 5
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            const int RetryDelay = 1000;
            const int SleepTime  = 200;
            const int LoopCount  = RetryDelay / SleepTime;

            ServiceHelperAppender serviceHelperAppender;
            RollingFileAppender   fileAppender;

            // Set current working directory to fix relative paths
            Directory.SetCurrentDirectory(FilePath.GetAbsolutePath(""));

            // Set up logging
            serviceHelperAppender = new ServiceHelperAppender(m_serviceHelper);

            fileAppender = new RollingFileAppender();
            fileAppender.StaticLogFileName            = false;
            fileAppender.AppendToFile                 = true;
            fileAppender.RollingStyle                 = RollingFileAppender.RollingMode.Composite;
            fileAppender.MaxSizeRollBackups           = 10;
            fileAppender.PreserveLogFileNameExtension = true;
            fileAppender.MaximumFileSize              = "1MB";
            fileAppender.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            try
            {
                if (!Directory.Exists("Debug"))
                {
                    Directory.CreateDirectory("Debug");
                }

                fileAppender.File = @"Debug\openXDA.log";
            }
            catch (Exception ex)
            {
                fileAppender.File = "openXDA.log";
                m_serviceHelper.ErrorLogger.Log(ex);
            }

            fileAppender.ActivateOptions();
            BasicConfigurator.Configure(serviceHelperAppender, fileAppender);

            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.AddScheduledProcess(ReloadConfigurationHandler, "ReloadConfiguration", "0 0 * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadSystemSettings", "Reloads system settings from the database", ReloadSystemSettingsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("EngineStatus", "Displays status information about the XDA engine", EngineStatusHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("TweakFileProcessor", "Modifies the behavior of the file processor at runtime", TweakFileProcessorHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated  += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded   += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.Initialize();

            // Set up the analysis engine
            m_extensibleDisturbanceAnalysisEngine = new ExtensibleDisturbanceAnalysisEngine();

            // Set up separate thread to start the engine
            m_startEngineThread = new Thread(() =>
            {
                while (!TryStartEngine())
                {
                    for (int i = 0; i < LoopCount; i++)
                    {
                        if (m_serviceStopping)
                        {
                            return;
                        }

                        Thread.Sleep(SleepTime);
                    }
                }
            });

            m_startEngineThread.Start();

            CategorizedSettingsElementCollection systemSettings   = ConfigurationFile.Current.Settings["systemSettings"];
            CategorizedSettingsElementCollection securityProvider = ConfigurationFile.Current.Settings["securityProvider"];

            ValidateAccountsAndGroups(new AdoDataConnection("securityProvider"));

            systemSettings.Add("CompanyName", "Grid Protection Alliance", "The name of the company who owns this instance of the openMIC.");
            systemSettings.Add("CompanyAcronym", "GPA", "The acronym representing the company who owns this instance of the openMIC.");
            systemSettings.Add("WebHostURL", "http://localhost:8080", "The web hosting URL for remote system management.");
            systemSettings.Add("DateFormat", "MM/dd/yyyy", "The default date format to use when rendering timestamps.");
            systemSettings.Add("TimeFormat", "HH:mm.ss.fff", "The default time format to use when rendering timestamps.");
            systemSettings.Add("BootstrapTheme", "Content/bootstrap.min.css", "Path to Bootstrap CSS to use for rendering styles.");
            systemSettings.Add("DefaultDialUpRetries", 3, "Default dial-up connection retries.");
            systemSettings.Add("DefaultDialUpTimeout", 90, "Default dial-up connection timeout.");
            systemSettings.Add("DefaultFTPUserName", "anonymous", "Default FTP user name to use for device connections.");
            systemSettings.Add("DefaultFTPPassword", "anonymous", "Default FTP password to use for device connections.");
            systemSettings.Add("DefaultRemotePath", "/", "Default remote FTP path to use for device connections.");
            systemSettings.Add("DefaultLocalPath", "", "Default local path to use for file downloads.");

            DefaultWebPage = systemSettings["DefaultWebPage"].Value;

            Model = new AppModel();
            Model.Global.CompanyName            = systemSettings["CompanyName"].Value;
            Model.Global.CompanyAcronym         = systemSettings["CompanyAcronym"].Value;
            Model.Global.ApplicationName        = "openXDA";
            Model.Global.ApplicationDescription = "open Meter Information Collection System";
            Model.Global.ApplicationKeywords    = "open source, utility, software, meter, interrogation";
            Model.Global.DateFormat             = systemSettings["DateFormat"].Value;
            Model.Global.TimeFormat             = systemSettings["TimeFormat"].Value;
            Model.Global.DateTimeFormat         = $"{Model.Global.DateFormat} {Model.Global.TimeFormat}";
            Model.Global.BootstrapTheme         = systemSettings["BootstrapTheme"].Value;

            try
            {
                // Attach to default web server events
                WebServer webServer = WebServer.Default;
                webServer.StatusMessage += WebServer_StatusMessage;

                // Define types for Razor pages - self-hosted web service does not use view controllers so
                // we must define configuration types for all paged view model based Razor views here:
                webServer.PagedViewModelTypes.TryAdd("Users.cshtml", new Tuple <Type, Type>(typeof(UserAccount), typeof(SecurityHub)));
                webServer.PagedViewModelTypes.TryAdd("Groups.cshtml", new Tuple <Type, Type>(typeof(SecurityGroup), typeof(SecurityHub)));
                webServer.PagedViewModelTypes.TryAdd("Settings.cshtml", new Tuple <Type, Type>(typeof(Setting), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("Devices.cshtml", new Tuple <Type, Type>(typeof(Meter), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("Stations.cshtml", new Tuple <Type, Type>(typeof(MeterLocation), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("MeterGroups.cshtml", new Tuple <Type, Type>(typeof(Group), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("GroupMeterView.cshtml", new Tuple <Type, Type>(typeof(GroupMeterView), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("Lines.cshtml", new Tuple <Type, Type>(typeof(LineView), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("MeterLine.cshtml", new Tuple <Type, Type>(typeof(MeterLine), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("Channel.cshtml", new Tuple <Type, Type>(typeof(Channel), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("DashSettings.cshtml", new Tuple <Type, Type>(typeof(DashSettings), typeof(DataHub)));
                webServer.PagedViewModelTypes.TryAdd("AlarmSettings", new Tuple <Type, Type>(typeof(AlarmRangeLimitView), typeof(DataHub)));
                // Initiate pre-compile of base templates
                if (AssemblyInfo.EntryAssembly.Debuggable)
                {
                    RazorEngine <CSharpDebug> .Default.PreCompile(HandleException);

                    RazorEngine <VisualBasicDebug> .Default.PreCompile(HandleException);
                }
                else
                {
                    RazorEngine <CSharp> .Default.PreCompile(HandleException);

                    RazorEngine <VisualBasic> .Default.PreCompile(HandleException);
                }

                // Create new web application hosting environment
                m_webAppHost = WebApp.Start <Startup>(systemSettings["WebHostURL"].Value);
            }
            catch (Exception ex)
            {
                HandleException(new InvalidOperationException($"Failed to initialize web hosting: {ex.Message}", ex));
            }
        }
Ejemplo n.º 6
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            const int RetryDelay = 1000;
            const int SleepTime  = 200;
            const int LoopCount  = RetryDelay / SleepTime;

            ServiceHelperAppender serviceHelperAppender;
            RollingFileAppender   fileAppender;

            // Set current working directory to fix relative paths
            Directory.SetCurrentDirectory(FilePath.GetAbsolutePath(""));

            // Set up logging
            serviceHelperAppender = new ServiceHelperAppender(m_serviceHelper);

            fileAppender = new RollingFileAppender();
            fileAppender.StaticLogFileName            = false;
            fileAppender.AppendToFile                 = true;
            fileAppender.RollingStyle                 = RollingFileAppender.RollingMode.Composite;
            fileAppender.MaxSizeRollBackups           = 10;
            fileAppender.PreserveLogFileNameExtension = true;
            fileAppender.MaximumFileSize              = "1MB";
            fileAppender.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            try
            {
                if (!Directory.Exists("Debug"))
                {
                    Directory.CreateDirectory("Debug");
                }

                fileAppender.File = @"Debug\openXDA.log";
            }
            catch (Exception ex)
            {
                fileAppender.File = "openXDA.log";
                m_serviceHelper.ErrorLogger.Log(ex);
            }

            fileAppender.ActivateOptions();
            BasicConfigurator.Configure(serviceHelperAppender, fileAppender);

            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.AddScheduledProcess(ReloadConfigurationHandler, "ReloadConfiguration", "0 0 * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadSystemSettings", "Reloads system settings from the database", ReloadSystemSettingsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("EngineStatus", "Displays status information about the XDA engine", EngineStatusHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("TweakFileProcessor", "Modifies the behavior of the file processor at runtime", TweakFileProcessorHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated  += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded   += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.Initialize();

            // Set up the analysis engine
            m_extensibleDisturbanceAnalysisEngine = new ExtensibleDisturbanceAnalysisEngine();

            // Set up separate thread to start the engine
            m_startEngineThread = new Thread(() =>
            {
                while (!TryStartEngine())
                {
                    for (int i = 0; i < LoopCount; i++)
                    {
                        if (m_serviceStopping)
                        {
                            return;
                        }

                        Thread.Sleep(SleepTime);
                    }
                }
            });

            m_startEngineThread.Start();
        }
Ejemplo n.º 7
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            ServiceHelperAppender serviceHelperAppender;
            RollingFileAppender fileAppender;

            // Set current working directory to fix relative paths
            Directory.SetCurrentDirectory(FilePath.GetAbsolutePath(""));

            // Set up logging
            serviceHelperAppender = new ServiceHelperAppender(m_serviceHelper);

            fileAppender = new RollingFileAppender();
            fileAppender.StaticLogFileName = false;
            fileAppender.AppendToFile = true;
            fileAppender.RollingStyle = RollingFileAppender.RollingMode.Composite;
            fileAppender.MaxSizeRollBackups = 10;
            fileAppender.PreserveLogFileNameExtension = true;
            fileAppender.MaximumFileSize = "1MB";
            fileAppender.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            try
            {
                if (!Directory.Exists("Debug"))
                    Directory.CreateDirectory("Debug");

                fileAppender.File = @"Debug\openXDA.log";
            }
            catch (Exception ex)
            {
                fileAppender.File = "openXDA.log";
                m_serviceHelper.ErrorLogger.Log(ex);
            }

            fileAppender.ActivateOptions();
            BasicConfigurator.Configure(serviceHelperAppender, fileAppender);

            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.AddScheduledProcess(ReloadConfigurationHandler, "ReloadConfiguration", "0 0 * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadSystemSettings", "Reloads system settings from the database", ReloadSystemSettingsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("EngineStatus", "Displays status information about the XDA engine", EngineStatusHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("TweakFileProcessor", "Modifies the behavior of the file processor at runtime", TweakFileProcessorHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.Initialize();

            // Set up the analysis engine
            m_extensibleDisturbanceAnalysisEngine = new ExtensibleDisturbanceAnalysisEngine();

            // Set up separate thread to start the engine
            m_startEngineThread = new Thread(() =>
            {
                const int RetryDelay = 1000;
                const int SleepTime = 200;
                const int LoopCount = RetryDelay / SleepTime;

                bool engineStarted = false;
                bool webUIStarted = false;

                while (true)
                {
                    engineStarted = engineStarted || TryStartEngine();
                    webUIStarted = webUIStarted || TryStartWebUI();

                    if (engineStarted && webUIStarted)
                        break;

                    for (int i = 0; i < LoopCount; i++)
                    {
                        if (m_serviceStopping)
                            return;

                        Thread.Sleep(SleepTime);
                    }
                }
            });

            m_startEngineThread.Start();
        }
Ejemplo n.º 8
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            ServiceHelperAppender serviceHelperAppender;
            RollingFileAppender fileAppender;
            ServiceProcess process;

            // Set current working directory to fix relative paths
            Directory.SetCurrentDirectory(FilePath.GetAbsolutePath(""));

            // Set up logging
            serviceHelperAppender = new ServiceHelperAppender(m_serviceHelper);

            fileAppender = new RollingFileAppender();
            fileAppender.StaticLogFileName = false;
            fileAppender.AppendToFile = true;
            fileAppender.RollingStyle = RollingFileAppender.RollingMode.Composite;
            fileAppender.MaxSizeRollBackups = 10;
            fileAppender.PreserveLogFileNameExtension = true;
            fileAppender.MaximumFileSize = "1MB";
            fileAppender.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            try
            {
                if (!Directory.Exists("Debug"))
                    Directory.CreateDirectory("Debug");

                fileAppender.File = @"Debug\openEAS.log";
            }
            catch (Exception ex)
            {
                fileAppender.File = "openEAS.log";
                m_serviceHelper.ErrorLogger.Log(ex);
            }

            fileAppender.ActivateOptions();
            BasicConfigurator.Configure(serviceHelperAppender, fileAppender);

            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ProcessLatestData, "ProcessLatestData", "* * * * *");
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadSystemSettings", "Reloads system settings from the database", ReloadSystemSettingsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.Initialize();

            // Set up the analysis engine
            m_extensibleDisturbanceAnalysisEngine = new SandBoxEngine();

            // Process latest data at startup
            process = m_serviceHelper.FindProcess("ProcessLatestData");

            if ((object)process != null)
                process.Start();
        }
Ejemplo n.º 9
0
        private void ServiceHelper_ServiceStarted(object sender, EventArgs e)
        {
            ServiceHelperAppender serviceHelperAppender;
            RollingFileAppender   debugLogAppender;

            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;

            // Set current working directory to fix relative paths
            Directory.SetCurrentDirectory(FilePath.GetAbsolutePath(""));

            // Set up logging
            serviceHelperAppender = new ServiceHelperAppender(m_serviceHelper);

            debugLogAppender = new RollingFileAppender();
            debugLogAppender.StaticLogFileName            = false;
            debugLogAppender.AppendToFile                 = true;
            debugLogAppender.RollingStyle                 = RollingFileAppender.RollingMode.Composite;
            debugLogAppender.MaxSizeRollBackups           = 10;
            debugLogAppender.PreserveLogFileNameExtension = true;
            debugLogAppender.MaximumFileSize              = "1MB";
            debugLogAppender.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            try
            {
                if (!Directory.Exists("Debug"))
                {
                    Directory.CreateDirectory("Debug");
                }

                debugLogAppender.File = @"Debug\MiMD.log";
            }
            catch (Exception ex)
            {
                debugLogAppender.File = "MiMD.log";
                m_serviceHelper.ErrorLogger.Log(ex);
            }

            debugLogAppender.ActivateOptions();
            BasicConfigurator.Configure(serviceHelperAppender, debugLogAppender);

            // Set up heartbeat and client request handlers
            m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *");
            m_serviceHelper.AddScheduledProcess(ReloadConfigurationHandler, "ReloadConfiguration", "0 0 * * *");

            string emailSchedule;
            List <DBCleanupTask> cleanupSchedules;

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                emailSchedule = connection.ExecuteScalar <string>("SELECT Value FROM Setting WHERE Name = 'Email.SummaryEmailSchedule'") ?? "0 7 * * *";
                try
                {
                    cleanupSchedules = (new TableOperations <DBCleanupTask>(connection)).QueryRecords().ToList();
                }
                catch (Exception ex) {
                    cleanupSchedules = new List <DBCleanupTask>();
                }
            }

            m_serviceHelper.AddScheduledProcess(DailyEmailHandler, "DailyEmail", emailSchedule);
            cleanupSchedules.ForEach(task => m_serviceHelper.AddScheduledProcess(DBCleanUpHandler, $"Cleanup-{task.ID}", new object[] { task }, task.Schedule));

            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadSystemSettings", "Reloads system settings from the database", ReloadSystemSettingsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("EngineStatus", "Displays status information about the XDA engine", EngineStatusHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("MsgServiceMonitors", "Sends a message to all service monitors", MsgServiceMonitorsRequestHandler));
            m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("TweakFileProcessor", "Modifies the behavior of the file processor at runtime", TweakFileProcessorHandler));

            m_serviceHelper.UpdatedStatus   += UpdatedStatusHandler;
            m_serviceHelper.LoggedException += LoggedExceptionHandler;

            // Set up adapter loader to load service monitors
            m_serviceMonitors = new ServiceMonitors();
            m_serviceMonitors.AdapterCreated       += ServiceMonitors_AdapterCreated;
            m_serviceMonitors.AdapterLoaded        += ServiceMonitors_AdapterLoaded;
            m_serviceMonitors.AdapterUnloaded      += ServiceMonitors_AdapterUnloaded;
            m_serviceMonitors.AdapterLoadException += (obj, args) => HandleException(args.Argument);
            m_serviceMonitors.Initialize();

            string systemSettingsConnectionString = LoadSystemSettings();

            // Set up the system center engine
            m_miMDEngine = new MiMDEngine();

            // Set up separate thread to start the engine
            m_startEngineThread = new Thread(() =>
            {
                const int RetryDelay = 1000;
                const int SleepTime  = 200;
                const int LoopCount  = RetryDelay / SleepTime;

                bool engineStarted = false;
                bool webUIStarted  = false;

                while (true)
                {
                    engineStarted = engineStarted || TryStartEngine();
                    webUIStarted  = webUIStarted || TryStartWebUI();

                    if (engineStarted && webUIStarted)
                    {
                        break;
                    }

                    for (int i = 0; i < LoopCount; i++)
                    {
                        if (m_serviceStopping)
                        {
                            return;
                        }

                        Thread.Sleep(SleepTime);
                    }
                }
            });

            m_startEngineThread.Start();
        }