public static INodeEndpointProtocolServer WaitForServer <T>(
            this INodeEndpointProtocolServerListener serverListener,
            string address,
            IDuplexNodeEndpoint <T> endpoint,
            int timeout = DefaultTimeout
            )
            where T : INodeEndpointClient
        {
            INodeEndpointProtocolServer server = WaitForServerBase(serverListener, address, endpoint, timeout);

            if (server != null)
            {
                if (server.EnableDuplex)
                {
                    INodeEndpointClientProvider provider = new ProtocolEnabledClientProvider();
                    provider.Protocol = server;
                    T endpointInterface = StrongTypedNodeEndpointClientBuilder.Create <T>(provider);
                    endpoint.Callback = endpointInterface;
                }
                else
                {
                    server.Disconnect();
                    throw new InvalidOperationException("The protocol does not support duplex communication.");
                }
                server.BeginListen();
            }
            return(server);
        }
예제 #2
0
        public void TestSimpleEndpointClientThrowException()
        {
            CalculationEndpoint calculation = new CalculationEndpoint(false);

            Assert.AreEqual("Calculation", calculation.EndpointName);
            Assert.AreEqual(false, calculation.EnableAsynchronization);

            PrimitiveEndpointClientProvider provider            = new PrimitiveEndpointClientProvider(calculation);
            ICalculationEndpoint            calculationEndpoint = StrongTypedNodeEndpointClientBuilder.Create <ICalculationEndpoint>(provider);

            calculationEndpoint.ThrowException();
        }
예제 #3
0
        public void TestSimpleEndpointClient()
        {
            CalculationEndpoint calculation = new CalculationEndpoint(false);

            Assert.AreEqual("Calculation", calculation.EndpointName);
            Assert.AreEqual(false, calculation.EnableAsynchronization);

            PrimitiveEndpointClientProvider provider            = new PrimitiveEndpointClientProvider(calculation);
            ICalculationEndpoint            calculationEndpoint = StrongTypedNodeEndpointClientBuilder.Create <ICalculationEndpoint>(provider);

            Assert.AreEqual(3, calculationEndpoint.Add(2, 1));
            Assert.AreEqual(1, calculationEndpoint.Sub(2, 1));
            Assert.AreEqual(2, calculationEndpoint.Mul(2, 1));
            Assert.AreEqual(2, calculationEndpoint.Div(2, 1));

            calculationEndpoint.SendMessage("Vczh is a genius!");
            Assert.AreEqual("Vczh is a genius!", calculationEndpoint.ReceiveMessage());
            Assert.AreEqual("Vczh is a genius!", calculation.Message);
        }
        public static T WaitForClient <T>(
            this INodeEndpointProtocolFactory protocolFactory,
            string address,
            string endpointName,
            int timeout = DefaultTimeout
            )
            where T : INodeEndpointClient
        {
            INodeEndpointProtocolClient client = protocolFactory.CreateClient();

            if (client.Connect(address, endpointName, timeout))
            {
                INodeEndpointClientProvider provider = new ProtocolEnabledClientProvider();
                provider.Protocol = client;
                T endpointInterface = StrongTypedNodeEndpointClientBuilder.Create <T>(provider);
                client.BeginListen();
                return(endpointInterface);
            }
            else
            {
                return(default(T));
            }
        }