public static async Task NamedPipeMessagesAreSentAndReceived()
        {
            using var waitHandle = new AutoResetEvent(false);

            using var receiver = new NamedPipeReceiver("foo", "test-pipe");
            var payload     = string.Empty;
            var headerValue = string.Empty;

            receiver.Start(async m =>
            {
                payload     = m.StringPayload;
                headerValue = m.Headers.GetValue <string>("bar");
                await m.AcknowledgeAsync().ConfigureAwait(false);
                waitHandle.Set();
            });

            using (var sender = new NamedPipeSender("foo", "test-pipe"))
            {
                await sender.SendAsync(new SenderMessage("Hello, world!") { Headers = { { "bar", "abc" } } }).ConfigureAwait(false);

                waitHandle.WaitOne();
            }

            Assert.Equal("Hello, world!", payload);
            Assert.Equal("abc", headerValue);
        }
        public void NamedPipeMessagesAreSentAndReceived()
        {
            var waitHandle = new AutoResetEvent(false);

            using (var receiver = new NamedPipeReceiver("foo", "test-pipe"))
            {
                string payload     = null;
                string headerValue = null;

                receiver.Start(async m =>
                {
                    payload     = m.StringPayload;
                    headerValue = m.Headers.GetValue <string>("bar");
                    await m.AcknowledgeAsync();
                    waitHandle.Set();
                });

                using (var sender = new NamedPipeSender("foo", "test-pipe"))
                {
                    sender.Send(new SenderMessage("Hello, world!")
                    {
                        Headers = { { "bar", "abc" } }
                    });
                }

                waitHandle.WaitOne();

                Assert.Equal("Hello, world!", payload);
                Assert.Equal("abc", headerValue);
            }
        }
Esempio n. 3
0
        public void Init()
        {
            RefreshReceiver();

            Log("Connecting to " + RECEIVERPIPENAME);
            messageSender = new NamedPipeSender(RECEIVERPIPENAME);
            Log("Created Sender");
            string request  = "REGISTER " + Process.GetCurrentProcess().Id;
            var    response = messageSender.SendRequest(request);

            Log("Response: " + response);
        }