Esempio n. 1
0
        private NewReportDTO DeserializeBody(byte[] body)
        {
            string json;

            if (body[0] == 0x1f && body[1] == 0x8b)
            {
                var decompressor = new ReportDecompressor();
                json = decompressor.Deflate(body);
            }
            else
            {
                json = Encoding.UTF8.GetString(body);
            }

            // protection against very large error reports.
            if (json.Length > _maxSizeForJsonErrorReport)
            {
                return(null);
            }

            // to support clients that still use the OneTrueError client library.
            json = json.Replace("OneTrueError", "Coderr");

            return(JsonConvert.DeserializeObject <NewReportDTO>(json,
                                                                new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                ContractResolver =
                    new IncludeNonPublicMembersContractResolver()
            }));
        }
        private NewReportDTO DeserializeBody(byte[] body)
        {
            string json;

            if (body[0] == 0x1f && body[1] == 0x8b)
            {
                var decompressor = new ReportDecompressor();
                json = decompressor.Deflate(body);
            }
            else
            {
                json = Encoding.UTF8.GetString(body);
            }

            // protection against very large error reports.
            if (json.Length > _maxSizeForJsonErrorReport)
            {
                return(null);
            }

            // to support clients that still use the OneTrueError client library.
            json = json.Replace("OneTrueError", "Coderr");

            var dto = JsonConvert.DeserializeObject <NewReportDTO>(json,
                                                                   new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                ContractResolver =
                    new IncludeNonPublicMembersContractResolver()
            });

            if (string.IsNullOrEmpty(dto.EnvironmentName) && !string.IsNullOrEmpty(dto.Environment))
            {
                dto.EnvironmentName = dto.Environment;
            }

            // Safeguard against malformed reports (other clients than the built in ones)
            if (dto.Exception == null)
            {
                return(null);
            }
            if (string.IsNullOrWhiteSpace(dto.Exception.Name) && string.IsNullOrWhiteSpace(dto.Exception.FullName))
            {
                return(null);
            }
            if (string.IsNullOrWhiteSpace(dto.Exception.Name))
            {
                dto.Exception.Name = dto.Exception.FullName;
            }
            if (string.IsNullOrWhiteSpace(dto.Exception.FullName))
            {
                dto.Exception.FullName = dto.Exception.Name;
            }
            if (dto.Exception.BaseClasses == null)
            {
                dto.Exception.BaseClasses = new string[0];
            }
            if (dto.Exception.Namespace == null)
            {
                dto.Exception.Namespace = "";
            }

            return(dto);
        }