예제 #1
0
        public static int RunTest()
        {
            // Duplex TCP Channel
            var protocol = new TcpDuplexClientProtocolSetup(true)
            {
                CompressionThreshold = 1, // compress data packets of any size
                CompressionMethod = CompressionMethod.DeflateStream
            };

            _connectionDuplex = new ZyanConnection("tcpex://localhost:8084/TcpDuplexEventTest", protocol);

            _proxySingletonDuplex = _connectionDuplex.CreateProxy<IEventComponentSingleton>();
            _proxySingleCallDuplex = _connectionDuplex.CreateProxy<IEventComponentSingleCall>();
            _proxyCallbackSingletonDuplex = _connectionDuplex.CreateProxy<ICallbackComponentSingleton>();
            _proxyCallbackSingleCallDuplex = _connectionDuplex.CreateProxy<ICallbackComponentSingleCall>();
            _proxyRequestResponseSingleCallDuplex = _connectionDuplex.CreateProxy<IRequestResponseCallbackSingleCall>();
            _proxyTimerTriggeredEvent = _connectionDuplex.CreateProxy<ITimerTriggeredEvent>();

            _proxyTimerTriggeredEvent.StartTimer();

            List<int> stepsDone = new List<int>();

            _proxyCallbackSingletonDuplex.Out_Callback = CallBackSingletonDuplex;
            _proxyCallbackSingleCallDuplex.Out_Callback = CallBackSingleCallDuplex;

            _proxyCallbackSingletonDuplex.DoSomething();
            if (_callbackCountSingletonDuplex == 1)
            {
                stepsDone.Add(1);
                Console.WriteLine("[TCP Duplex] Singleton Callback Test passed.");
            }
            _proxyCallbackSingleCallDuplex.DoSomething();
            if (_callbackCountSingleCallDuplex == 1)
            {
                stepsDone.Add(2);
                Console.WriteLine("[TCP Duplex] SingleCall Callback Test passed.");
            }

            RegisterEventsDuplex();

            if (_registrationsSingletonDuplex == _proxySingletonDuplex.Registrations)
                stepsDone.Add(3);
            if (_registrationsSingleCallDuplex == _proxySingleCallDuplex.Registrations)
                stepsDone.Add(4);

            _proxySingletonDuplex.TriggerEvent();
            if (_firedCountSingletonDuplex == 1)
            {
                stepsDone.Add(5);
                Console.WriteLine("[TCP Duplex] Singleton Event Test passed.");
            }

            _proxySingleCallDuplex.TriggerEvent();
            if (_firedCountSingleCallDuplex == 1)
            {
                stepsDone.Add(6);
                Console.WriteLine("[TCP Duplex] SingleCall Event Test passed.");
            }

            Thread.Sleep(1000);

            if (_firedTimerTriggeredEvent > 1)
            {
                stepsDone.Add(7);
                Console.WriteLine("[TCP Duplex] Timer triggered Event Test passed.");
            }

            UnregisterEventsDuplex();

            if (_registrationsSingletonDuplex == _proxySingletonDuplex.Registrations)
                stepsDone.Add(8);
            if (_registrationsSingleCallDuplex == _proxySingleCallDuplex.Registrations)
                stepsDone.Add(9);

            RequestResponseResult requestResponseResult = new RequestResponseResult("TCP Duplex");

            _proxyRequestResponseSingleCallDuplex.DoRequestResponse("Success", requestResponseResult.ReceiveResponseSingleCall);

            Thread.Sleep(1000);

            if (requestResponseResult.Count == 1)
                stepsDone.Add(10);

            _connectionDuplex.Dispose();

            if (stepsDone.Count == 10)
                return 0;
            else
                return 1;
        }
예제 #2
0
        public static int RunTest()
        {
            // Duplex TCP Channel
            var protocol = new TcpDuplexClientProtocolSetup(true)
            {
                CompressionThreshold = 1,                 // compress data packets of any size
                CompressionMethod    = CompressionMethod.DeflateStream
            };

            _connectionDuplex = new ZyanConnection("tcpex://localhost:8084/TcpDuplexEventTest", protocol);

            _proxySingletonDuplex                 = _connectionDuplex.CreateProxy <IEventComponentSingleton>();
            _proxySingleCallDuplex                = _connectionDuplex.CreateProxy <IEventComponentSingleCall>();
            _proxyCallbackSingletonDuplex         = _connectionDuplex.CreateProxy <ICallbackComponentSingleton>();
            _proxyCallbackSingleCallDuplex        = _connectionDuplex.CreateProxy <ICallbackComponentSingleCall>();
            _proxyRequestResponseSingleCallDuplex = _connectionDuplex.CreateProxy <IRequestResponseCallbackSingleCall>();
            _proxyTimerTriggeredEvent             = _connectionDuplex.CreateProxy <ITimerTriggeredEvent>();

            _proxyTimerTriggeredEvent.StartTimer();

            List <int> stepsDone = new List <int>();

            _proxyCallbackSingletonDuplex.Out_Callback  = CallBackSingletonDuplex;
            _proxyCallbackSingleCallDuplex.Out_Callback = CallBackSingleCallDuplex;

            _proxyCallbackSingletonDuplex.DoSomething();
            if (_callbackCountSingletonDuplex == 1)
            {
                stepsDone.Add(1);
                Console.WriteLine("[TCP Duplex] Singleton Callback Test passed.");
            }
            _proxyCallbackSingleCallDuplex.DoSomething();
            if (_callbackCountSingleCallDuplex == 1)
            {
                stepsDone.Add(2);
                Console.WriteLine("[TCP Duplex] SingleCall Callback Test passed.");
            }

            RegisterEventsDuplex();

            if (_registrationsSingletonDuplex == _proxySingletonDuplex.Registrations)
            {
                stepsDone.Add(3);
            }
            if (_registrationsSingleCallDuplex == _proxySingleCallDuplex.Registrations)
            {
                stepsDone.Add(4);
            }

            _proxySingletonDuplex.TriggerEvent();
            if (_firedCountSingletonDuplex == 1)
            {
                stepsDone.Add(5);
                Console.WriteLine("[TCP Duplex] Singleton Event Test passed.");
            }

            _proxySingleCallDuplex.TriggerEvent();
            if (_firedCountSingleCallDuplex == 1)
            {
                stepsDone.Add(6);
                Console.WriteLine("[TCP Duplex] SingleCall Event Test passed.");
            }

            Thread.Sleep(1000);

            if (_firedTimerTriggeredEvent > 1)
            {
                stepsDone.Add(7);
                Console.WriteLine("[TCP Duplex] Timer triggered Event Test passed.");
            }

            UnregisterEventsDuplex();

            if (_registrationsSingletonDuplex == _proxySingletonDuplex.Registrations)
            {
                stepsDone.Add(8);
            }
            if (_registrationsSingleCallDuplex == _proxySingleCallDuplex.Registrations)
            {
                stepsDone.Add(9);
            }

            RequestResponseResult requestResponseResult = new RequestResponseResult("TCP Duplex");

            _proxyRequestResponseSingleCallDuplex.DoRequestResponse("Success", requestResponseResult.ReceiveResponseSingleCall);

            Thread.Sleep(1000);

            if (requestResponseResult.Count == 1)
            {
                stepsDone.Add(10);
            }

            _connectionDuplex.Dispose();

            if (stepsDone.Count == 10)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }