Ejemplo n.º 1
0
        public void CreateReport(ErrorReportEntity report)
        {
            if (report == null)
            {
                throw new ArgumentNullException(nameof(report));
            }

            if (string.IsNullOrEmpty(report.Title) && report.Exception != null)
            {
                report.Title = report.Exception.Message;
                if (report.Title == null)
                {
                    report.Title = "[Exception message was not specified]";
                }
                else if (report.Title.Length > 100)
                {
                    report.Title = report.Title.Substring(0, 100);
                }
            }

            var collections = new List <string>();

            foreach (var context in report.ContextCollections)
            {
                var data = EntitySerializer.Serialize(context);
                if (data.Length > MaxCollectionSize)
                {
                    var tooLargeCtx = new ErrorReportContextCollection(context.Name,
                                                                       new Dictionary <string, string>()
                    {
                        {
                            "Error",
                            $"This collection was larger ({data.Length}bytes) than the threshold of {MaxCollectionSize}bytes"
                        }
                    });

                    data = EntitySerializer.Serialize(tooLargeCtx);
                }
                collections.Add(data);
            }

            _unitOfWork.Insert(report);

            var cols     = string.Join(", ", collections);
            var inboound = new InboundCollection
            {
                JsonData = $"[{cols}]",
                ReportId = report.Id
            };

            _unitOfWork.Insert(inboound);
        }
Ejemplo n.º 2
0
        private static DataRow CreateDataTableRow(DataTable dataTable, int reportId,
                                                  ErrorReportContextCollection context,
                                                  KeyValuePair <string, string> property)
        {
            var contextName = context.Name.Length > 50
                ? context.Name.Substring(0, 47) + "..."
                : context.Name;
            var propertyName = property.Key.Length > 50
                ? property.Key.Substring(0, 47) + "..."
                : property.Key;

            var row = dataTable.NewRow();

            row["ReportId"]     = reportId;
            row["Name"]         = contextName;
            row["PropertyName"] = propertyName;
            row["Value"]        = property.Value;
            return(row);
        }
Ejemplo n.º 3
0
        public async Task <ErrorReportEntity> GetAsync(int id)
        {
            ErrorReportEntity report;

            using (var cmd = (DbCommand)_uow.CreateCommand())
            {
                cmd.CommandText =
                    "SELECT * FROM ErrorReports With (ReadUncommitted) WHERE Id = @id";

                cmd.AddParameter("id", id);
                report = await cmd.FirstAsync <ErrorReportEntity>();
            }

            var collections = new List <ErrorReportContextCollection>();

            using (var cmd = (DbCommand)_uow.CreateCommand())
            {
                cmd.CommandText =
                    @"SELECT Name, PropertyName, Value 
                        FROM ErrorReportCollectionProperties WITH(ReadUncommitted)
                        WHERE ReportId = @id 
                        ORDER BY Name";

                cmd.AddParameter("id", id);
                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    string previousCollectionName = null;
                    var    properties             = new Dictionary <string, string>();
                    string currentCollectionName  = null;
                    while (await reader.ReadAsync())
                    {
                        currentCollectionName = reader.GetString(0);

                        // We always want to add the context when the last property have been found
                        // so that all props are included.
                        if (previousCollectionName == null)
                        {
                            previousCollectionName = currentCollectionName;
                        }

                        if (previousCollectionName != currentCollectionName)
                        {
                            var collection = new ErrorReportContextCollection(previousCollectionName ?? currentCollectionName, properties);
                            collections.Add(collection);
                            properties             = new Dictionary <string, string>();
                            previousCollectionName = currentCollectionName;
                            report.Add(collection);
                        }

                        properties[reader.GetString(1)] = reader.GetString(2);
                    }

                    // When the last property is in a new collection
                    if (currentCollectionName != null && collections.All(x => x.Name != currentCollectionName))
                    {
                        var collection = new ErrorReportContextCollection(previousCollectionName, properties);
                        collections.Add(collection);
                        report.Add(collection);
                    }
                }
            }

            return(report);
        }