Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url">Exeption Url </param>
        /// <param name="context"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public async Task ErrorResponse(string url, HttpContext context, Document document)
        {
            var ErrorList = ErrorCache(url);

            ErrorList.Add(document);
            _database.ErrodDocuments.FindOneAndUpdate(mbox => mbox.Id == CacheData.ErrorBase.Id,
                                                      Builders <ErrorDocument> .Update.AddToSet(m => m.Documents, document));
            if (_next != null)
            {
                Task.Run(() => { _next.ErrorResponse(url, context, document); });
            }
        }
Ejemplo n.º 2
0
        public async Task InvokeAsync(HttpContext context)
        {
            Document document = new Document();

            document.Start = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            string authHeader  = context.Request.Headers["Authorization"];
            string url         = context.Request.Path.Value.ParseUrl();
            Stream orginalBody = context.Response.Body;



            try
            {
                using (var memStream = new MemoryStream()){
                    context.Response.Body = memStream;

                    var timer = Stopwatch.StartNew();
                    await _next(context);

                    document.EllepsitTime = timer.ElapsedMilliseconds;
                    memStream.Position    = 0;
                    await memStream.CopyToAsync(orginalBody);

                    document.ResponseStutus = context.Response.StatusCode;

                    if (context.Response.StatusCode != 200)
                    {
                        GetRequest(context, document);
                        GetResponse(memStream, document);

                        Task.Run(async() =>
                        {
                            await _service.ErrorResponse(url, context, document);
                        });
                    }
                    else
                    {
                        Task.Run(async() => { await _service.Request(url, context, document); });
                    }
                    //old
                }
            }
            finally
            {
                context.Response.Body = orginalBody;
            }
        }