Пример #1
0
 public ValueTask <ICommandResult> ExecuteCallbacksAsync(
     CommandMiddleware final,
     CommandContext context,
     CancellationToken cancellationToken)
 {
     return(ExecuteNextAsync(_middleware, 0, context, cancellationToken,
                             final));
Пример #2
0
        public McConnection(McConnectionContext ctx)
        {
            this.ctx = ctx;
            var stateChange = new StateUpdateMiddleware(null);
            var command     = new CommandMiddleware(stateChange.Invoke);
            var compression = new CompressionMiddleware(command.Invoke);

            connectionMiddleware = new MessageBuilderMiddleware(compression.Invoke);
        }
Пример #3
0
        private static async ValueTask <ICommandResult> TestMiddlewareAsync(
            CommandMiddleware next, CommandContext context,
            CancellationToken cancellationToken)
        {
            var logger = context.Services
                         .GetRequiredService <ILoggerFactory>()
                         .CreateLogger(typeof(Program).Name);

            logger.LogInformation("Hello world from middleware!");

            return(await next());
        }
Пример #4
0
 static async ValueTask <ICommandResult> ExecuteNextAsync(
     List <Middleware> middleware, int pos,
     CommandContext context, CancellationToken token,
     CommandMiddleware final)
 {
     return(pos >= middleware.Count
         ? await final()
         : await middleware[pos](
                () => ExecuteNextAsync(middleware, pos + 1, context, token, final),
                context,
                token));
 }