Beispiel #1
0
        public async Task InvokeAsync(CFTFileContext context)
        {
            try
            {
                _logger.LogInformation(StartMessage);
                await ExecAsync(context);

                _logger.LogInformation(EndSuccessMessage);
            }
            catch (Exception e)
            {
                _logger.LogError(e, EndErrorMessage);
                throw;
            }

            try
            {
                await _next.Invoke(context);
            }
            catch (Exception e)
            {
                await NextExceptionExecAsync(e, context);

                throw;
            }
        }
Beispiel #2
0
        public async Task SendAsync(Stream stream)
        {
            var context  = new ConnectionContext(Connection, stream);
            var iterator = Middleware.GetEnumerator();
            MiddlewareDelegate delegator = BuildMiddlewareDelegate(iterator, InternalSendAsync);

            await delegator
            .Invoke(context)
            .ContinueWith(task => iterator.Dispose())
            .ConfigureAwait(false);
        }
Beispiel #3
0
        /// <summary>
        /// Invokes added <see cref="IMiddleware{TContext}"/> in order they were added by <see cref="IFlowBuilder{TContext}"/>.
        /// Middlewares are resolved by <see cref="IServiceProvider"/>.
        /// </summary>
        /// <param name="serviceProvider"><see cref="IServiceProvider"/> for resolving middlewares.</param>
        /// <param name="context"><see cref="TContext"/> for middleware execution.</param>
        /// <returns>Awaitable <see cref="Task{TContext}"/> for asynchronous middleware invocation.</returns>
        public async Task <TContext> InvokeAsync(TContext context, IServiceProvider serviceProvider)
        {
            var factory = serviceProvider.GetService(typeof(IMiddlewareFactory <TContext>)) as IMiddlewareFactory <TContext>;

            if (factory == null)
            {
                throw new InvalidOperationException(
                          $"Failed to resolve {typeof(IMiddlewareFactory<TContext>)}. Verify that the factory is registered in your IoC container.");
            }

            await _start.Invoke(context, factory);

            return(context);
        }
Beispiel #4
0
        public async Task InvokeAsync(CFTFileContext context)
        {
            try
            {
                _logger.LogInformation(_startMessage);
                await _next.Invoke(context);

                _logger.LogInformation(_endSuccessMessage);
            }
            catch (Exception e)
            {
                _logger.LogError(e, _endErrorMessage);
            }
        }
Beispiel #5
0
 public async Task InvokeAsync(CFTFileContext context)
 {
     using (_logger.BeginScope($"file_name = {context.InputFile.FileName}"))
     {
         using (_logger.BeginScope($"full_name = {context.InputFile.FullName}"))
         {
             using (_logger.BeginScope($"corelation_id = {Guid.NewGuid()}"))
             {
                 try
                 {
                     _logger.LogInformation("Начинаем обработку файла.");
                     await _next.Invoke(context);
                     _logger.LogInformation("Файл успешно обработан.");
                 }
                 catch (Exception e)
                 {
                     _logger.LogError(e, "Ошибка обработки файла.");
                 }
             }
         }
     }
 }
Beispiel #6
0
 /// <inheritdoc/>
 public void Use(MiddlewareDelegate middleware)
 {
     UseMiddleware(middleware.Invoke());
 }