コード例 #1
0
        private async Task RunServer()
        {
            this.container.Logger().Info("Starting CLI server");

            this.cancellationTokenSource = new CancellationTokenSource();

            while (true)
            {
                try {
                    using (var pipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) {
                        await pipe.WaitForConnectionAsync(this.cancellationTokenSource.Token);

                        PXCliCommand command = (PXCliCommand)formatter.Deserialize(pipe);

                        ExecuteInCliScope(delegate(IResolverContext context) {
                            this.container.Handlers().HandleCliCommand(command, context);
                        });

                        formatter.Serialize(pipe, command.FlushOutput());
                    }
                } catch (OperationCanceledException) {
                    break;
                } catch (Exception e) {
                    this.container.Errors().Handle(e, Services.PXErrorHandlingService.Scope.CliCommand);
                }
            }
        }
コード例 #2
0
        public async Task Send(PXCliCommand command)
        {
            using (var pipe = new NamedPipeClientStream(this.pipeName)) {
                await pipe.ConnectAsync();

                formatter.Serialize(pipe, command);

                string output = (string)formatter.Deserialize(pipe);

                if (output.Length > 0)
                {
                    OnOutput(output);
                }
            }
        }