private void ExecuteCommand(string commandLine) { List <string> args = new List <string>(commandLine.Split(' ')); if (args.Count == 0) { return; } string cmd = args[0].ToLower(); try { IConsoleCommand command = AvailableCommands[cmd]; args.RemoveAt(0); command.Execute(args.ToArray()); } catch (KeyNotFoundException) { Con.ForegroundColor = ConsoleColor.Red; Con.WriteLine("Unknown command: '{0}'", cmd); Con.ResetColor(); } catch (Exception e) { Con.ForegroundColor = ConsoleColor.Red; Con.WriteLine("There was an error while executing the command:\n{0}", e); Con.ResetColor(); } }
/// <summary> /// Processes commands (chat messages starting with /) /// </summary> /// <param name="text">input text</param> private void ProcessCommand(string text) { //Commands are processed locally and then sent to the server to be processed there again. var args = new List <string>(); CommandParsing.ParseArguments(text, args); string commandname = args[0]; //Entity player; //var entMgr = IoCManager.Resolve<IEntityManager>(); //var plrMgr = IoCManager.Resolve<IPlayerManager>(); //player = plrMgr.ControlledEntity; //IoCManager.Resolve<INetworkManager>(). bool forward = true; if (commands.ContainsKey(commandname)) { IConsoleCommand command = commands[commandname]; args.RemoveAt(0); forward = command.Execute(this, args.ToArray()); } else if (!IoCManager.Resolve <INetworkManager>().IsConnected) { AddLine("Unknown command: " + commandname, Color.Red); return; } if (forward) { SendServerConsoleCommand(text); } }
private void ExecuteCommand(IConsoleCommand command, string options) { var message = command.Execute(options); if (message.Length > 0) { View.Success(message); } }
private static void ExecuteCommand(IConsoleCommand cmd) { var startDate = DateTime.UtcNow; var sw = new Stopwatch(); sw.Start(); Console.WriteLine("Command started at: " + DateTime.UtcNow); cmd.Execute(); sw.Stop(); var endDate = DateTime.UtcNow; Console.WriteLine("Command ended at: {0} - Elapsed SW: {1} - Elapsed DT: {2}", endDate, new TimeSpan(sw.ElapsedTicks), endDate - startDate); }
public int Process() { ShowBanner(); try { if (args.Length == 0) { ShowHelp(); return(0); } string commandName = args[0]; if (commands.ContainsKey(commandName)) { IConsoleCommand command = commands[commandName]; List <string> remainingArgs = new List <string>(args); remainingArgs.RemoveAt(0); return(command.Execute(remainingArgs)); } else { throw new ArgumentException( String.Format( CultureInfo.InvariantCulture, "Unknown command: '{0}'", commandName)); } } catch (OptionException ex) { consoleLogger.WriteLine(log, Level.Error, "ERROR: {0}", ex); ShowHelp(); } catch (ArgumentException ex) { consoleLogger.WriteLine(log, Level.Error, "ERROR: {0}", ex); ShowHelp(); } catch (Exception ex) { consoleLogger.WriteLine(log, Level.Fatal, "ERROR: {0}", ex); } return(1); }
public TPMConsole() { //Looks for all ConsoleCommands foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) { if (t.IsAbstract == false && t.IsClass && typeof(IConsoleCommand).IsAssignableFrom(t)) { object[] commandAttrs = t.GetCustomAttributes(typeof(TPMConsoleCommandAttribute), false); if (commandAttrs != null && commandAttrs.Length == 1) { TPMConsoleCommandAttribute attribute = commandAttrs[0] as TPMConsoleCommandAttribute; ConstructorInfo ctor = t.GetConstructor(new Type[] { }); if (ctor != null) { foreach (string cmdName in attribute.CmdNames) { if (_commands.ContainsKey(cmdName) == false) { _commands.Add(cmdName, (IConsoleCommand)ctor.Invoke(new object[] { })); } } } } foreach (IConsoleCommand cmd in _commands.Values) { cmd.Initialize(this); } object[] startupAttrs = t.GetCustomAttributes(typeof(TPMConsoleStartupCommand), false); if (startupAttrs != null && startupAttrs.Length == 1) { ConstructorInfo ctor = t.GetConstructor(new Type[] { }); if (ctor != null) { IConsoleCommand cmd = (IConsoleCommand)ctor.Invoke(new object[] { }); cmd.Initialize(this); cmd.Execute(null); } } } } }
private void btnSend_Click(object sender, EventArgs e) { Print("> " + txtInput.Text); string[] tokens = txtInput.Text.Split(' '); IConsoleCommand command = ConsoleCommandManager.Instance.GetConsoleCommand(tokens[0]); if (command != null) { command.Execute(engine, currentScript, this, tokens); } else { Print("Unknown command"); } txtInput.Text = null; }
public void Execute(string[] args) { if (args.Length == 0) { if (_noArgsCommand != null) { _noArgsCommand.Execute(args); } else { throw new InvalidOperationException("No executor registered for zero arguments"); } } else { var commandKey = args[0]; Execute(commandKey, args.Skip(1).ToArray()); } }
private void Execute(List <string> args) { if (args.Count == 0) { PrintHelp(); return; } IConsoleCommand command = GetCommand(args[0]); if (command == null) { _log.Error("Could not find command '" + args[0] + "'"); PrintHelp(); return; } args.RemoveAt(0); _log.Debug("Executing command [" + command.GetType() + "]"); command.Execute(args); }
public void InterceptSpecialCommands(string input) { Trace.Assert(!String.IsNullOrWhiteSpace(input)); Trace.Assert(input.StartsWith(".")); string commandName = new Regex(@"\.([A-z0-9])+").Match(input).Captures[0].Value.Substring(1).Trim(); if (commandName.Equals("help")) { console.log(helpManager.GetHelpString()); return; } if (!commands.ContainsKey(commandName)) { console.log("Could not find command: " + input); return; } IConsoleCommand command = (IConsoleCommand)kernel.Get(commands[commandName]); command.Execute(ParseSpecialCommandInputs(input)); }
/// <summary> /// Run the application /// </summary> /// <param name="args">The array of commandline arguments</param> public virtual void Run(string[] args) { Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKeyPress); try { ParseArguments(args); } catch (ArgumentException ex) { Console.Error.WriteLine(ex.Message); ShowUsage(); Environment.ExitCode = (int)CommandStatus.E_FAIL_INVALID_ARGUMENTS; return; } #if DEBUG if (_Command != null) { Console.WriteLine("Silent: {0}\nTest: {1}", _Command.IsSilent, _Command.IsTestOnly); } #endif int retCode = (int)CommandStatus.E_OK; if (_Command != null) { try { retCode = _Command.Execute(); } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); retCode = (int)CommandStatus.E_FAIL_UNKNOWN; } } #if DEBUG Console.WriteLine("Status: {0}", retCode); #endif System.Environment.ExitCode = retCode; }
public string Process(string buffer) { string commandName = GetCommandName(buffer); IConsoleCommand command = GameConsoleOptions.Commands.Where(c => c.Name == commandName).FirstOrDefault(); var arguments = GetArguments(buffer); if (command == null) { return("ERROR: Command not found"); } string commandOutput; try { commandOutput = command.Execute(arguments); } catch (Exception ex) { commandOutput = "ERROR: " + ex.Message; } return(commandOutput); }
public void ProcessLine(string line) { tokens.Clear(); StringHelper.Tokenise(line, " ", tokens); if (tokens.Count == 0) { return; } string commandKey = tokens[0].ToLower(); if (!commands.ContainsKey(commandKey)) { Log("No command \"{0}\" exists", commandKey); return; } IConsoleCommand command = commands[commandKey]; command.Execute(this, tokens); }
public void Execute(string text) { try { char[] sp = new char[] { ' ', '\t' }; string[] argv = text.Split(sp, 2, StringSplitOptions.RemoveEmptyEntries); string alias = null; if (argv.Length == 0) { return; } // replace first argument with alias value if (null != (alias = Context.Settings.Alias.FindAliasValue(argv[0]))) { if (2 == argv.Length) { text = alias + " " + argv[1]; } else if (1 == argv.Length) { text = alias; } argv = text.Split(sp, 2, StringSplitOptions.RemoveEmptyEntries); } IConsoleCommand command = FindCommand(argv[0]); if (command == null) { string strError = "Command: " + "<" + argv[0] + ">" + " is not valid."; Write(strError); return; } if (eCommandStatus.CommandStatus_Disabled == command.CommandStatus) { string strError = "Command: " + "<" + argv[0] + ">" + " is only available while debugging."; Write(strError); return; } if (argv.Length > 1) { command.Execute(argv[1]); } else { command.Execute(""); } } catch (Exception e) { System.Diagnostics.Debugger.Log(0, "Diag", e.ToString()); try { Write("Command Exception:" + e.Message); Write(e.StackTrace); } catch (Exception ex) { System.Diagnostics.Debugger.Log(0, "Diag", ex.ToString()); } } }
public void RunSimulator() { m_Terminal.PrintString("Type \"help\" (sans quotes) to print a brief description of available commands.\n"); while (!m_TerminationMgr.IsTerminated) { try { m_Terminal.PrintString(">>> "); string command = m_Terminal.ReadCommand(); ParsedCommand parsedCmd = m_LastParsedCmd; if (!string.IsNullOrEmpty(command)) { parsedCmd = ParsedCommand.ParseInput(command); } if (parsedCmd != null) { m_LastParsedCmd = parsedCmd; IConsoleCommand cmdImpl = m_CmdTable.GetCommand(parsedCmd); if (cmdImpl == null) { IEnumerable <string> possibleCmds = m_Terminal.GetSuggestedCommands(command); var allCmdSuggestions = new List <IConsoleCommand>(); foreach (var possibleCmd in possibleCmds) { allCmdSuggestions.AddRange(m_CmdTable.FindCommandsSimilarToTypedCommand(possibleCmd)); } if (allCmdSuggestions.Count == 1 && allCmdSuggestions[0].NumArguments == 0) { cmdImpl = allCmdSuggestions[0]; cmdImpl.Execute(new string[] { }); } else if (allCmdSuggestions.Count >= 1) { m_Terminal.PrintString("\"" + parsedCmd.Command + "\" is ambiguous. "); m_Terminal.PrintString("The following command(s) match the provided pattern:\n"); foreach (var cmd in allCmdSuggestions) { m_Terminal.PrintString(cmd.CommandStringWithArgs + '\n'); } m_Terminal.PrintChar('\n'); } else { m_Terminal.PrintString("\"" + parsedCmd.Command + "\" was not a recognized command. "); m_Terminal.PrintChar('\n'); } } else { cmdImpl.Execute(parsedCmd.Arguments); } } } catch (Exception ex) { m_Terminal.PrintString(ex.Message + '\n'); m_Terminal.RequestOutputFlush(); } } }