示例#1
0
        public async Task InvokeAsync(
            IKernelCommand command,
            KernelPipelineContext context)
        {
            EnsureMiddlewarePipelineIsInitialized();

            await _pipeline(command, context, (_, __) => Task.CompletedTask);
        }
示例#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();
        }
示例#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;
            }
        }
示例#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];
         }
     }
 }
示例#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());
        }
示例#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);
        }
示例#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));
        }
示例#8
0
 protected internal abstract Task HandleAsync(
     IKernelCommand command,
     KernelPipelineContext context);
示例#9
0
 public async Task SendOnContextAsync(
     IKernelCommand command,
     KernelPipelineContext invocationContext)
 {
     await Pipeline.InvokeAsync(command, invocationContext);
 }