Exemplo n.º 1
0
        /// <summary>
        /// Creates an instance of <see cref="ActorFault"/> from an actor exception.
        /// </summary>
        /// <param name="exception">Unhandled exception.</param>
        /// <param name="detailed">Whether to include detailed information (namely, stack trace).</param>
        /// <returns>Instance of <see cref="ActorFault"/>.</returns>
        public static ActorFault From(ActorException exception, bool detailed)
        {
            #region Validations

            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            #endregion

            ActorFault fault = new ActorFault();
            fault.Actor         = exception.Actor;
            fault.Code          = exception.Code;
            fault.Message       = exception.Description;
            fault.ExceptionType = exception.GetType().FullName;
            fault.InnerFaults   = Walk(exception.InnerException, detailed);

            if (detailed == true)
            {
                fault.StackTrace = exception.StackTrace;
            }

            return(fault);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts an exception into an WCF exception.
        /// </summary>
        /// <param name="exception">
        /// Exception.
        /// </param>
        /// <returns>
        /// WCF exception.
        /// </returns>
        public static FaultException <ActorFault> ToUnhandledException(Exception exception)
        {
            ActorFault detail = ActorFault.FromUnhandled(exception, true);

            string faultCode = "Server";

            if (detail.Actor.EndsWith(".Client", StringComparison.Ordinal) == true)
            {
                faultCode = "Client";
            }

            return(new FaultException <ActorFault>(detail, detail.Message, new FaultCode(faultCode)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an instance of <see cref="ActorFault"/> from an unhandled exception.
        /// </summary>
        /// <param name="exception">Unhandled exception.</param>
        /// <param name="detailed">Whether to include detailed information (namely, stack trace).</param>
        /// <returns>Instance of <see cref="ActorFault"/>.</returns>
        public static ActorFault FromUnhandled(Exception exception, bool detailed)
        {
            #region Validations

            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            #endregion

            ActorFault fault = new ActorFault();
            fault.Actor       = App.Name;
            fault.Code        = 990;
            fault.Message     = "Unhandled exception.";
            fault.InnerFaults = Walk(exception, detailed);

            if (detailed == true)
            {
                fault.StackTrace = exception.StackTrace;
            }

            return(fault);
        }
Exemplo n.º 4
0
        private static ActorFault[] Walk(Exception exception, bool detailed)
        {
            if (exception == null)
            {
                return(null);
            }


            /*
             * AggregateException, which contains Exception[]
             */
            if (exception is AggregateException)
            {
                AggregateException aex = (AggregateException)exception;
                List <ActorFault>  l   = new List <ActorFault>();

                foreach (Exception iex in aex.InnerExceptions)
                {
                    l.AddRange(Walk(iex, detailed));
                }

                return(l.ToArray());
            }


            /*
             * ActorAggregateException, which contains ActorException[]
             */
            if (exception is ActorAggregateException)
            {
                ActorAggregateException aex = (ActorAggregateException)exception;
                List <ActorFault>       l   = new List <ActorFault>();

                foreach (ActorException iex in aex)
                {
                    l.AddRange(Walk(iex, detailed));
                }

                return(l.ToArray());
            }


            /*
             * ActorException
             */
            if (exception is ActorException)
            {
                ActorException aex = (ActorException)exception;

                ActorFault f = new ActorFault();
                f.Actor         = aex.Actor;
                f.Code          = aex.Code;
                f.Message       = aex.Description;
                f.ExceptionType = aex.GetType().FullName;
                f.InnerFaults   = Walk(aex.InnerException, detailed);

                if (detailed == true)
                {
                    f.StackTrace = aex.StackTrace;
                }

                return(new ActorFault[] { f });
            }


            /*
             * Exception
             */
            if (true)
            {
                ActorFault f = new ActorFault();
                f.Actor         = App.Name;
                f.Code          = 991;
                f.Message       = exception.Message;
                f.ExceptionType = exception.GetType().FullName;
                f.InnerFaults   = Walk(exception.InnerException, detailed);

                if (detailed == true)
                {
                    f.StackTrace = exception.StackTrace;
                }

                return(new ActorFault[] { f });
            }

            // Impossible! :)
        }