Exemplo n.º 1
0
        public void DynamicRpcNonGenericEvent_10000()
        {
            RpcFactory           anRpcFactory = new RpcFactory(mySerializer);
            HelloService         aService     = new HelloService();
            IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService);
            IRpcClient <IHello>  anRpcClient  = anRpcFactory.CreateClient <IHello>();

            try
            {
                anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId));
                anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId));

                int                      aCounter        = 0;
                AutoResetEvent           anEventReceived = new AutoResetEvent(false);
                EventHandler <EventArgs> anEventHandler  = (x, y) =>
                {
                    ++aCounter;
                    if (aCounter == 10000)
                    {
                        anEventReceived.Set();
                    }
                };

                // Subscribe.
                anRpcClient.SubscribeRemoteEvent("Close", anEventHandler);

                Stopwatch aStopWatch = new Stopwatch();
                aStopWatch.Start();

                // Raise the event in the service.
                for (int i = 0; i < 10000; ++i)
                {
                    aService.RaiseClose();
                }

                aStopWatch.Stop();
                Console.WriteLine("Remote event. Elapsed time = " + aStopWatch.Elapsed);

                Assert.IsTrue(anEventReceived.WaitOne());

                // Unsubscribe.
                anRpcClient.UnsubscribeRemoteEvent("Close", anEventHandler);
            }
            finally
            {
                if (anRpcClient.IsDuplexOutputChannelAttached)
                {
                    anRpcClient.DetachDuplexOutputChannel();
                }

                if (anRpcService.IsDuplexInputChannelAttached)
                {
                    anRpcService.DetachDuplexInputChannel();
                }
            }
        }
Exemplo n.º 2
0
        public void DynamicRpcGenericEvent()
        {
            RpcFactory           anRpcFactory = new RpcFactory(mySerializer);
            HelloService         aService     = new HelloService();
            IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService);
            IRpcClient <IHello>  anRpcClient  = anRpcFactory.CreateClient <IHello>();

            try
            {
                anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId));
                anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId));

                AutoResetEvent          anEventReceived = new AutoResetEvent(false);
                string                  aReceivedEvent  = "";
                EventHandler <OpenArgs> anEventHandler  = (x, y) =>
                {
                    aReceivedEvent = y.Name;
                    anEventReceived.Set();
                };

                // Subscribe.
                anRpcClient.SubscribeRemoteEvent("Open", anEventHandler);

                // Raise the event in the service.
                OpenArgs anOpenArgs = new OpenArgs()
                {
                    Name = "Hello"
                };
                aService.RaiseOpen(anOpenArgs);

                Assert.IsTrue(anEventReceived.WaitOne());
                Assert.AreEqual("Hello", aReceivedEvent);

                // Unsubscribe.
                anRpcClient.UnsubscribeRemoteEvent("Open", anEventHandler);

                // Try to raise again.
                aService.RaiseOpen(anOpenArgs);

                Assert.IsFalse(anEventReceived.WaitOne(1000));
            }
            finally
            {
                if (anRpcClient.IsDuplexOutputChannelAttached)
                {
                    anRpcClient.DetachDuplexOutputChannel();
                }

                if (anRpcService.IsDuplexInputChannelAttached)
                {
                    anRpcService.DetachDuplexInputChannel();
                }
            }
        }
Exemplo n.º 3
0
        public void DynamicRpcNonGenericEvent()
        {
            RpcFactory           anRpcFactory = new RpcFactory(mySerializer);
            HelloService         aService     = new HelloService();
            IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService);
            IRpcClient <IHello>  anRpcClient  = anRpcFactory.CreateClient <IHello>();

            try
            {
                anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId));
                anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId));

                AutoResetEvent           anEventReceived = new AutoResetEvent(false);
                EventHandler <EventArgs> anEventHandler  = (x, y) =>
                {
                    anEventReceived.Set();
                };

                // Subscribe.
                anRpcClient.SubscribeRemoteEvent <EventArgs>("Close", anEventHandler);

                // Raise the event in the service.
                aService.RaiseClose();

                Assert.IsTrue(anEventReceived.WaitOne());

                // Unsubscribe.
                anRpcClient.UnsubscribeRemoteEvent("Close", anEventHandler);

                // Try to raise again.
                aService.RaiseClose();

                Assert.IsFalse(anEventReceived.WaitOne(1000));
            }
            finally
            {
                if (anRpcClient.IsDuplexOutputChannelAttached)
                {
                    anRpcClient.DetachDuplexOutputChannel();
                }

                if (anRpcService.IsDuplexInputChannelAttached)
                {
                    anRpcService.DetachDuplexInputChannel();
                }
            }
        }