public static SimulationCore.Environment.Configuration ConfigurationConverter(ResultContext resultCtx, int id) { var validCommands = Commands.GetAllValidCommands; var config = new SimulationCore.Environment.Configuration(); ICommand command = validCommands.Single(x => x.ArgLong == "SimulationId"); command.Action(config, id.ToString()); var configurationItems = resultCtx.ConfigurationRelations .Include(x => x.ChildItem) .Where(x => x.Id == id).Select(x => x.ChildItem).ToList(); if (id != 1) { configurationItems = AddDefaultItems(resultCtx, configurationItems); } foreach (var item in configurationItems) { if (!IsArg(validCommands: validCommands, argument: "--" + item.Property, command: ref command)) { throw new InvalidOperationException("No command found that is equal to:" + item.Property); } //else command.Action(arg1: config, arg2: item.PropertyValue); } return(config); }
public static void HandleInput(string input) { input = input.ToLower(); ICommand activeCommand = null; _commands.TryGetValue(input, out activeCommand); if (activeCommand != null) { activeCommand?.Action(); history.Add(activeCommand); } else { Console.WriteLine(input + " is not recognised"); } }
/// <summary> /// Runs the command with args. /// </summary> /// <param name="commandString">The entire command to run as a string.</param> private void RunCommand(string commandString) { string label = commandString; List <string> args = new List <string>(); //Remember the last command if (!commandString.Equals(string.Empty)) { previousCommandText = commandString; } //Parse the command label and args if (commandString.IndexOf(' ') > -1) { label = commandString.Substring(0, commandString.IndexOf(' ')); args.AddRange(commandString.Substring(commandString.IndexOf(' ') + 1).Split(' ')); //Check if the last arg is empty if (args[args.Count - 1].Equals(string.Empty)) { //Remove the last arg if it is empty args.RemoveAt(args.Count - 1); //print("last arg is empty"); } } //Find the suggestion text suggestionBuilder.Clear(); ICommand command = FindCommand(label); //Run the command if one was found if (command != null) { command.Action(args.ToArray()); } else { Log($"<color=red>Unknown command</color> <color=#FF6666>\"{label}\"</color>"); } //Clear the input field inputField.text = string.Empty; }
public virtual void Enter() { var monsterFactory = MonsterFactory.Instance(); ICommand action = null; while (true) { display(); var choice = UserInterface.GetInput("Choose an action: "); action = Commands.FirstOrDefault(c => c.Keys.ToLower() == choice.ToLower()); if (action == null) { Feedback = "Invalid Choice!"; } else { action.Action(); } } }
public virtual void Enter(IPlayer player) { this.player = player; ICommand action = null; while (true) { display(); var choice = UserInterface.GetInput("Choose an action: "); action = Commands.FirstOrDefault(c => c.Keys.ToLower() == choice.ToLower()); if (action == null) { Feedback = "Invalid Choice!"; } else { action.Action(); } } }
public virtual void Enter() { ICommand action = null; string error = ""; while (action == null) { display(error); var choice = Console.ReadLine(); action = Commands.FirstOrDefault(c => c.Keys == choice); if (action == null) { error = "Invalid Choice!"; } else { action.Action(); } } }
/// <summary> /// Processes an input string. /// </summary> /// <param name="input">Input to process.</param> /// <returns>The command handler or operation response.</returns> public static string Process(string input) { if (input == new string(Key)) { return(new string(KeyResponse)); } var split = input.Split(' '); if (split.Length == 0) { throw new InvalidArgumentException("Invalid command"); } var command = split[0]; var args = split.Skip(1).ToList(); ICommand cmd = Commands.Find(x => x.CommandName() == command); if (cmd != null) { if (cmd.ArgCount() != -1 && args.Count != cmd.ArgCount()) { return("Usage: " + cmd.Usage()); } return(cmd.Action(args)); } if (LambdaCommands.ContainsKey(command)) { return(LambdaCommands[command](args)); } throw new ProcessingException("Unknown operation or invalid arguments"); }
public object ExecuteCommand() { return(_command.Action()); }
public void Excute() { _command.Action(); }
/// <summary> /// Execute command by its type. /// </summary> /// <param name="command">Command type.</param> /// <param name="commandLineText">Line to parse</param> /// <param name="console">Console parameter.</param> public static void ExecuteCommand(ICommand command, string commandLineText, CyberConsole console) { command.Action(commandLineText, console); console.InsertText(command.PrintInfo()); }
public void Calc() { ICommand command = CommandFactory.Make("1"); command.Action(); }