Пример #1
0
        /// <summary>Execute WheelMUD program via our own console-mode server harness.</summary>
        public static void RunWithConsoleHarness()
        {
            string logFileName = "Log_" + DateTime.Now.ToShortDateString() + ".txt";

            logFileName = logFileName.Replace('\\', '_').Replace('/', '_');
            var consoleDisplay = new ConsoleUpdater();
            var textLogWriter  = new TextLogUpdater(logFileName);
            var display        = new MultiUpdater(consoleDisplay, textLogWriter);

            var app = Application.Instance;

            app.SubscribeToSystem(display);
            app.Start();

            // TODO: GitHub #58: Reflect implementers of IServerHarnessCommand to keep this automatically up to date
            IServerHarnessCommand[] commandObjects =
            {
                new HelpCommand(), new UpdateActionsCommand(), new RunTestsCommand(), new DebugExploreDocumentsCommand()
            };
            var commands = new Dictionary <string, IServerHarnessCommand>();

            foreach (var cmdObj in commandObjects)
            {
                foreach (var name in cmdObj.Names)
                {
                    commands[name] = cmdObj;
                }
            }

            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                var words = input.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if ("shutdown".Equals(words[0], StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                var command = FindCommand(commands, words[0]);
                if (command != null)
                {
                    command.Execute(app, display, words);
                }
                else
                {
                    display.Notify(string.Format("> Command not recognized: {0}", input));
                }
            }

            app.Stop();

            display.Notify("Press enter to quit...");
            Console.ReadLine();
        }
Пример #2
0
        /// <summary>Execute WheelMUD program via our own console-mode server harness.</summary>
        public static void RunWithConsoleHarness()
        {
            string logFileName = "Log_" + DateTime.Now.ToShortDateString() + ".txt";

            logFileName = logFileName.Replace('\\', '_').Replace('/', '_');
            var consoleDisplay = new ConsoleUpdater();
            var textLogWriter  = new TextLogUpdater(logFileName);
            var display        = new MultiUpdater(consoleDisplay, textLogWriter);

            var app = Application.Instance;

            app.SubscribeToSystem(display);
            app.Start();

            bool done        = false;
            var  exitCommand = new DynamicServerHarnessCommand(() => done = true, new string[] { "SHUTDOWN", "EXIT" }, "Shuts down the game instance and server harness.");

            ServerHarnessCommands.Instance.DynamicCommands.Add(exitCommand);

            var commands = new Dictionary <string, IServerHarnessCommand>();

            foreach (var cmdObj in ServerHarnessCommands.Instance.AllCommands)
            {
                foreach (var name in cmdObj.Names)
                {
                    commands[name] = cmdObj;
                }
            }

            while (!done)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                var words   = input.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                var command = FindCommand(commands, words[0]);
                if (command != null)
                {
                    command.Execute(app, display, words);
                }
                else
                {
                    display.Notify(string.Format("> Command not recognized: {0}", input));
                }
            }

            app.Stop();
        }