Exemplo n.º 1
0
        public void TestDuplexChannels()
        {
            string pipeName = "Vkm.TestPipe3";

            var service  = new Test1();
            var callback = new Test2();

            var master = new IntercomDuplexChannel <Test1, Test2>(service, pipeName, true);
            var slave  = new IntercomDuplexChannel <Test2, Test1>(callback, pipeName, false);

            Assert.AreEqual(0, service.MethodCallCount);
            var r = slave.Execute(nameof(Test1.Do), 5, 1);

            Assert.AreEqual(1, service.MethodCallCount);
            Assert.AreEqual(5, r);

            Assert.AreEqual(0, callback.MethodCallCount);
            r = master.Execute(nameof(Test2.Do));
            Assert.AreEqual(1, callback.MethodCallCount);
            Assert.AreEqual(string.Empty, r);
        }
Exemplo n.º 2
0
        public string Dispatch()
        {
            var pipeName = $"{_pipeName}_{Guid.NewGuid()}";

            var service          = _serviceFactory();
            var newDuplexChannel = new IntercomDuplexChannel <TService, TCallback>(service, pipeName, true);

            if (service is IRemoteServiceWithCallback withCallback)
            {
                withCallback.RegisterChannel(newDuplexChannel);
            }

            if (service is IDisposable disposableService)
            {
                newDuplexChannel.ConnectionClosed += (sender, args) => disposableService.Dispose();
            }

            _dispatchedChannels.Add(newDuplexChannel);

            newDuplexChannel.ConnectionClosed += OnConnectionClosed;

            return(pipeName);
        }
Exemplo n.º 3
0
 private VkmIntercomClient(IntercomDuplexChannel <IVkmRemoteCallback, IVkmRemoteService> channel)
 {
     _channel = channel;
 }