public void With_no_args()
        {
            Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100);

            Assert.False(simple.WasRun);
            Assert.False(containerCommand.inner.WasRun);
        }
        public void Should_work_with_engines()
        {
            //Arrange
            var consoleManager1 = new FakeConsoleManager();
            var consoleManager2 = new FakeConsoleManager();
            var console1        = new TestConsole(consoleManager1);
            var console2        = new TestConsole(consoleManager2);
            var command1        = new RootCommand(console1);
            var command2        = new RootCommand(console2);
            var commandEngine1  = new CommandEngine(command1);
            var commandEngine2  = new CommandEngine(command2);

            Task.Run(() => { commandEngine1.Start(new string[] { }); }).Wait(100);
            Task.Run(() => { commandEngine2.Start(new string[] { }); }).Wait(100);
            console2.Output(new WriteEventArgs(new string('C', console1.BufferWidth * (console1.BufferHeight - 1))));
            console1.Output(new WriteEventArgs(new string('A', console1.BufferWidth * (console1.BufferHeight - 1))));

            //Act
            console1.Output(new WriteEventArgs("B"));

            //Assert
            Assert.That(consoleManager1.LineOutput[0], Is.EqualTo(new string('A', consoleManager1.BufferWidth)));
            Assert.That(consoleManager1.LineOutput[consoleManager1.BufferHeight - 3], Is.EqualTo(new string('A', consoleManager1.BufferWidth)));
            Assert.That(consoleManager1.LineOutput[consoleManager1.BufferHeight - 2], Is.EqualTo("B"));
            //Assert.That(consoleManager1.LineOutput[consoleManager1.BufferHeight - 1], Is.EqualTo("> "));
            //Assert.That(consoleManager1.CursorTop, Is.EqualTo(consoleManager1.BufferHeight - 1));
            //Assert.That(consoleManager1.CursorLeft, Is.EqualTo(2));

            Assert.That(consoleManager2.LineOutput[0], Is.EqualTo(new string('C', consoleManager1.BufferWidth)));
            Assert.That(consoleManager2.LineOutput[consoleManager1.BufferHeight - 3], Is.EqualTo(new string('C', consoleManager1.BufferWidth)));
            //Assert.That(consoleManager2.LineOutput[0], Is.EqualTo("> "));
        }
Esempio n. 3
0
 private static void Main(string[] args)
 {
     using (var console = new ClientConsole())
     {
         var command       = new RootCommand(console);
         var commandEngine = new CommandEngine(command);
         commandEngine.Start(args);
     }
 }
Esempio n. 4
0
        private Program(string[] args)
        {
            using (var console = new ClientConsole())
            {
                var rootCommand = new RootCommand(console);
                rootCommand.RegisterCommand(new StartGameConsoleCommand(_game));
                rootCommand.RegisterCommand(new GetBoardCommand(_game));
                rootCommand.RegisterCommand(new MoveCommand(_game));

                var engine = new CommandEngine(rootCommand);
                engine.Start(args);
            }
        }
Esempio n. 5
0
        public void Should_prompt_cursor()
        {
            //Arrange
            var consoleManager = new FakeConsoleManager();
            var console        = new TestConsole(consoleManager);
            var command        = new RootCommand(console);
            var commandEngine  = new CommandEngine(command);

            //Act
            Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100);

            //Assert
            //TODO: Fix on build server! Assert.That(consoleManager.LineOutput[0], Is.EqualTo("> "));
            //TODO: Fix on build server! Assert.That(consoleManager.CursorTop, Is.EqualTo(0));
            //TODO: Fix on build server! Assert.That(consoleManager.CursorLeft, Is.EqualTo(2));
        }
Esempio n. 6
0
        private static void Main(string[] args)
        {
            var config = new ConsoleConfiguration {
                SplashScreen = "Best Bank ever"
            };

            using (var console = new ClientConsole(config))
            {
                var rootCommand = new RootCommand(console);

                rootCommand.RegisterCommand(Container.GetInstance <Kontener.InterfejsBanku>());

                var commandEngine = new CommandEngine(rootCommand);

                commandEngine.Start(args);
            }
        }
