Beispiel #1
0
        private static void RunDemoHub(HubConnection hubConnection)
        {
            var demo = hubConnection.CreateProxy("demo");

            hubConnection.StateChanged += change =>
            {
                Console.WriteLine(change.OldState + " => " + change.NewState);
            };

            demo.On<int>("invoke", i =>
            {
                int n = demo.GetValue<int>("index");
                Console.WriteLine("{0} client state index -> {1}", i, n);
            });

            hubConnection.Start().Wait();

            demo.Invoke("multipleCalls").ContinueWith(task =>
            {
                using (var error = task.Exception.GetError())
                {
                    Console.WriteLine(error);
                }

            }, TaskContinuationOptions.OnlyOnFaulted);

            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(7000);
                hubConnection.Stop();
            });
        }
Beispiel #2
0
        private static async Task RunAsync()
        {
            var connection = new HubConnection("http://localhost:17318/");
            IHubProxy chat = connection.CreateProxy("Chat");

            chat.On<string>("send", Console.WriteLine);

            await connection.Start();

            string line = null;
            while ((line = Console.ReadLine()) != null)
            {
                await chat.Invoke("send", "Console: " + line);
            }
        }
Beispiel #3
0
        public void HubNamesAreNotCaseSensitive()
        {
            var host = new MemoryHost();
            host.MapHubs();

            var hubConnection = new HubConnection("http://fake");
            IHubProxy proxy = hubConnection.CreateProxy("chatHub");
            var wh = new ManualResetEvent(false);

            proxy.On("addMessage", data =>
            {
                Assert.Equal("hello", data);
                wh.Set();
            });

            hubConnection.Start(host).Wait();

            proxy.Invoke("Send", "hello").Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
        }
Beispiel #4
0
        public void UnableToCreateHubThrowsError()
        {
            var host = new MemoryHost();
            host.MapHubs();

            var hubConnection = new HubConnection("http://fake");
            IHubProxy proxy = hubConnection.CreateProxy("MyHub2");

            hubConnection.Start(host).Wait();
            Assert.Throws<MissingMethodException>(() => proxy.Invoke("Send", "hello").Wait());
        }