Пример #1
0
 private async Task StoreReport(string appKey, string remoteAddress, ReceivedReportDTO report)
 {
     try
     {
         using (var connection = ConnectionFactory.Create())
         {
             using (var cmd = (DbCommand)connection.CreateCommand())
             {
                 cmd.CommandText =
                     @"INSERT INTO QueueReports (appkey, CreatedAtUtc, RemoteAddress, Body)
                                     VALUES (@appkey, @CreatedAtUtc, @RemoteAddress, @Body);";
                 cmd.AddParameter("createdatutc", DateTime.UtcNow);
                 cmd.AddParameter("appKey", appKey);
                 cmd.AddParameter("RemoteAddress", remoteAddress);
                 cmd.AddParameter("Body", JsonConvert.SerializeObject(report));
                 await cmd.ExecuteNonQueryAsync();
             }
         }
     }
     catch (Exception ex)
     {
         _logger.Warn(
             "Failed to StoreReport: " + JsonConvert.SerializeObject(new { appKey, model = report }), ex);
     }
 }
Пример #2
0
        public async Task BuildReportAsync(string appKey, string signatureProvidedByTheClient, string remoteAddress,
                                           byte[] reportBody)
        {
            if (!Guid.TryParse(appKey, out var tempKey))
            {
                _logger.Warn("Incorrect appKeyFormat: " + appKey + " from " + remoteAddress);
                throw new InvalidCredentialException("AppKey must be a valid GUID which '" + appKey + "' is not.");
            }

            var application = await GetAppAsync(appKey);

            if (application == null)
            {
                _logger.Warn("Unknown appKey: " + appKey + " from " + remoteAddress);
                throw new InvalidCredentialException("AppKey was not found in the database. Key '" + appKey + "'.");
            }

            if (!ReportValidator.ValidateBody(application.SharedSecret, signatureProvidedByTheClient, reportBody))
            {
                await StoreInvalidReportAsync(appKey, signatureProvidedByTheClient, remoteAddress, reportBody);

                throw new AuthenticationException(
                          "You either specified the wrong SharedSecret, or someone tampered with the data.");
            }

            var report = DeserializeBody(reportBody);

            //fix malconfigured clients
            if (report.CreatedAtUtc > DateTime.UtcNow)
            {
                report.CreatedAtUtc = DateTime.UtcNow;
            }

            if (_filters.Any(x => !x(report)))
            {
                return;
            }

            var internalDto = new ReceivedReportDTO
            {
                ApplicationId      = application.Id,
                RemoteAddress      = remoteAddress,
                ContextCollections = report.ContextCollections.Select(ConvertCollection).ToArray(),
                CreatedAtUtc       = report.CreatedAtUtc,
                DateReceivedUtc    = DateTime.UtcNow,
                Exception          = ConvertException(report.Exception),
                ReportId           = report.ReportId,
                ReportVersion      = report.ReportVersion
            };

            await StoreReportAsync(internalDto);
        }
#pragma warning disable 1998
        private async Task StoreReportAsync(ReceivedReportDTO report)
#pragma warning restore 1998
        {
            try
            {
                _queue.Write(report.ApplicationId, report);
            }
            catch (Exception ex)
            {
                _logger.Warn(
                    "Failed to StoreReport: " + JsonConvert.SerializeObject(new { model = report }), ex);
            }
        }
Пример #4
0
        /// <summary>
        ///     Convert received report to our internal format
        /// </summary>
        /// <param name="report">client report</param>
        /// <param name="applicationId">application that we identified that the report belongs to</param>
        /// <returns>internal format</returns>
        public ErrorReportEntity ConvertReport(ReceivedReportDTO report, int applicationId)
        {
            ErrorReportException ex = null;

            if (report.Exception != null)
            {
                ex = ConvertException(report.Exception);
            }

            //var id = _idGeneratorClient.GetNextId(ErrorReportEntity.SEQUENCE);
            var contexts = report.ContextCollections.Select(x => new ErrorReportContext(x.Name, x.Properties)).ToArray();
            var dto      = new ErrorReportEntity(applicationId, report.ReportId, report.CreatedAtUtc, ex, contexts);

            return(dto);
        }