예제 #1
0
        public void Add(IKernel kernel)
        {
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            if (ChildKernels.Any(k => k.Name == kernel.Name))
            {
                throw new ArgumentException($"Kernel \"{kernel.Name}\" already registered", nameof(kernel));
            }

            _childKernels.Add(kernel);

            var chooseKernelCommand = new Command($"%%{kernel.Name}");

            chooseKernelCommand.Handler =
                CommandHandler.Create <KernelInvocationContext>(context =>
            {
                context.HandlingKernel = kernel;
            });

            AddDirective(chooseKernelCommand);

            RegisterForDisposal(kernel.KernelEvents.Subscribe(PublishEvent));

            RegisterForDisposal(kernel);
        }
예제 #2
0
        public void Add(IKernel kernel)
        {
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            if (ChildKernels.Any(k => k.Name == kernel.Name))
            {
                throw new ArgumentException($"Kernel \"{kernel.Name}\" already registered", nameof(kernel));
            }

            _childKernels.Add(kernel);

            if (kernel is KernelBase kernelBase)
            {
                kernelBase.Pipeline.AddMiddleware(async(command, context, next) =>
                {
                    await next(command, context);
                    while (_packages.TryDequeue(out var packageAdded))
                    {
                        var loadExtensionsInDirectory =
                            new LoadExtensionsInDirectory(packageAdded.PackageReference.PackageRoot, Name);
                        await this.SendAsync(loadExtensionsInDirectory);
                    }
                });
            }

            var chooseKernelCommand = new Command($"%%{kernel.Name}")
            {
                Handler = CommandHandler.Create <KernelInvocationContext>(
                    context => { context.HandlingKernel = kernel; })
            };

            AddDirective(chooseKernelCommand);
            RegisterForDisposal(kernel.KernelEvents.Subscribe(PublishEvent));
            RegisterForDisposal(kernel);
        }