Ejemplo n.º 1
0
 /// <summary>
 /// A convenience method that wraps <code>command.Wait()</code> in order to re-throw a fancy <see cref="CommandLineException"/>
 /// when the underlying task fails or is canceled.
 /// </summary>
 public static void WaitWithFancyError(this Command command, CommandLineErrorCode errorCode)
 {
     try
     {
         command.Wait();
     }
     catch (Exception e)
     {
         Log.Ex(e);
         throw new CommandLineException(errorCode, e);
     }
 }
Ejemplo n.º 2
0
 public CommandLineException(CommandLineErrorCode errorCode, Exception innerException) : base(errorCode.GetDefaultMessage(), innerException)
 {
     Code = errorCode;
 }
Ejemplo n.º 3
0
 public CommandLineException(CommandLineErrorCode errorCode, string message) : base(message)
 {
     Code = errorCode;
 }
Ejemplo n.º 4
0
 public CommandLineException(CommandLineErrorCode errorCode, string message, Exception innerException) : base(message, innerException)
 {
     Code = errorCode;
 }
Ejemplo n.º 5
0
 public CommandLineException(CommandLineErrorCode errorCode) : base(errorCode.GetDefaultMessage())
 {
     Code = errorCode;
 }
Ejemplo n.º 6
0
 private static MemberInfo ForValue(CommandLineErrorCode code)
 {
     return(typeof(CommandLineErrorCode).GetField(Enum.GetName(typeof(CommandLineErrorCode), code)));
 }
Ejemplo n.º 7
0
 private static CommandLineErrorCodeAttribute GetAttribute(CommandLineErrorCode code)
 {
     return((CommandLineErrorCodeAttribute)Attribute.GetCustomAttribute(ForValue(code), typeof(CommandLineErrorCodeAttribute)));
 }
Ejemplo n.º 8
0
        public static string GetLocalizationKey(this CommandLineErrorCode code)
        {
            CommandLineErrorCodeAttribute attribute = (CommandLineErrorCodeAttribute)Cache[code];

            return(attribute?.LocalizationKey);
        }
Ejemplo n.º 9
0
        public static string GetDefaultMessage(this CommandLineErrorCode code)
        {
            CommandLineErrorCodeAttribute attribute = (CommandLineErrorCodeAttribute)Cache[code];

            return(attribute != null ? attribute.DefaultMessage : string.Empty);
        }