Beispiel #1
0
        /// <summary>
        /// Creates a new object that is a deep copy of the current instance.
        /// </summary>
        /// <param name="handledErrorList">List of errors already handled.</param>
        /// <returns>A new object that is a deep copy of this instance.</returns>
        private OperationError CreateDeepCopy(IDictionary <OperationError, OperationError> handledErrorList)
        {
            // Return self copy if already in list.
            OperationError thisCopy;

            if (handledErrorList.TryGetValue(this, out thisCopy))
            {
                return(thisCopy);
            }

            // Create a copy of this.
            OperationError copy = new OperationError();

            // Add copy to the list.
            handledErrorList.Add(this, copy);

            // Copy attributes.
            copy.ClassName     = this.ClassName;
            copy.FullClassName = this.FullClassName;
            copy.Message       = this.Message;
            copy.Source        = this.Source;
            copy.StackTrace    = this.StackTrace;

            // Copy inner error.
            if (this.InnerError != null)
            {
                copy.InnerError = this.InnerError.CreateDeepCopy(handledErrorList);
            }

            return(copy);
        }
Beispiel #2
0
 /// <summary>
 /// Constructor with exception message and inner operation error.
 /// </summary>
 /// <param name="message">Message for the exception.</param>
 /// <param name="operationError">Inner operation error.</param>
 public OperationErrorException(string message, OperationError operationError) : base(message)
 {
     if (operationError != null)
     {
         this.InnerError = operationError.CreateDeepCopy <OperationError>();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Adds stack trace information to a given string builder.
        /// </summary>
        /// <param name="builder">String builder to append data.</param>
        /// <param name="error">'ServiceError' object to get string.</param>
        /// <param name="handledErrorList">List of errors already handled.</param>
        /// <returns>Whether data was written.</returns>
        static private bool AppendStackTraceString(StringBuilder builder, OperationError error, HashSet <OperationError> handledErrorList)
        {
            // Return if this error is already handled.
            if (handledErrorList.Contains(error))
            {
                return(false);
            }

            // Add current error to list of handled errors.
            handledErrorList.Add(error);

            // Add inner stack trace.
            if (error.InnerError != null)
            {
                if (AppendStackTraceString(builder, error.InnerError, handledErrorList))
                {
                    builder.Append(System.Environment.NewLine);
                    builder.Append("   --- End of inner exception stack trace ---");
                }
            }

            // Add stack trace.
            if (string.IsNullOrEmpty(error.StackTrace) == false)
            {
                builder.Append(System.Environment.NewLine);
                builder.Append(error.StackTrace);
            }

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Adds error information to a given string builder.
        /// </summary>
        /// <param name="builder">String builder to append data.</param>
        /// <param name="error">'ServiceError' object to get string.</param>
        /// <param name="handledErrorList">List of errors already handled.</param>
        /// <returns>Whether data was written.</returns>
        static private bool AppendErrorString(StringBuilder builder, OperationError error, HashSet <OperationError> handledErrorList)
        {
            // Return if this error is already handled.
            if (handledErrorList.Contains(error))
            {
                return(false);
            }

            // Add current error to list of handled errors.
            handledErrorList.Add(error);

            // Add class name.
            builder.Append(error.FullClassName);

            // Add message.
            if (string.IsNullOrEmpty(error.Message) == false)
            {
                builder.Append(": ");
                builder.Append(error.Message);
            }

            // Add inner error.
            if (error.InnerError != null)
            {
                if (handledErrorList.Contains(error.InnerError) == false)
                {
                    builder.Append(" ---> ");
                }
                AppendErrorString(builder, error.InnerError, handledErrorList);
            }

            return(true);
        }
Beispiel #5
0
 /// <summary>
 /// Constructor with inner operation error.
 /// </summary>
 /// <param name="operationError">Inner operation error.</param>
 public OperationErrorException(OperationError operationError) : this("An operation error occurred.", operationError)
 {
 }