Ejemplo n.º 1
0
        public KernelServer(
            Kernel kernel,
            IInputTextStream input,
            IOutputTextStream output,
            DirectoryInfo workingDir)
        {
            _kernel = kernel ?? throw new ArgumentNullException(nameof(kernel));
            _input  = input ?? throw new ArgumentNullException(nameof(input));
            _output = output ?? throw new ArgumentNullException(nameof(output));

            if (workingDir is null)
            {
                throw new ArgumentNullException(nameof(workingDir));
            }

            _disposables = new CompositeDisposable
            {
                _input.Subscribe(async line =>
                {
                    await DeserializeAndSendCommand(line);
                }),
                _kernel.KernelEvents.Subscribe(WriteEventToOutput),
                _input
            };

            Environment.CurrentDirectory = workingDir.FullName;
            WriteEventToOutput(new KernelReady());
        }
Ejemplo n.º 2
0
        public KernelStreamClient(IKernel kernel, IInputTextStream input, IOutputTextStream output)
        {
            _disposables = new CompositeDisposable();
            _kernel      = kernel ?? throw new ArgumentNullException(nameof(kernel));
            _input       = input ?? throw new ArgumentNullException(nameof(input));
            _output      = output ?? throw new ArgumentNullException(nameof(output));
            _disposables.Add(
                _input.Subscribe(async line => { await ParseLine(line); }));
            _disposables.Add(
                _kernel.KernelEvents.Subscribe(e =>
            {
                switch (e)
                {
                case KernelBusy _:
                case KernelIdle _:
                    break;

                default:
                    {
                        var id = (int)e.GetRootCommand().Properties["id"];
                        Write(e, id);
                    }
                    break;
                }
            }));
        }
Ejemplo n.º 3
0
        public KernelClient(
            IInputTextStream input,
            IOutputTextStream output)
        {
            _input  = input ?? throw new ArgumentNullException(nameof(input));
            _output = output ?? throw new ArgumentNullException(nameof(output));

            _disposables = new CompositeDisposable
            {
                _input.Subscribe(DeserializeAndSendEvent)
            };
        }