Esempio n. 7
0
        public void Should_prompt_cursor_after_full_line_output()
        {
            //Arrange
            var consoleManager = new FakeConsoleManager();
            var console        = new TestConsole(consoleManager);
            var command        = new RootCommand(console);
            var commandEngine  = new CommandEngine(command);

            Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100);

            //Act
            console.Output(new WriteEventArgs(new string('A', console.BufferWidth)));

            //Assert
            Assert.That(consoleManager.LineOutput[0], Is.EqualTo(new string('A', console.BufferWidth)));
            //TODO: Fix on build server! Assert.That(consoleManager.LineOutput[1], Is.EqualTo("> "));
            //TODO: Fix on build server! Assert.That(consoleManager.CursorTop, Is.EqualTo(1));
            //TODO: Fix on build server! Assert.That(consoleManager.CursorLeft, Is.EqualTo(2));
        }
Esempio n. 8
0
        private static void Main(string[] args)
        {
            using (var console = new ClientConsole())
            {
                var connection = new ExampleContext(console).Connection;
                var container  = InjectionHelper.GetIocContainer(connection);

                var rootCommand = new RootCommand(console, new CommandResolver(type => (ICommand)container.Resolve(type)));
                rootCommand.RegisterCommand <ConnectionConsoleCommands>();
                rootCommand.RegisterCommand <ConfigurationConsoleCommands>();
                rootCommand.RegisterCommand <TimeConsoleCommands>();
                rootCommand.RegisterCommand <SimulatorConsoleCommands>();
                rootCommand.RegisterCommand <LightConsoleCommand>();
                rootCommand.RegisterCommand <TextConsoleCommand>();
                rootCommand.RegisterCommand <BeepConsoleCommand>();
                rootCommand.RegisterCommand <RawDataConsoleCommands>();

                var engine = new CommandEngine(rootCommand);
                engine.Start(args);
            }
        }
Esempio n. 9
0
        public void Should_a_short_string()
        {
            //Arrange
            var consoleManager = new FakeConsoleManager();
            var console        = new TestConsole(consoleManager);
            var command        = new RootCommand(console);
            var commandEngine  = new CommandEngine(command);

            Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100);
            console.Output(new WriteEventArgs(new string('A', console.BufferWidth * (console.BufferHeight - 1))));

            //Act
            console.Output(new WriteEventArgs("B"));

            //Assert
            Assert.That(consoleManager.LineOutput[0], Is.EqualTo(new string('A', consoleManager.BufferWidth)));
            Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 3], Is.EqualTo(new string('A', consoleManager.BufferWidth)));
            Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 2], Is.EqualTo("B"));
            //TODO: Fix on build server! Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 1], Is.EqualTo("> "));
            //TODO: Fix on build server! Assert.That(consoleManager.CursorTop, Is.EqualTo(consoleManager.BufferHeight - 1));
            //TODO: Fix on build server! Assert.That(consoleManager.CursorLeft, Is.EqualTo(2));
        }
Esempio n. 10
0
        public void Should_keep_buffer_after_line_output()
        {
            //Arrange
            var inputEngine = new Mock <IKeyInputEngine>(MockBehavior.Strict);

            inputEngine.Setup(x => x.ReadKey(It.IsAny <CancellationToken>())).Returns(new ConsoleKeyInfo('A', ConsoleKey.A, false, false, false));
            var consoleManager = new FakeConsoleManager(inputEngine.Object);
            var console        = new TestConsole(consoleManager);
            var command        = new RootCommand(console);
            var commandEngine  = new CommandEngine(command);

            Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100);

            //Act
            console.Output(new WriteEventArgs("A"));

            //Assert
            Assert.That(consoleManager.LineOutput[0], Is.EqualTo("A"));
            Assert.That(consoleManager.LineOutput[1], Is.EqualTo($"{Constants.Prompt}A"));
            Assert.That(consoleManager.CursorTop, Is.EqualTo(1));
            Assert.That(consoleManager.CursorLeft, Is.EqualTo(5));
        }
Esempio n. 11
0
 static void Main(string[] args)
 {
     CommandEngine.Start();
 }
