Пример #1
0
        public async Task <HttpResponseMessage> Post(string appKey, string sig)
        {
            if (HttpContext.Current.Request.InputStream.Length > 20000000)
            {
                return(await KillLargeReportAsync(appKey));
            }

            if (!_samplingCounter.CanAccept(appKey))
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }


            try
            {
                var buffer = new byte[HttpContext.Current.Request.InputStream.Length];
                HttpContext.Current.Request.InputStream.Read(buffer, 0, buffer.Length);
                var handler = new SaveReportHandler(_queueProvider);
                await handler.BuildReportAsync(appKey, sig, Request.GetClientIpAddress(), buffer);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception exception)
            {
                _logger.Error("Failed to handle request from " + appKey + " / " + Request.GetClientIpAddress(),
                              exception);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception));
            }
        }
        public async Task <HttpResponseMessage> Post(string appKey, string sig)
        {
            if (HttpContext.Current.Request.InputStream.Length > 2000000)
            {
                return(await KillLargeReportAsync(appKey));
            }

            if (!_samplingCounter.CanAccept(appKey))
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }


            try
            {
                var buffer = new byte[HttpContext.Current.Request.InputStream.Length];
                HttpContext.Current.Request.InputStream.Read(buffer, 0, buffer.Length);
                var handler   = new SaveReportHandler(_messageQueue, _unitOfWork, _configStore);
                var principal = CreateReporterPrincipal();
                await handler.BuildReportAsync(principal, appKey, sig, Request.GetClientIpAddress(), buffer);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (InvalidCredentialException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "INVALID_APP_KEY", ex));
            }
            catch (HttpException ex)
            {
                _logger.InfoFormat(ex.Message);
                return(Request.CreateErrorResponse((HttpStatusCode)ex.GetHttpCode(), ex.Message));
            }
            catch (Exception exception)
            {
                _logger.Error("Failed to handle request from " + appKey + " / " + Request.GetClientIpAddress(),
                              exception);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception));
            }
        }