/// <summary> /// When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts. /// </summary> /// <param name="args">Data passed by the start command.</param> protected override void OnStart(string[] args) { try { _alarmWorkflow = new AlarmWorkflowEngine(); _alarmWorkflow.Start(); _servicesHostManager = new WcfServices.WcfServicesHostManager(_alarmWorkflow); _servicesHostManager.Initialize(); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.ServiceStartError_Message, ex.Message); Logger.Instance.LogException(this, ex); } }
/// <summary> /// Called when the Windows-service is starting. /// </summary> internal void OnStart() { try { // Initialize the settings on every start. SettingsManager.Instance.Invalidate(); SettingsManager.Instance.Initialize(); _alarmWorkflow = new AlarmWorkflowEngine(); _alarmWorkflow.Start(); _servicesHostManager = new WcfServicesHostManager(_alarmWorkflow); _servicesHostManager.Initialize(); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.ServiceStartError_Message, ex.Message); Logger.Instance.LogException(this, ex); } }
static void Main(string[] args) { // Print welcome information :-) Console.WriteLine("********************************************************"); Console.WriteLine("* *"); Console.WriteLine("* AlarmWorkflow Service Console *"); Console.WriteLine("* FOR DEBUGGING ONLY! *"); Console.WriteLine("* *"); Console.WriteLine("* !!! Press ESCAPE to quit safely !!! *"); Console.WriteLine("* *"); Console.WriteLine("********************************************************"); Console.WriteLine(); Console.WriteLine("Starting service..."); // Catch all unhandled exceptions and display them. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // TODO: This is duplex code! Rather create and instance of "AlarmWorkflow.Windows.Service.AlarmWorkflowService" (start and stop it)! // Register logger and listeners Logger.Instance.Initialize(); Logger.Instance.RegisterListener(new RelayLoggingListener(LoggingListener)); Logger.Instance.RegisterListener(new DiagnosticsLoggingListener()); // Then initialize the settings. SettingsManager.Instance.Initialize(); // Create the engine manually using (AlarmWorkflowEngine ac = new AlarmWorkflowEngine()) { // Host the WCF-services, too WcfServicesHostManager shm = new WcfServicesHostManager(ac); try { ac.Start(); shm.Initialize(); } catch (Exception ex) { WriteExceptionInformation(ex); } while (true) { if (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Escape) { break; } } Thread.Sleep(1); } ac.Stop(); shm.Shutdown(); } SettingsManager.Instance.SaveSettings(); Console.WriteLine("Shutting down complete. Press any key to exit."); Console.ReadKey(); }