Esempio n. 12
0
        private static void Main(string[] args)
        {
            IConsole console = null;

            try
            {
                //Part 1. Console.
                using (
                    //NOTE: Enable the type of console you want to use for the sample.
                    console = new ClientConsole(new ConsoleConfiguration {
                    SplashScreen = Constants.SplashScreen
                })
                              //console = new VoiceConsole(new ConsoleConfiguration { SplashScreen = Constants.SplashScreen });
                              //console = new NullConsole();
                              //console = new ActionConsole(e => { System.Diagnostics.Debug.WriteLine(e.Message); });
                              //console = new EventConsole();
                              //console.OutputEvent += (sender, e) => { System.Diagnostics.Debug.WriteLine(e.Message); };
                              //console = new AggregateConsole(new ClientConsole(), new ActionConsole(e => { System.Diagnostics.Debug.WriteLine(e.Message); }));
                    )
                {
                    //Part 2. Commands
                    //NOTE: Creating the command object and registering some commands
                    var command = new RootCommand(console);
                    command.RegisterCommand(new SomeContainerCommand());
                    command.RegisterCommand(new MathContainerCommand());
                    command.RegisterCommand(new StatusCommand());
                    command.RegisterCommand(new SomeContainerWithDisabledSubs());
                    command.RegisterCommand(new OutputContainerCommand());

                    //Part 3. Engine
                    var commandEngine = new CommandEngine(command)
                    {
                        //If you want the console to run some managed background process, they can be created here.
                        TaskRunners = new[]
                        {
                            new TaskRunner((c, a) =>
                            {
                            }),
                            //    //NOTE: You can add a runner that runs until the application exits.
                            //    new TaskRunner(e =>
                            //    {
                            //        var i = 0;
                            //        var intervalSeconds = 15;
                            //        while (!e.IsCancellationRequested)
                            //        {
                            //            if (i % (10 * intervalSeconds) == 0)
                            //            {
                            //                Instance.WriteLine($"First taskrunner is alive in the background. Repporting every {intervalSeconds} seconds.", OutputLevel.Information);
                            //            }
                            //            Thread.Sleep(100);
                            //            i++;
                            //        }
                            //        Instance.WriteLine("First taskrunner is exiting.", OutputLevel.Information);
                            //    }),

                            //    //NOTE: You can add a runner that contains an AutoResetEvent that triggers when the application exits.
                            //    new TaskRunner(e =>
                            //    {
                            //        Instance.WriteLine("Second taskrunner is doing some stuff at startup.", OutputLevel.Information);
                            //        e.WaitOne();
                            //        Instance.WriteLine("Second taskrunner is doing some stuff before the application exits.", OutputLevel.Information);
                            //    }),
                        }
                    };


                    ////Log4Net
                    ////Enable this section to try out the Log4Net appender provided in the nuget package "Tharga.Toolkit.Log4Net".
                    //var logger =  LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

                    ////Logging on different levels
                    //logger.Debug("this Debug msg");
                    //logger.Warn("this Warn msg");
                    //logger.Info("this Info msg");
                    //logger.Error("this Error msg");
                    //logger.Fatal("this Fatal msg");

                    ////Logging exceptions
                    //try
                    //{
                    //    var i = 0;
                    //    var j = 5 / i;
                    //}
                    //catch (Exception ex)
                    //{
                    //    ex.Data.Add("AAA", "AAA1"); //Append data to the exception
                    //    logger.Error("this Error msg,中文测试", ex);
                    //}


                    //NOTE: This part starts the console engine.
                    commandEngine.Start(args);

                    //NOTE: Enable this code if you want to see what happens right before the application closes
                    //Console.WriteLine("Press any key to exit...");
                    //Console.ReadKey();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Fatal Error.");
                console?.OutputError(exception);
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
            finally
            {
                console?.Dispose();
            }
        }
Esempio n. 13
0
        private static void Main(string[] args)
        {
            IConsole console = null;

            try
            {
                //Part 1. Console.
                using (
                    //NOTE: Enable the type of console you want to use for the sample.
                    console = new ClientConsole(new ConsoleConfiguration {
                    SplashScreen = Constants.SplashScreen
                })
                              //console = new VoiceConsole(new ConsoleConfiguration { SplashScreen = Constants.SplashScreen });
                              //console = new NullConsole();
                              //console = new ActionConsole(e => { System.Diagnostics.Debug.WriteLine(e.Message); });
                              //console = new EventConsole();
                              //console.OutputEvent += (sender, e) => { System.Diagnostics.Debug.WriteLine(e.Message); };
                              //console = new AggregateConsole(new ClientConsole(), new ActionConsole(e => { System.Diagnostics.Debug.WriteLine(e.Message); }));
                    )
                {
                    //var environment = new QueryInput(console).QueryParam("Environment", "Dev".AsOption().And("Test").And("Production"));
                    //console.Output(new WriteEventArgs($"Env: {environment}"));

                    //var s1 = new QueryInput(console).QueryParam<string>("Basic string");
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", args);
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", args, new Dictionary<string, string> { { "A", "A" } });
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", new Dictionary<string, string> { { "A", "A" } });
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", Param.Build<string>());
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", Param.Build<string>("n"));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", Param.Build<string>("n").And("x"));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", Param.Build<string>(null).And("x"));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", new Dictionary<string, string> { { "A", "a" } }.And("x"));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", new Dictionary<string, string> { { "A", "a" } }.And(("S", "s")));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", new[] { "A", "B", "X" }.And("yyy"));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", new[] { ("A", "a"), ("B", "b") }.And(("C", "c")));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", ("A", "a").AsOption());
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", "A".And("B"));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));
                    //s1 = new QueryInput(console).QueryParam<string>("S1", ("A", "a").And(("B", "b")));
                    //console.Output(new WriteEventArgs($"s1: {s1}"));

                    //var p1 = new QueryInput(console).QueryParam<bool>("P");
                    //console.Output(new WriteEventArgs($"p1: {p1}"));
                    //p1 = new QueryInput(console).QueryParam<bool>("P1", args);
                    //console.Output(new WriteEventArgs($"p1: {p1}"));
                    //p1 = new QueryInput(console).QueryParam<bool>("P2", args, true.AsOption());
                    //console.Output(new WriteEventArgs($"p1: {p1}"));
                    //p1 = new QueryInput(console).QueryParam<bool>("P3", args, true.AsOption().And(false).And(true).And((false, "nej")));
                    //console.Output(new WriteEventArgs($"p1: {p1}"));
                    //p1 = new QueryInput(console).QueryParam<bool>("P4", args, Param.AsOption<bool>().And(false).And(true));
                    //console.Output(new WriteEventArgs($"p1: {p1}"));
                    //p1 = new QueryInput(console).QueryParam<bool>("P4", args, Param.Build<bool>());
                    //console.Output(new WriteEventArgs($"p1: {p1}"));

                    //var p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, Param.AsOption<bool>().AsNullable().ToArray());
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //p2 = new QueryInput(console).QueryParam<bool?>("P4", aa1);
                    //console.Output(new WriteEventArgs($"p1: {p1}"));
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN2", args, aa1.And((null, "perhaps")));
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, true.AsOption().And(false).AsNullable().And((null, "Any")));
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //var a1 = ((bool?)null, "perhaps").And((false, "no")).And((true, "yes"));
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, a1);
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //var a5 = new[] { ((bool?)null, "Perhaps"), (true, "Ja"), (false, "Nej") };
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, a5);
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //var a4 = ((bool?)null).AsOption().And(false).And(true);
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, a4);
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, Param.Build<bool?>());
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, Param.Build<bool?>("any"));
                    //console.Output(new WriteEventArgs($"p2: {p2}"));
                    //p2 = new QueryInput(console).QueryParam<bool?>("PN1", args, Param.Build<bool?>().And(((bool?)null, "all")));
                    //console.Output(new WriteEventArgs($"p2: {p2}"));

                    //var e1 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum>("E1");
                    //console.Output(new WriteEventArgs($"e1: {e1}"));
                    //e1 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum>("E2", args);
                    //console.Output(new WriteEventArgs($"e1: {e1}"));
                    //e1 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum>("E3", SomeEnumCommand.MyEnum.One.AsOption());
                    //console.Output(new WriteEventArgs($"e1: {e1}"));
                    //e1 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum>("E4", Param.AsOption<SomeEnumCommand.MyEnum>());
                    //console.Output(new WriteEventArgs($"e1: {e1}"));

                    //var e2 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum?>("EN4", Param.AsOption<SomeEnumCommand.MyEnum>().AsNullable().And((null, "ALL")));
                    //console.Output(new WriteEventArgs($"e2: {e2}"));
                    //e2 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum?>("EN4b", new Dictionary<SomeEnumCommand.MyEnum, string>().AsNullable().And((null, "Yee")));
                    //console.Output(new WriteEventArgs($"e2: {e2}"));
                    //e2 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum?>("EN4", Param.Build<SomeEnumCommand.MyEnum?>());
                    //console.Output(new WriteEventArgs($"e2: {e2}"));
                    //e2 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum?>("EN4", Param.Build<SomeEnumCommand.MyEnum?>("any"));
                    //console.Output(new WriteEventArgs($"e2: {e2}"));
                    //e2 = new QueryInput(console).QueryParam<SomeEnumCommand.MyEnum?>("EN4", Param.Build<SomeEnumCommand.MyEnum?>().And((null, "all")));
                    //console.Output(new WriteEventArgs($"e2: {e2}"));

                    console.Output(new WriteEventArgs("Setup complete", OutputLevel.Event));

                    //Part 2. Commands
                    //NOTE: Creating the command object and registering some commands
                    var command = new RootCommand(console);
                    command.RegisterCommand(new SomeContainerCommand());
                    command.RegisterCommand(new SomeMoreCommand());
                    command.RegisterCommand(new MathContainerCommand());
                    command.RegisterCommand(new StatusCommand());
                    command.RegisterCommand(new SomeContainerWithDisabledSubs());
                    command.RegisterCommand(new OutputContainerCommand());
                    command.RegisterCommand(new ReadKeyLoop());
                    command.RegisterCommand(new InfiniteLoop());

                    //Part 3. Engine
                    var commandEngine = new CommandEngine(command)
                    {
                        //If you want the console to run some managed background process, they can be created here.
                        TaskRunners = new[]
                        {
                            new TaskRunner((c, a) =>
                            {
                            }),
                            //    //NOTE: You can add a runner that runs until the application exits.
                            //    new TaskRunner(e =>
                            //    {
                            //        var i = 0;
                            //        var intervalSeconds = 15;
                            //        while (!e.IsCancellationRequested)
                            //        {
                            //            if (i % (10 * intervalSeconds) == 0)
                            //            {
                            //                Instance.WriteLine($"First taskrunner is alive in the background. Repporting every {intervalSeconds} seconds.", OutputLevel.Information);
                            //            }
                            //            Thread.Sleep(100);
                            //            i++;
                            //        }
                            //        Instance.WriteLine("First taskrunner is exiting.", OutputLevel.Information);
                            //    }),

                            //    //NOTE: You can add a runner that contains an AutoResetEvent that triggers when the application exits.
                            //    new TaskRunner(e =>
                            //    {
                            //        Instance.WriteLine("Second taskrunner is doing some stuff at startup.", OutputLevel.Information);
                            //        e.WaitOne();
                            //        Instance.WriteLine("Second taskrunner is doing some stuff before the application exits.", OutputLevel.Information);
                            //    }),
                        }
                    };


                    ////Log4Net
                    ////Enable this section to try out the Log4Net appender provided in the nuget package "Tharga.Toolkit.Log4Net".
                    //var logger =  LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

                    ////Logging on different levels
                    //logger.Debug("this Debug msg");
                    //logger.Warn("this Warn msg");
                    //logger.Info("this Info msg");
                    //logger.Error("this Error msg");
                    //logger.Fatal("this Fatal msg");

                    ////Logging exceptions
                    //try
                    //{
                    //    var i = 0;
                    //    var j = 5 / i;
                    //}
                    //catch (Exception ex)
                    //{
                    //    ex.Data.Add("AAA", "AAA1"); //Append data to the exception
                    //    logger.Error("this Error msg,中文测试", ex);
                    //}


                    //NOTE: This part starts the console engine.
                    commandEngine.Start(args);

                    //NOTE: Enable this code if you want to see what happens right before the application closes
                    //Console.WriteLine("Press any key to exit...");
                    //Console.ReadKey();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Fatal Error.");
                console?.OutputError(exception);
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
            finally
            {
                console?.Dispose();
            }
        }