private bool TryToProceedCommand(ICommand command, IEnumerable <string> args) { if (command != null) { if (command.Verbose) { Console.WriteLine("Proceeding Command: " + command.Name); } try { _commandPropertyWalker.FillCommandProperties(args, command); command.Console = Console; command.Run(); return(true); } catch (Exception exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unexpected error happended while proceeding the command: " + command.Name); var exceptionWalker = new ExceptionWalker(exception); foreach (var message in exceptionWalker.GetExceptionMessages()) { Console.WriteLine(message); } Console.ResetColor(); return(false); } } return(false); }
private void LogException(AbstractConsole console, Exception exception, ICommand command) { if (console == null) console = Console; var traceconsole = console as TraceConsole; var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Unexpected error happended while proceeding the command: " + command.Name); var exceptionWalker = new ExceptionWalker(exception); foreach (var message in exceptionWalker.GetExceptionMessages()) { stringBuilder.AppendLine(message); } if(traceconsole != null) { //If we have a TraceConsole, trace as error, otherwise use the default Console try { traceconsole.TraceEvent(TraceEventType.Error, 0, stringBuilder.ToString()); } catch (Exception ex) { //In case of any errors regardings the tracing (e.g. missing FileWrite rights) use //the default console and log this exception as well ConsoleHelper.WriteLineInRed(Console, stringBuilder.ToString()); LogException(Console, ex, command); } } else { ConsoleHelper.WriteLineInRed(Console, stringBuilder.ToString()); } }
private bool TryToProceedCommand(ICommand command, IEnumerable<string> args) { if (command != null) { if (command.Verbose) Console.WriteLine("Proceeding Command: " + command.Name); try { _commandPropertyWalker.FillCommandProperties(args, command); command.Console = Console; command.Run(); return true; } catch (Exception exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unexpected error happended while proceeding the command: " + command.Name); var exceptionWalker = new ExceptionWalker(exception); foreach (var message in exceptionWalker.GetExceptionMessages()) { Console.WriteLine(message); } Console.ResetColor(); return false; } } return false; }