public void When_registering_two_commands_with_the_same_name() { //Arrange var console = new ClientConsole(new ConsoleConfiguration { RememberStartPosition = false }); var command = new RootCommand(console); var cmd1 = new Mock <ICommand>(MockBehavior.Strict); cmd1.Setup(x => x.Name).Returns("A"); cmd1.Setup(x => x.Names).Returns(new string[] {}); var cmd2 = new Mock <ICommand>(MockBehavior.Strict); cmd2.Setup(x => x.Name).Returns("A"); cmd2.Setup(x => x.Names).Returns(new[] { "A" }); command.RegisterCommand(cmd1.Object); Exception exceptionThrown = null; //Act try { command.RegisterCommand(cmd2.Object); } catch (Exception exception) { exceptionThrown = exception; } //Assert Assert.That(exceptionThrown, Is.Not.Null); Assert.That(exceptionThrown.GetType(), Is.EqualTo(typeof(CommandAlreadyRegisteredException))); }
public void SetUp() { this.simple = new TestAction("Simple"); this.containerCommand = new TestContainerCommand(); this.command = new RootCommand(new TestConsole(new FakeConsoleManager())); this.commandEngine = new CommandEngine(this.command); command.RegisterCommand(this.simple); command.RegisterCommand(this.containerCommand); }
public static void Main(string[] args) { var rootCommand = new RootCommand(new ClientConsole()); rootCommand.RegisterCommand(new ExampleCommands()); rootCommand.RegisterCommand(new TestCommands()); rootCommand.RegisterCommand(new PdfCommand()); var engine = new CommandEngine(rootCommand); engine.Run(args); }
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); } }
private static void Main(string[] args) { System.Console.Title = Constants.ServiceName + " Management Console"; var compositeRoot = new CompositeRoot(); var command = new RootCommand(compositeRoot.ClientConsole); command.RegisterCommand(new ConfigCommands(compositeRoot)); command.RegisterCommand(new ServiceCommands(compositeRoot)); command.RegisterCommand(new CounterCommands(compositeRoot)); command.RegisterCommand(new PublishCommands(compositeRoot)); command.RegisterCommand(new SenderCommands(compositeRoot)); new CommandEngine(command).Run(args); }
static void Setup(RootCommand rootCmd, ARealmReversed realm) { rootCmd.RegisterCommand(new Commands.LanguageCommand(realm)); rootCmd.RegisterCommand(new Commands.RawCommand(realm)); rootCmd.RegisterCommand(new Commands.ImageCommand(realm)); rootCmd.RegisterCommand(new Commands.UiCommand(realm)); rootCmd.RegisterCommand(new Commands.MapCommand(realm)); rootCmd.RegisterCommand(new Commands.ExdCommand(realm)); rootCmd.RegisterCommand(new Commands.AllExdCommand(realm)); rootCmd.RegisterCommand(new Commands.RawExdCommand(realm)); rootCmd.RegisterCommand(new Commands.BgmCommand(realm)); }
static void Main(string[] args) { var command = new RootCommand(new VoiceConsole()); command.RegisterCommand(new SomeContainerCommand()); new CommandEngine(command).Run(args); }
public static void Main(string[] args) { //LoadedAssembly(); if (args.Length == 0) { SwitchDomainForRazorEngine(); } var console = new ClientConsole(); var command = new RootCommand(console); var razorcmd = new RazorCommand(); command.RegisterCommand(razorcmd); command.RegisterCommand(new TestCaseCommand(razorcmd)); var commandEngine = new CommandEngine(command); commandEngine.Run(args); }
static void Setup(RootCommand rootCmd, ARealmReversed realm) { var assembly = typeof(Program).Assembly; foreach (var t in assembly.GetTypes().Where(t => typeof(ActionCommandBase).IsAssignableFrom(t))) { var cons = t.GetConstructor(new[] { typeof(ARealmReversed) }); rootCmd.RegisterCommand((ActionCommandBase)cons.Invoke(new[] { realm })); } }
private static void Main(string[] args) { _compositeRoot = new CompositeRoot(); var clientConsole = _compositeRoot.ClientConsole; var command = new RootCommand(clientConsole); System.Console.Title = Constants.ServiceName + " Management Console"; CounterBusiness.ChangedCurrentCultureEvent += CounterBusiness_ChangedCurrentCultureEvent; clientConsole.KeyReadEvent += ClientConsole_KeyReadEvent; command.RegisterCommand(new ConfigCommands(_compositeRoot)); command.RegisterCommand(new ServiceCommands(_compositeRoot)); command.RegisterCommand(new CounterCommands(_compositeRoot)); command.RegisterCommand(new PublishCommands(_compositeRoot)); command.RegisterCommand(new SenderCommands(_compositeRoot)); new CommandEngine(command).Run(args); }
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); } }
public void Initialize() { RootCommand Root = new RootCommand(Log.Console); Root.RegisterCommand(new GoToRoomCommand(Map)); Root.RegisterCommand(new RoomInfoCommand(Map)); Root.RegisterCommand(new ListRoomsCommand(Map)); Root.RegisterCommand(new SetViewCommand(MapRenderer)); Root.RegisterCommand(new OutlineCommand(MapRenderer)); Root.RegisterCommand(new DisplayCommand(GameController)); Root.RegisterCommand(new DisableCommand(MapRenderer)); CommandEngine Engine = new CommandEngine(Root); Engine.Run(new string[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); } }
private static void Main(string[] args) { var console = new ClientConsole(); Effort.Provider.EffortProviderConfiguration.RegisterProvider(); var connection = DbConnectionFactory.CreateTransient(); using (var context = new SampleDb(connection, "geo")) { console.WriteLine("Welcome to EF Test Console, type help to check available commands", OutputLevel.Information, null); context.Products.AddRange(new[] { new Product { Name = "CocaCola" }, new Product { Name = "Pepsi" }, new Product { Name = "Starbucks" }, new Product { Name = "Donut" } }); context.SaveChanges(); var ct = new System.Threading.CancellationToken(); Task.Run(() => { SingletonSampleJob.Instance.RunBackgroundWork(ct); }, ct); var command = new RootCommand(console); command.RegisterCommand(new FillOrderCommand(context)); command.RegisterCommand(new EditOrder(context)); command.RegisterCommand(new QueryAuditTrail(context)); command.RegisterCommand(new QueryOrder(context)); command.RegisterCommand(new ToggleController(context)); command.RegisterCommand(new JobController(context)); var commandEngine = new CommandEngine(command); commandEngine.Run(args); } }
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(); } }
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(); } }