Ejemplo n.º 1
0
        public async Task InvokeAsync(
            IKernelCommand command,
            KernelPipelineContext context)
        {
            EnsureMiddlewarePipelineIsInitialized();

            await _pipeline(command, context, (_, __) => Task.CompletedTask);
        }
Ejemplo n.º 2
0
        protected internal override async Task HandleAsync(
            IKernelCommand command,
            KernelPipelineContext context)
        {
            var kernel = context.Kernel;

            if (kernel is KernelBase kernelBase)
            {
                await kernelBase.SendOnContextAsync(command, context);

                return;
            }

            throw new NoSuitableKernelException();
        }
Ejemplo n.º 3
0
        protected internal override async Task HandleAsync(
            IKernelCommand command,
            KernelPipelineContext context)
        {
            switch (command)
            {
            case SubmitCode submitCode:
                context.OnExecute(async invocationContext =>
                {
                    await HandleSubmitCode(submitCode, invocationContext);
                });

                break;
            }
        }
Ejemplo n.º 4
0
 protected override void SetKernel(
     IKernelCommand command,
     KernelPipelineContext context)
 {
     if (context.Kernel == null)
     {
         if (DefaultKernel != null)
         {
             context.Kernel = DefaultKernel;
         }
         else if (_kernels.Count == 1)
         {
             context.Kernel = _kernels[0];
         }
     }
 }
Ejemplo n.º 5
0
        protected Parser BuildDirectiveParser(KernelPipelineContext pipelineContext)
        {
            var root = new RootCommand();

            foreach (var c in _directiveCommands)
            {
                root.Add(c);
            }

            return(new CommandLineBuilder(root)
                   .UseMiddleware(
                       context => context.BindingContext
                       .AddService(
                           typeof(KernelPipelineContext),
                           () => pipelineContext))
                   .Build());
        }
Ejemplo n.º 6
0
        public async Task <IKernelCommandResult> SendAsync(
            IKernelCommand command,
            CancellationToken cancellationToken)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var pipelineContext = new KernelPipelineContext(PublishEvent);

            await SendOnContextAsync(command, pipelineContext);

            var result = await pipelineContext.InvokeAsync();

            return(result);
        }
Ejemplo n.º 7
0
        private Task ChooseKernel(
            IKernelCommand command,
            KernelPipelineContext context,
            KernelPipelineContinuation next)
        {
            if (context.Kernel == null)
            {
                if (DefaultKernel != null)
                {
                    context.Kernel = DefaultKernel;
                }
                else if (_kernels.Count == 1)
                {
                    context.Kernel = _kernels[0];
                }
            }

            return(next(command, context));
        }
Ejemplo n.º 8
0
 protected internal abstract Task HandleAsync(
     IKernelCommand command,
     KernelPipelineContext context);
Ejemplo n.º 9
0
 public async Task SendOnContextAsync(
     IKernelCommand command,
     KernelPipelineContext invocationContext)
 {
     await Pipeline.InvokeAsync(command, invocationContext);
 }