Example #1
0
        /// <summary>
        /// Creates the ExceptionStub object from the Exception passed
        /// </summary>
        /// <param name="exception">Exception object containing the runtime exceptions</param>
        /// <returns>Exceptionstub object</returns>
        public static ExceptionStub CreateExceptionStub(System.Exception exception)
        {
            ExceptionStub stub = new ExceptionStub();

            stub.Message      = exception.Message;
            stub.Source       = exception.Source;
            stub.FullTypeName = exception.GetType().FullName;
            stub.Stack        = exception.StackTrace;
            if (exception.InnerException != null)
            {
                stub.InnerException = CreateExceptionStub(exception.InnerException);
            }

            if (InnerExceptions == null)
            {
                InnerExceptions = new List <ExceptionStub>();
            }
            if (exception is AggregateException)
            {
                AggregateException age = (exception as AggregateException);
                foreach (Exception innerEx in age.InnerExceptions)
                {
                    InnerExceptions.Add(CreateExceptionStub(innerEx));
                }
            }

            return(stub);
        }
Example #2
0
        /// <summary>
        /// Serializer the exception into XML
        /// </summary>
        /// <param name="exception">Exception object to serialize</param>
        /// <returns>XML serialized representation of the exception object</returns>
        public static string CreateExceptionStubXml(System.Exception exception)
        {
            ExceptionStub         stub       = CreateExceptionStub(exception);
            ISerializationManager serializer = new XmlSerializationManager();

            return(serializer.Serialize <ExceptionStub>(stub));
        }
Example #3
0
        /// <summary>
        /// Creates fault exception using supplied parameters.
        /// </summary>
        /// <typeparam name="T">The type of fault.</typeparam>
        /// <param name="ex">The exception.</param>
        /// <param name="source">The error source.</param>
        /// <param name="message">The message that describes the error.</param>
        /// <param name="isFatal">The value indicating whether the error is fatal.</param>
        /// <returns>The type of fault.</returns>
        public static T CreateFaultFromException <T>(Exception ex, string source, string message, bool isFatal) where T : CoreFault, new()
        {
            T fault = new T();

            fault.Source = source;

            if (string.IsNullOrEmpty(message))
            {
                fault.Description = ex.Message;
            }
            else
            {
                fault.Description = message;
            }

            fault.ErrorCode = ex.GetHashCode();

            fault.IsFatal = isFatal;

            fault.Reason = new FaultReason(fault.Description);

            fault.Exception = ExceptionStub.CreateExceptionStub(ex);
            return(fault);
        }