public void RegisterCommand(ICommand command) { if (command == null) { throw new ArgumentException("command argument cannot be null"); } if (Commands.ContainsKey(command.GetName())) { LOGGER.ErrorFormat("Can't register command {0} because command with this name already registered!", command.GetName()); return; } Commands.TryAdd(command.GetName(), command); }
public void TestUndoCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("undo"); Assert.AreEqual("Undo", command.GetName()); }
public void TestRestartCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("restart"); Assert.AreEqual("Restart", command.GetName()); }
public void TestScoreCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("top"); Assert.AreEqual("Score", command.GetName()); }
public void TestMoveRightCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("r"); Assert.AreEqual("Move Right", command.GetName()); }
private void ProccessCommand(string commandName) { this.commandContext = new CommandContext(this.playField, this.renderer, this.memory, this.ladder, this.player); string inputToLower = commandName.ToLower(); ICommand command = this.commandFactory.CreateCommand(inputToLower); command.Execute(this.commandContext); this.logger.Log("Executed command - " + command.GetName()); }
public void Print(ICommand command) { con.ForegroundColor = ConsoleColor.White; con.Write("* "); con.ForegroundColor = ConsoleColor.Cyan; con.Write($"{command.GetName()} "); con.ForegroundColor = ConsoleColor.Yellow; con.WriteLine(command.Syntax); con.ForegroundColor = ConsoleColor.Gray; con.WriteLine($" {command.Description}\n"); con.ResetColor(); }
public void Execute(ref IContract channel) { switch (_command.GetName()) { case "help": _model = channel.GetHelp(); OutputResult(_model.Result); for (var i = 0; i < 14; i++) { if (i % 2 == 0) { _output.Execute(_model.Results[i], ConsoleColor.Gray); } else { _output.Execute(_model.Results[i]); } } return; case "add": _model = channel.AddComposition(_model); break; case "rm": _model = channel.RemoveComposition(_model); break; case "search": _model = channel.SearchComposition(_model); break; case "ls c": _model = channel.GetCompositionsList(_model); break; case "ls p": _model = channel.GetPlaylistsList(); break; } OutputResult(_model.Result); _output.Execute(_model.ToString()); }
public bool Execute() { var input = new Input(); var output = new Output(); output.Execute("Input command: "); var commandName = input.Execute(); var retrn = commands.Any(x => x.GetName() == commandName); if (retrn) { command = commands.FirstOrDefault(x => x.GetName() == commandName); if (commandName == "exit") { command.Execute(Environment.CurrentDirectory, out _result); } else { var requestCommand = new RequestCommand(command.GetName()); _result = requestCommand.Serialize(); var result = command.ReadArgs(); if (command.GetArgsCount() == 0) { } else if (result == null) { retrn = false; } else { _result += "\n" + result; } } } return(retrn); }
public void Print(ICommand command) { con.WriteLine($"* {command.GetName()} {command.Syntax}"); con.WriteLine($" {command.Description}\n"); }