using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Unity.Cloud
{
///
/// Represents a serializable exception.
///
public class SerializableException
{
#region Constructors
///
/// Creates a new instance of the class.
///
public SerializableException()
{
// Empty
}
///
/// Creates a new instance of the class.
///
/// The exception.
public SerializableException(Exception exception)
{
// Message
this.Message = exception.Message;
// Full Text
this.FullText = exception.ToString();
// Type
Type exceptionType = exception.GetType();
this.Type = exceptionType.FullName;
// Stack Trace
this.StackTrace = new List();
StackTrace stackTrace = new StackTrace(exception, true);
foreach (StackFrame stackFrame in stackTrace.GetFrames())
{
this.StackTrace.Add(new SerializableStackFrame(stackFrame));
}
// Problem Identifier
if (this.StackTrace.Count > 0)
{
SerializableStackFrame stackFrame = this.StackTrace[0];
this.ProblemIdentifier = string.Format("{0} at {1}.{2}", this.Type, stackFrame.DeclaringType, stackFrame.MethodName);
}
else
{
this.ProblemIdentifier = this.Type;
}
// Detailed Problem Identifier
if (this.StackTrace.Count > 1)
{
SerializableStackFrame stackFrame1 = this.StackTrace[0];
SerializableStackFrame stackFrame2 = this.StackTrace[1];
this.DetailedProblemIdentifier = string.Format("{0} at {1}.{2} from {3}.{4}", this.Type, stackFrame1.DeclaringType, stackFrame1.MethodName, stackFrame2.DeclaringType, stackFrame2.MethodName);
}
// Inner Exception
if (exception.InnerException != null)
{
this.InnerException = new SerializableException(exception.InnerException);
}
}
#endregion
#region Properties
///
/// Gets or sets the detailed problem identifier.
///
public string DetailedProblemIdentifier { get; set; }
///
/// Gets or sets the full text.
///
public string FullText { get; set; }
///
/// Gets or sets the inner exception.
///
public SerializableException InnerException { get; set; }
///
/// Gets or sets the message.
///
public string Message { get; set; }
///
/// Gets or sets the problem identifier.
///
public string ProblemIdentifier { get; set; }
///
/// Gets or sets the stack trace.
///
public List StackTrace { get; set; }
///
/// Gets or sets the type.
///
public string Type { get; set; }
#endregion
}
}