Beispiel #1
0
        public async Task Start()
        {
            using var pipeInStream    = streamFactory.CreateAnonymousPipeClientStream(PipeDirection.In, inputData.PipeInName);
            using var pipeOutStream   = streamFactory.CreateAnonymousPipeClientStream(PipeDirection.Out, inputData.PipeOutName);
            using var pipeEventStream = streamFactory.CreateAnonymousPipeClientStream(PipeDirection.Out, inputData.PipeEventName);

            eventService.Subscribe(pipeEventStream);

            try
            {
                var done = false;

                while (!done)
                {
                    await pipeInStream.ReadAsync(new byte[0], 0, 0);

                    var message = messageSerializer.DeserializeWithLengthPrefix <BaseRequest>(pipeInStream, PrefixStyle.Base128);

                    if (message == null)
                    {
                        throw new InvalidOperationException($"No data in pipe.");
                    }

                    logger.LogDebug("Got message with {Type} and {Sequence}", message.GetType(), message.SequenceNumber);
                    done = messageService.Process(message, pipeEventStream, pipeOutStream);
                }
                logger.LogInformation($"Handled message of Type Quit");
            }
            catch (EndOfStreamException) { logger.LogInformation("End of stream"); }
        }