示例#1
0
        public KernelServerTests(ITestOutputHelper output)
        {
            var kernel = new CompositeKernel
            {
                new CSharpKernel()
                .UseKernelHelpers()
                .UseNugetDirective()
                .UseDefaultFormatting()
                .UseDefaultMagicCommands()
            };


            _kernelServer = kernel.CreateKernelServer(new StreamReader(new MemoryStream()), new StringWriter(), new DirectoryInfo(Environment.CurrentDirectory));

            _kernelEvents = _kernelServer
                            .Output
                            .Where(s => !string.IsNullOrWhiteSpace(s))
                            .Select(KernelEventEnvelope.Deserialize)
                            .ToSubscribedList();

            _disposables.Add(_kernelServer);
            _disposables.Add(output.SubscribeToPocketLogger());
            _disposables.Add(kernel.LogEventsToPocketLogger());
            _disposables.Add(kernel);
        }
示例#2
0
        public static async Task <int> Do(StartupOptions startupOptions, KernelServer kernelServer, IConsole console)
        {
            var disposable = Program.StartToolLogging(startupOptions);

            kernelServer.Start();
            await kernelServer.Input.LastOrDefaultAsync();

            return(0);
        }
示例#3
0
        public static Task WriteAsync(
            this KernelServer server,
            KernelCommand command)
        {
            var json = KernelCommandEnvelope.Serialize(
                KernelCommandEnvelope.Create(command));

            return(server.WriteAsync(json));
        }
示例#4
0
        public static async Task <int> Do(StartupOptions startupOptions, KernelServer kernelServer, IConsole console)
        {
            var disposable = Program.StartToolLogging(startupOptions);
            var run        = kernelServer.RunAsync();

            kernelServer.NotifyIsReady();
            await run;

            return(0);
        }
示例#5
0
        public static KernelServer CreateKernelServer(this Kernel kernel, TextReader inputStream, TextWriter outputStream, DirectoryInfo workingDir)
        {
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            var input        = new TextReaderInputStream(inputStream);
            var output       = new TextWriterOutputStream(outputStream);
            var kernelServer = new KernelServer(kernel, input, output, workingDir);

            kernel.RegisterForDisposal(kernelServer);
            return(kernelServer);
        }