コード例 #1
0
        private static void RunAsConsole()
        {
            Console.WriteLine("Welcome to FireSinging!");

            Helper.CheckCanSetConsoleColor();

            Console.WriteLine("Initializing...");

            IBootstrap bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Helper.SetConsoleColor(ConsoleColor.Red);

                Console.WriteLine("Failed to initialize FireSinging! Please check error log for more information!");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Starting...");

                StartResult startResult = bootstrap.Start();

                Console.WriteLine("-------------------------------------------------------------------");

                foreach (IWorkItem workItem in bootstrap.AppServers)
                {
                    if (workItem.State == ServerState.Running)
                    {
                        Helper.SetConsoleColor(ConsoleColor.Green);

                        Console.WriteLine("- {0} has been started", (object)workItem.Name);
                    }
                    else
                    {
                        Helper.SetConsoleColor(ConsoleColor.Red);

                        Console.WriteLine("- {0} failed to start", (object)workItem.Name);
                    }
                }

                Console.ResetColor();
                Console.WriteLine("-------------------------------------------------------------------");

                switch (startResult)
                {
                case StartResult.None:

                    Helper.SetConsoleColor(ConsoleColor.Red);

                    Console.WriteLine("FireSinging could not be started. No server is configured, please check you configuration!");
                    Console.ReadKey();

                    return;

                case StartResult.Success:

                    Console.WriteLine("FireSinging has been started!");

                    break;

                case StartResult.PartialSuccess:

                    Helper.SetConsoleColor(ConsoleColor.Red);

                    Console.WriteLine("FireSinging could not be started. Some server instances were started successfully, but the others failed! Please check error log for more information!");
                    Console.ReadKey();

                    return;

                case StartResult.Failed:

                    Helper.SetConsoleColor(ConsoleColor.Red);

                    Console.WriteLine("FireSinging could not be started. Please check error log for more information!");
                    Console.ReadKey();

                    return;
                }

                Console.ResetColor();
                Console.WriteLine("Enter key 'quit' to stop FireSinging.");

                Program.RegisterCommands();
                Program.ReadConsoleCommand(bootstrap);

                bootstrap.Stop();

                Console.WriteLine("FireSinging has been stopped!");
            }
        }