Exemplo n.º 1
0
 public static void Guard(this Je.IErrExpander exp, bool isError, Exception exception)
 {
     if (isError)
     {
         throw exception;
     }
 }
Exemplo n.º 2
0
 public static void GuardCommandNotDefined(this Je.IErrExpander exp, Func <bool> isError, Guid session)
 {
     if (isError())
     {
         throw new CommandNotDefinedException(session);
     }
 }
Exemplo n.º 3
0
 public static void Guard <T>(this Je.IErrExpander exp, bool isError) where T : Exception, new()
 {
     if (isError)
     {
         throw new T();
     }
 }
Exemplo n.º 4
0
 public static void GuardTypeNotFound(this Je.IErrExpander exp, bool isError, string typeName)
 {
     if (isError)
     {
         throw new TypeNotFoundException(typeName);
     }
 }
Exemplo n.º 5
0
 public static void GuardTypeNotSubtype(this Je.IErrExpander exp, bool isError, string type, string baseType)
 {
     if (isError)
     {
         throw new TypeNotSubtypeException(type, baseType);
     }
 }
Exemplo n.º 6
0
 public static void GuardArg(this Je.IErrExpander exp, Func <bool> isError, string paramName)
 {
     if (isError())
     {
         throw new ArgumentException(paramName);
     }
 }
Exemplo n.º 7
0
 public static void GuardRange(this Je.IErrExpander exp, bool isError, string paramName)
 {
     if (isError)
     {
         throw new ArgumentOutOfRangeException(paramName);
     }
 }
Exemplo n.º 8
0
 public static void Guard(this Je.IErrExpander exp, Func <bool> isError, Exception exception)
 {
     if (isError())
     {
         throw exception;
     }
 }
Exemplo n.º 9
0
        public static Exception FirstErrOf(this Je.IErrExpander exp, object obj)
        {
            var ae = obj as AggregateException;

            if (ae == null)
            {
                return(obj as Exception);
            }
            return(ae.InnerExceptions.Count > 0 ? ae.InnerExceptions[0].InnerException ?? ae.InnerExceptions[0] : null);
        }
Exemplo n.º 10
0
        public static string ErrToStr(this Je.IErrExpander exp, Exception exception)
        {
            exception = FirstErrOf(exp, exception);
            var msg = WebToStr(exp, exception as WebException);

            if (msg != null)
            {
                return(msg);
            }
            return(StackOf(exp, exception));
        }
Exemplo n.º 11
0
        public static string StackOf(this Je.IErrExpander exp, Exception e)
        {
            var sb = new StringBuilder();

            sb.AppendLine(e.ToString());
            while (e != null)
            {
                sb.AppendLine(e.Message);
                e = e.InnerException;
            }
            return(sb.ToString());
        }
Exemplo n.º 12
0
        public static CommandMessage LastErrOf(this Je.IErrExpander exp, IEnumerable <CommandMessage> messages)
        {
            var error = (CommandMessage)null;

            foreach (CommandMessage message in (messages ?? new CommandMessage[0]))
            {
                if (message.Category == ECommandMessage.Error)
                {
                    error = message;
                }
            }
            return(error);
        }
Exemplo n.º 13
0
        public static string WebToStr(this Je.IErrExpander exp, WebException we)
        {
            if (we == null)
            {
                return(null);
            }
            if (we.Response == null)
            {
                return("Response is empty");
            }
            var responseStream = we.Response.GetResponseStream();

            if (responseStream == null)
            {
                return("Response stream unavailable");
            }
            using (var sr = new StreamReader(responseStream)) { return(sr.ReadToEnd()); }
        }
Exemplo n.º 14
0
 public static CommandMessage FirstErrOf(this Je.IErrExpander exp, IEnumerable <CommandMessage> messages)
 {
     return((messages ?? new CommandMessage[0]).FirstOrDefault(x => x.Category == ECommandMessage.Error));
 }
Exemplo n.º 15
0
        public static Exception MsgToErr(this Je.IErrExpander exp, IEnumerable <CommandMessage> messages)
        {
            var msg = FirstErrOf(exp, messages);

            return(msg != null ? new Exception(msg.Message) : null);
        }
Exemplo n.º 16
0
 public static Exception MsgToErr(this Je.IErrExpander exp, CommandMessage msg)
 {
     return(msg.Category == ECommandMessage.Error ? new Exception(msg.Message) : null);
 }
Exemplo n.º 17
0
 public static CommandMessage ErrToMsg(this Je.IErrExpander exp, Exception e)
 {
     return(e != null ? new CommandMessage {
         Category = ECommandMessage.Error, Message = e.Message, Comment = ErrToStr(exp, e)
     } : null);
 }