示例#1
0
文件: Program.cs 项目: yallie/zyan
        static void Main(string[] args)
        {
            System.Console.Write("Nickname: ");
            _nickName = System.Console.ReadLine();

            System.Console.WriteLine("-----------------------------------------------");

            Hashtable credentials = new Hashtable();
            credentials.Add("nickname", _nickName);

            ZyanConnection connection = null;
            TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true);

            try
            {
                connection = new ZyanConnection(Properties.Settings.Default.ServerUrl, protocol, credentials, false, true);
            }
            catch (SecurityException ex)
            {
                System.Console.WriteLine(ex.Message);
                System.Console.ReadLine();
                return;
            }

            connection.CallInterceptors.For<IMiniChat>().Add(
                (IMiniChat chat, string nickname, string message) => chat.SendMessage(nickname, message),
                (data, nickname, message) =>
                {
                    if (message.Contains("f**k") || message.Contains("sex"))
                    {
                        System.Console.WriteLine("TEXT CONTAINS FORBIDDEN WORDS!");
                        data.Intercepted = true;
                    }
                });

            connection.CallInterceptionEnabled = true;

            IMiniChat chatProxy = connection.CreateProxy<IMiniChat>();
            chatProxy.MessageReceived += new Action<string, string>(chatProxy_MessageReceived);

            string text = string.Empty;

            while (text.ToLower() != "quit")
            {
                text = System.Console.ReadLine();
                chatProxy.SendMessage(_nickName, text);
            }

            chatProxy.MessageReceived -= new Action<string, string>(chatProxy_MessageReceived);
            connection.Dispose();
        }
        public void CreateDisposeAndRecreateConnectionUsingTcpDuplexChannel()
        {
            string url = "tcpex://localhost:8084/RecreateClientConnectionTestHost_TcpDuplex";
            var protocol = new TcpDuplexClientProtocolSetup(true);

            using (var connection = new ZyanConnection(url, protocol))
            {
                var proxy1 = connection.CreateProxy<ISampleServer>("SampleServer");
                Assert.AreEqual("Hallo", proxy1.Echo("Hallo"));
                proxy1 = null;
            }

            using (var connection = new ZyanConnection(url, protocol))
            {
                var proxy2 = connection.CreateProxy<ISampleServer>("SampleServer");
                Assert.AreEqual("Hallo", proxy2.Echo("Hallo"));
            }
        }
示例#3
0
文件: Program.cs 项目: yallie/zyan
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string nickname = string.Empty;
            string serverUrl = string.Empty;

            LoginForm loginForm = new LoginForm();

            while (string.IsNullOrEmpty(nickname) || string.IsNullOrEmpty(serverUrl))
            {
                if (loginForm.ShowDialog() != DialogResult.OK)
                    break;

                nickname = loginForm.Nickname;
                serverUrl = loginForm.ServerUrl;
            }

            if (string.IsNullOrEmpty(nickname))
                return;

            Credentials = new Hashtable();
            Credentials.Add("nickname", nickname);

            TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true);

            try
            {
                using (Connection = new ZyanConnection(serverUrl, protocol, Credentials, false, true))
                {
                    Connection.PollingInterval = new TimeSpan(0, 0, 30);
                    Connection.PollingEnabled = true;
                    Connection.Disconnected += new EventHandler<DisconnectedEventArgs>(Connection_Disconnected);
                    Connection.NewLogonNeeded += new EventHandler<NewLogonNeededEventArgs>(Connection_NewLogonNeeded);
                    Connection.Error += new EventHandler<ZyanErrorEventArgs>(Connection_Error);

                    Connection.CallInterceptors.For<IMiniChat>()
                        .Add<string, string>(
                            (chat, nickname2, text) => chat.SendMessage(nickname2, text),
                            (data, nickname2, text) =>
                            {
                                if (text.Contains("f**k") || text.Contains("sex"))
                                {
                                    MessageBox.Show("TEXT CONTAINS FORBIDDEN WORDS!");
                                    data.Intercepted = true;
                                }
                            });

                    Connection.CallInterceptionEnabled = true;

                    Application.Run(new ChatForm(nickname));
                }
            }
            catch (SecurityException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#4
0
文件: MainForm.cs 项目: yallie/zyan
 private void MainForm_Shown(object sender, EventArgs e)
 {
     var protocol = new TcpDuplexClientProtocolSetup(true);
     _connection = new ZyanConnection(Properties.Settings.Default.ServerUrl, protocol);
     _proxy = _connection.CreateProxy<IWhisperChatService>();
 }
示例#5
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;
        }
示例#6
0
 public void TcpDuplexUrlValidation()
 {
     var protocol = new TcpDuplexClientProtocolSetup();
     Assert.IsTrue(protocol.IsUrlValid("tcpex://localhost:123/server"));
     Assert.IsTrue(protocol.IsUrlValid("tcpex://www.example.com:8080/server"));
     Assert.IsTrue(protocol.IsUrlValid("tcpex://127.0.0.1:8888/index"));
     Assert.IsTrue(protocol.IsUrlValid("tcpex://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index"));
     Assert.IsFalse(protocol.IsUrlValid(null));
     Assert.IsFalse(protocol.IsUrlValid(string.Empty));
     Assert.IsFalse(protocol.IsUrlValid("tcpex://"));
     Assert.IsFalse(protocol.IsUrlValid("tcpex://host/server"));
 }