private void OnExecuted(IExecutionContext session, string commandText, CommandResultCode resultCode) { if (CommandExecuted != null) { CommandExecuted(session, new CommandEventArgs(commandText, resultCode)); } }
internal CommandEventArgs(string commandText, CommandResultCode resultcode) { this.commandText = commandText; this.resultcode = resultcode; }
internal CommandResult(TCommand command, CommandResultCode returnCode, List <ValidationResult> validationResults) { _command = command; _returnCode = returnCode; _validationResults = validationResults; }
internal CommandResult(TCommand command, CommandResultCode returnCode) : this(command, returnCode, new List <ValidationResult>()) { }
public void ExecuteCommand(IExecutionContext context, string commandText) { if (String.IsNullOrEmpty(commandText)) { return; } // remove trailing command separator and whitespaces. StringBuilder cmdBuilder = new StringBuilder(commandText.Trim()); int i; for (i = cmdBuilder.Length - 1; i > 0; --i) { char c = cmdBuilder[i]; if (c != CommandSeparator && !Char.IsWhiteSpace(c)) { break; } } if (i < 0) { return; } cmdBuilder.Length = i + 1; string cmd = cmdBuilder.ToString(); string cmdName = CompleteCommandName(cmd); Command command = GetCommandFromCooked(cmdName); if (command != null) { try { string[] args = new string[0]; string parameters = cmd.Substring(cmdName.Length); if (parameters.Length > 0) { parameters = parameters.Trim(); args = parameters.Split(' '); ArrayList argsList = new ArrayList(); for (int j = 0; j < args.Length; j++) { args[j] = args[j].Trim(); if (args[j].Length > 0) { argsList.Add(args[j]); } } args = (string[])argsList.ToArray(typeof(string)); } if (command.RequiresContext && (context == null || !context.IsIsolated)) { Application.Error.WriteLine(cmdName + " requires a valid isolated context."); return; } OnExecuting(context, commandText); CommandResultCode result = command.Execute(context, new CommandArguments(args)); OnExecuted(context, commandText, result); switch (result) { case CommandResultCode.SyntaxError: { string[] synopsis = command.Synopsis; if (synopsis != null && synopsis.Length > 0) { Application.Error.WriteLine(cmdName + " usage: "); for (int j = 0; j < synopsis.Length; j++) { Application.Error.Write(" "); Application.Error.WriteLine(synopsis[j]); } } else { Application.Error.WriteLine(cmdName + " syntax error."); } break; } case CommandResultCode.ExecutionFailed: { // if we are in batch mode, then no message is written // to the screen by default. Thus we don't know, _what_ // command actually failed. So in this case, write out // the offending command. if (IsInBatch) { Application.Error.WriteLine("-- failed command: "); Application.Error.WriteLine(commandText); } break; } } } catch (Exception e) { #if DEBUG System.Console.Error.WriteLine(e.Message); System.Console.Error.WriteLine(e.StackTrace); #endif Application.Error.WriteLine(e.ToString()); OnExecuted(context, commandText, CommandResultCode.ExecutionFailed); } } }
private void OnExecuted(IExecutionContext session, string commandText, CommandResultCode resultCode) { if (CommandExecuted != null) CommandExecuted(session, new CommandEventArgs(commandText, resultCode)); }