Ejemplo n.º 1
0
        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();
        }