Ejemplo n.º 1
0
        /// <summary>
        ///     Execute on a set of report mastery.
        /// </summary>
        /// <returns><c>false</c> if there are no more reports to analyze.</returns>
        public bool Execute()
        {
            using (var transaction = _queue.BeginTransaction())
            {
                var dto = _queue.TryReceive <ReceivedReportDTO>(transaction, TimeSpan.FromMilliseconds(500));
                if (dto == null)
                {
                    return(false);
                }

                try
                {
                    ErrorReportException ex = null;
                    if (dto.Exception != null)
                    {
                        ex = ConvertException(dto.Exception);
                    }
                    var contexts = dto.ContextCollections.Select(ConvertContext).ToArray();
                    var entity   = new ErrorReportEntity(dto.ApplicationId, dto.ReportId, dto.CreatedAtUtc, ex, contexts)
                    {
                        RemoteAddress = dto.RemoteAddress
                    };
                    _analyzer.Analyze(entity);
                }
                catch (Exception ex)
                {
                    _logger.Error("Failed to analyze report ", ex);
                }

                transaction.Commit();
            }
            return(true);
        }
        public async Task <HttpResponseMessage> SupplyFeedback(string appKey, string sig, FeedbackModel model)
        {
            try
            {
                int appId;
                using (var connection = _connectionFactory.Open())
                {
                    using (var cmd = (DbCommand)connection.CreateCommand())
                    {
                        cmd.CommandText = "SELECT Id FROM Applications WHERE AppKey = @key";
                        cmd.AddParameter("key", appKey);
                        appId = (int)await cmd.ExecuteScalarAsync();
                    }
                }
                using (var transaction = _queue.BeginTransaction())
                {
                    var dto = new ReceivedFeedbackDTO
                    {
                        ApplicationId = appId,
                        Description   = model.Description,
                        EmailAddress  = model.EmailAddress,
                        ReceivedAtUtc = DateTime.UtcNow,
                        RemoteAddress = Request.GetClientIpAddress(),
                        ReportId      = model.ReportId,
                        ReportVersion = "1"
                    };
                    _queue.Write(appId, dto);

                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                _logger.Warn(
                    "Failed to submit feedback: " + JsonConvert.SerializeObject(new { appKey, model }),
                    ex);
            }

            return(new HttpResponseMessage(HttpStatusCode.NoContent));
        }