Esempio n. 1
0
        public async Task InvokeAsync(HttpContext httpContext, FunctionRequestDelegate next)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            var start = Stopwatch.GetTimestamp();

            PushInfoToContext(httpContext, _correlationIdProvider);

            var requestStartingLog = GenerateRequestStartingLogMessage(httpContext);

            Log.Information(requestStartingLog);

            try
            {
                await next(httpContext);

                var elapsedMs = GetElapsedMilliseconds(start, Stopwatch.GetTimestamp());

                var statusCode = httpContext.Response?.StatusCode;
                var level      = statusCode >= 500 ? LogEventLevel.Error : LogEventLevel.Information;

                var log = level == LogEventLevel.Error ? LogForErrorContext(httpContext) : Log;
                var requestFinishingLog = GenerateRequestFinishingLogMessage(httpContext, elapsedMs);
                log.Write(level, requestFinishingLog);
            }
            catch (Exception ex) when(LogException(httpContext,
                                                   GetElapsedMilliseconds(start, Stopwatch.GetTimestamp()), ex))
            {
            }
        }
        public IFunctionApplicationBuilder Clear()
        {
            _components.Clear();
            _mainFunctionResult   = null;
            _mainFunctionDelegate = null;

            return(this);
        }
        public async Task InvokeAsync(HttpContext httpContext, FunctionRequestDelegate next)
        {
            _logger.LogInformation("Before the function endpoint is executed");

            await next(httpContext);

            _logger.LogInformation("After the function endpoint is executed");
        }
        public IFunctionApplicationBuilder UseFunction(Func <Task <IActionResult> > function)
        {
            FunctionRequestDelegate app = async(context) =>
            {
                _mainFunctionResult = await function();
            };

            _mainFunctionDelegate = app;

            return(this);
        }
        public async Task <IActionResult> RunAsync(HttpContext httpContext)
        {
            FunctionRequestDelegate app = _mainFunctionDelegate;

            if (app == null)
            {
                throw new ArgumentNullException("Main function delegate can not be null. Call UseFunction method.");
            }

            foreach (var component in _components.Reverse())
            {
                app = component(app);
            }

            await app(httpContext);

            return(_mainFunctionResult);
        }
Esempio n. 6
0
        public async Task InvokeAsync(HttpContext context, FunctionRequestDelegate next)
        {
            var correlation = _correlationIdProvider.EnsureCorrelationIdPresent();
            var request     = context.Request;
            var response    = context.Response;

            request.Headers.TryGetValue(KnownHttpHeaders.CorrelationId, out StringValues requestHeaderValue);
            if (requestHeaderValue.FirstOrDefault() == null)
            {
                request.Headers.Add(KnownHttpHeaders.CorrelationId, correlation);
            }

            response.Headers.TryGetValue(KnownHttpHeaders.CorrelationId, out StringValues responseHeaderValue);
            if (responseHeaderValue.FirstOrDefault() == null)
            {
                response.Headers.Add(KnownHttpHeaders.CorrelationId, correlation);
            }

            await next(context);
        }
 public async Task InvokeAsync(HttpContext httpContext, FunctionRequestDelegate next)
 {
     _theList.Add(1);
     await next(httpContext);
 }
Esempio n. 8
0
 public async Task InvokeAsync(HttpContext httpContext, FunctionRequestDelegate next)
 {
     await next(httpContext);
 }