public async Task <TerminalResult> Process(string line) { CommandExecutingResult result = CommandExecutingResult.Invalid; string response = ""; if (string.IsNullOrEmpty(line)) { response = "Command can not be empty!"; result = CommandExecutingResult.EmptyInput; } foreach (var command in GetCommands().Where(command => command.IsExecutable(line))) { var runResult = await Task.Run(() => command.Run(line)); if (!runResult) { response = command.GetMessage(); result = CommandExecutingResult.IncorrectSyntax; break; } response = command.GetMessage(); result = CommandExecutingResult.Success; break; } if (result == CommandExecutingResult.Invalid) { response = $"Command: '{line}' not found!"; result = CommandExecutingResult.CommandNotFound; } return(new TerminalResult(result, response)); }
public TerminalResult(CommandExecutingResult result, string response) { ExecutingResult = result; Response = response; }