/// <summary>
        ///     Initializes a new instance of the <see cref="ErrorReportDTO" /> class.
        /// </summary>
        /// <param name="reportId">Unique identifier for this error report.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="contextCollections">The context collections.</param>
        public ErrorReportDTO(string reportId, ExceptionDTO exception, ContextCollectionDTO[] contextCollections)
        {
            if (reportId == null)
            {
                throw new ArgumentNullException("reportId");
            }
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            if (contextCollections == null)
            {
                throw new ArgumentNullException("contextCollections");
            }
            if (reportId.Contains(" ") || reportId.Length > 30)
            {
                throw new ArgumentException(
                          string.Format(
                              "reportId must be 30 or less characters and should be alphanumeric only. Your id '{0}' is {1} chars.",
                              reportId, reportId.Length));
            }

            ContextCollections = contextCollections;
            Exception          = exception;
            ReportId           = reportId;
            ReportVersion      = "1.0";
            CreatedAtUtc       = DateTime.UtcNow;
        }
Пример #2
0
        /// <summary>
        ///     Copy the .NET exception information into our DTO.
        /// </summary>
        /// <param name="source">Exception to copy from</param>
        /// <param name="destination">Model to put the information in.</param>
        public static void Copy(Exception source, ExceptionDTO destination)
        {
            destination.FullName     = source.GetType().FullName;
            destination.Name         = source.GetType().Name;
            destination.Namespace    = source.GetType().Namespace;
            destination.AssemblyName = source.GetType().GetTypeInfo().Assembly.FullName;
            destination.Message      = source.Message;

            var baseTypes = GetBaseClasses(source);

            destination.BaseClasses = baseTypes.ToArray();
            destination.StackTrace  = source.StackTrace;
            destination.Properties  = GetProperties(source);

            destination.AsString = source.ToString();

            if (source.InnerException != null)
            {
                destination.InnerException = new ExceptionDTO(source.InnerException);
            }

            if (destination.StackTrace == null)
            {
                destination.StackTrace = "";
            }
        }
Пример #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ExceptionDTO" /> class.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <exception cref="System.ArgumentNullException">exception</exception>
        public ExceptionDTO(ExceptionDTO exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            Copy(exception, this);
            Properties = new Dictionary <string, string>();
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ErrorReportDTO" /> class.
        /// </summary>
        /// <param name="reportId">Unique identifier for this error report.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="contextCollections">The context collections.</param>
        public ErrorReportDTO(string reportId, ExceptionDTO exception, ContextCollectionDTO[] contextCollections)
        {
            if (reportId == null)
            {
                throw new ArgumentNullException(nameof(reportId));
            }
            if (reportId.Contains(" ") || reportId.Length > 30)
            {
                throw new ArgumentException(
                          $"reportId must be 30 or less characters and should be alphanumeric only. Your id '{reportId}' is {reportId.Length} chars.");
            }

            ContextCollections = contextCollections ?? throw new ArgumentNullException(nameof(contextCollections));
            Exception          = exception ?? throw new ArgumentNullException(nameof(exception));
            ReportId           = reportId;
            ReportVersion      = "1.0";
            CreatedAtUtc       = DateTime.UtcNow;
        }
Пример #5
0
        /// <summary>
        ///     Copy the .NET exception information into our DTO.
        /// </summary>
        /// <param name="source">Exception to copy from</param>
        /// <param name="destination">Model to put the information in.</param>
        public static void Copy(ExceptionDTO source, ExceptionDTO destination)
        {
            destination.FullName     = source.FullName;
            destination.Name         = source.Name;
            destination.Namespace    = source.Namespace;
            destination.AssemblyName = source.AssemblyName;
            destination.Message      = source.Message;

            destination.BaseClasses = source.BaseClasses.ToArray();
            destination.StackTrace  = source.StackTrace;
            destination.Properties  = new Dictionary <string, string>(source.Properties);

            destination.AsString = source.AsString;

            if (source.InnerException != null)
            {
                destination.InnerException = new ExceptionDTO(source.InnerException);
            }

            if (destination.StackTrace == null)
            {
                destination.StackTrace = "";
            }
        }
Пример #6
0
        /// <summary>
        ///     Copy the .NET exception information into our DTO.
        /// </summary>
        /// <param name="source">Exception to copy from</param>
        /// <param name="destination">Model to put the information in.</param>
        public static void Copy(Exception source, ExceptionDTO destination)
        {
            var culture   = Thread.CurrentThread.CurrentCulture;
            var uiCulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                var evt = new ManualResetEventSlim(false);

                // in a separate thread to not get any side effects due to the culture change.
                ThreadPool.QueueUserWorkItem(x =>
                {
                    //TODO: wont work for some exceptions (where texts are preloaded). We need to use Google Translate.
                    Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = English;
                    try
                    {
                        destination.FullName     = source.GetType().FullName;
                        destination.Name         = source.GetType().Name;
                        destination.Namespace    = source.GetType().Namespace;
                        destination.AssemblyName = source.GetType().Assembly.FullName;
                        destination.Message      = source.Message;

                        var baseTypes           = GetBaseClasses(source);
                        destination.BaseClasses = baseTypes.ToArray();
                        destination.StackTrace  = source.StackTrace;
                        destination.Properties  = GetProperties(source);

                        try
                        {
                            destination.Everything = Serializer.Serialize(source);
                        }
                        catch
                        {
                            destination.Everything = source.ToString();
                        }

                        if (source.InnerException != null)
                        {
                            destination.InnerException = new ExceptionDTO(source.InnerException);
                        }
                    }
                    catch
                    {
                        Thread.CurrentThread.CurrentCulture   = culture;
                        Thread.CurrentThread.CurrentUICulture = uiCulture;
                    }
                    evt.Set();
                });
                evt.Wait();

                if (destination.StackTrace == null)
                {
                    Debug.WriteLine("StackTrace can be empty (SoapException), but it's not likely");
                    destination.StackTrace = "";
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture   = culture;
                Thread.CurrentThread.CurrentUICulture = uiCulture;
            }
        }