当前位置: 首页>>代码示例>>C#>>正文


C# Hubs.HubConnection类代码示例

本文整理汇总了C#中Client.Hubs.HubConnection的典型用法代码示例。如果您正苦于以下问题:C# Client.Hubs.HubConnection类的具体用法?C# Client.Hubs.HubConnection怎么用?C# Client.Hubs.HubConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Client.Hubs.HubConnection类属于命名空间,在下文中一共展示了Client.Hubs.HubConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BasicAuthCredentialsFlow

        public void BasicAuthCredentialsFlow(TransportType transportType)
        {
            using (var host = new OwinTestHost())
            {
                Debug.Listeners.Clear();

                host.Start<BasicAuthApplication>();

                var connection = new Client.Hubs.HubConnection(host.Url);

                var hub = connection.CreateHubProxy("demo");

                hub["name"] = "test";

                connection.Credentials = new System.Net.NetworkCredential("user", "password");

                connection.Start(CreateTransport(transportType)).Wait();

                var result = hub.InvokeWithTimeout<string>("ReadStateValue");

                Assert.Equal("test", result);

                connection.Stop();
            }
        }
开发者ID:khalidabuhakmeh,项目名称:SignalR,代码行数:25,代码来源:HubFacts.cs

示例2: AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedWithRoles

        public void AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedWithRoles()
        {
            using (var host = new MemoryHost())
            {
                host.MapHubs();
                var connection = new Client.Hubs.HubConnection("http://foo/");

                host.User = new GenericPrincipal(new GenericIdentity("test"), new string[] { "Admin" });

                var hub = connection.CreateHubProxy("AdminAuthHub");
                var wh = new ManualResetEvent(false);
                hub.On<string, string>("invoked", (id, time) =>
                {
                    Assert.NotNull(id);
                    wh.Set();
                });

                connection.Start(host).Wait();

                hub.InvokeWithTimeout("InvokedFromClient");

                Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
                connection.Stop();
            }
        }
开发者ID:rustd,项目名称:SignalR,代码行数:25,代码来源:HubAuthFacts.cs

示例3: ChangeHubUrl

        public void ChangeHubUrl()
        {
            using (var host = new MemoryHost())
            {
                host.MapHubs("/foo");
                var connection = new Client.Hubs.HubConnection("http://site/foo", useDefaultUrl: false);

                var hub = connection.CreateHubProxy("demo");

                var wh = new ManualResetEventSlim(false);

                hub.On("signal", id =>
                {
                    Assert.NotNull(id);
                    wh.Set();
                });

                connection.Start(host).Wait();

                hub.Invoke("DynamicTask").Wait();

                Assert.True(wh.Wait(TimeSpan.FromSeconds(10)));
                connection.Stop();
            }
        }
开发者ID:kppullin,项目名称:SignalR,代码行数:25,代码来源:HubFacts.cs

示例4: RunConnectDisconnect

        public static IDisposable RunConnectDisconnect(int connections)
        {
            var host = new MemoryHost();

            host.MapHubs();

            for (int i = 0; i < connections; i++)
            {
                var connection = new Client.Hubs.HubConnection("http://foo");
                var proxy = connection.CreateHubProxy("EchoHub");
                var wh = new ManualResetEventSlim(false);

                proxy.On("echo", _ => wh.Set());

                try
                {
                    connection.Start(host).Wait();

                    proxy.Invoke("Echo", "foo").Wait();

                    if (!wh.Wait(TimeSpan.FromSeconds(10)))
                    {
                        Debugger.Break();
                    }
                }
                finally
                {
                    connection.Stop();
                }
            }

            return host;
        }
开发者ID:nonintanon,项目名称:SignalR,代码行数:33,代码来源:StressRuns.cs

示例5: AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedSpecifyingUserAndRole

        public void AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedSpecifyingUserAndRole()
        {
            using (var host = new MemoryHost())
            {
                host.Configure(app =>
                {
                    var configuration = new HubConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    WithUser(app, new GenericPrincipal(new GenericIdentity("User"), new string[] { "Admin" }));
                    app.MapHubs("/signalr", configuration);
                });

                var connection = new Client.Hubs.HubConnection("http://foo/");

                var hub = connection.CreateHubProxy("UserAndRoleAuthHub");
                var wh = new ManualResetEvent(false);
                hub.On<string, string>("invoked", (id, time) =>
                {
                    Assert.NotNull(id);
                    wh.Set();
                });

                connection.Start(host).Wait();

                hub.InvokeWithTimeout("InvokedFromClient");

                Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
                connection.Stop();
            }
        }
开发者ID:Jozef89,项目名称:SignalR,代码行数:33,代码来源:HubAuthFacts.cs

示例6: ClientStopsReconnectingAfterDisconnectTimeout

            public void ClientStopsReconnectingAfterDisconnectTimeout(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize(keepAlive: 1, disconnectTimeout: 2);
                    var connection = new Client.Hubs.HubConnection(host.Url);
                    var reconnectWh = new ManualResetEventSlim();
                    var disconnectWh = new ManualResetEventSlim();

                    connection.Reconnecting += () =>
                    {
                        reconnectWh.Set();
                        Assert.Equal(ConnectionState.Reconnecting, connection.State);
                    };

                    connection.Closed += () =>
                    {
                        disconnectWh.Set();
                        Assert.Equal(ConnectionState.Disconnected, connection.State);
                    };

                    connection.Start(host.Transport).Wait();
                    host.Shutdown();

                    Assert.True(reconnectWh.Wait(TimeSpan.FromSeconds(5)));
                    Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(5)));
                }
            }
开发者ID:rustd,项目名称:SignalR,代码行数:28,代码来源:ConnectionFacts.cs

示例7: DisconnectFiresForHubsWhenConnectionGoesAway

        public void DisconnectFiresForHubsWhenConnectionGoesAway()
        {
            using (var host = new MemoryHost())
            {
                host.MapHubs();
                host.Configuration.DisconnectTimeout = TimeSpan.Zero;
                host.Configuration.HeartbeatInterval = TimeSpan.FromSeconds(5);
                var connectWh = new ManualResetEventSlim();
                var disconnectWh = new ManualResetEventSlim();
                host.DependencyResolver.Register(typeof(MyHub), () => new MyHub(connectWh, disconnectWh));
                var connection = new Client.Hubs.HubConnection("http://foo/");

                connection.CreateHubProxy("MyHub");

                // Maximum wait time for disconnect to fire (3 heart beat intervals)
                var disconnectWait = TimeSpan.FromTicks(host.Configuration.HeartbeatInterval.Ticks * 3);

                connection.Start(host).Wait();

                Assert.True(connectWh.Wait(TimeSpan.FromSeconds(10)), "Connect never fired");

                connection.Stop();

                Assert.True(disconnectWh.Wait(disconnectWait), "Disconnect never fired");
            }
        }
开发者ID:kppullin,项目名称:SignalR,代码行数:26,代码来源:DisconnectFacts.cs

示例8: CancelledGenericTask

        public void CancelledGenericTask(HostType hostType, TransportType transportType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                host.Initialize();
                var connection = new Client.Hubs.HubConnection(host.Url);
                var tcs = new TaskCompletionSource<object>();

                var hub = connection.CreateHubProxy("demo");
                connection.Start(host.Transport).Wait();

                hub.Invoke("CancelledGenericTask").ContinueWith(tcs);

                try
                {
                    tcs.Task.Wait(TimeSpan.FromSeconds(10));
                    Assert.True(false, "Didn't fault");
                }
                catch (Exception)
                {

                }

                connection.Stop();
            }
        }
开发者ID:rustd,项目名称:SignalR,代码行数:26,代码来源:HubFacts.cs

示例9: AddingToMultipleGroups

        public void AddingToMultipleGroups()
        {
            var host = new MemoryHost();
            host.MapHubs();
            int max = 100;

            var countDown = new CountDown(max);
            var list = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("MultGroupHub");

            proxy.On<User>("onRoomJoin", user =>
            {
                lock (list)
                {
                    list.Remove(user.Index);
                }

                countDown.Dec();
            });

            connection.Start(host).Wait();

            for (int i = 0; i < max; i++)
            {
                proxy.Invoke("login", new User { Index = i, Name = "tester", Room = "test" + i }).Wait();
            }

            Assert.True(countDown.Wait(TimeSpan.FromSeconds(10)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", list.Select(i => i.ToString())));

            connection.Stop();
        }
开发者ID:thoughtentity,项目名称:SignalR,代码行数:32,代码来源:HubFacts.cs

示例10: AddingToMultipleGroups

        public void AddingToMultipleGroups(HostType hostType, TransportType transportType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                host.Initialize();
                int max = 10;

                var countDown = new CountDownRange<int>(Enumerable.Range(0, max));
                var connection = new Client.Hubs.HubConnection(host.Url);
                var proxy = connection.CreateHubProxy("MultGroupHub");

                proxy.On<User>("onRoomJoin", user =>
                {
                    Assert.True(countDown.Mark(user.Index));
                });

                connection.Start(host.Transport).Wait();

                for (int i = 0; i < max; i++)
                {
                    var user = new User { Index = i, Name = "tester", Room = "test" + i };
                    proxy.InvokeWithTimeout("login", user);
                    proxy.InvokeWithTimeout("joinRoom", user);
                }

                Assert.True(countDown.Wait(TimeSpan.FromSeconds(30)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", countDown.Left.Select(i => i.ToString())));

                connection.Stop();
            }
        }
开发者ID:rustd,项目名称:SignalR,代码行数:30,代码来源:HubFacts.cs

示例11: BrodcastFromServer

        public static IDisposable BrodcastFromServer()
        {
            var host = new MemoryHost();
            IHubContext context = null;

            host.Configure(app =>
            {
                var config = new HubConfiguration()
                {
                    Resolver = new DefaultDependencyResolver()
                };

                app.MapHubs(config);

                var configuration = config.Resolver.Resolve<IConfigurationManager>();
                // The below effectively sets the heartbeat interval to five seconds.
                configuration.KeepAlive = TimeSpan.FromSeconds(10);

                var connectionManager = config.Resolver.Resolve<IConnectionManager>();
                context = connectionManager.GetHubContext("EchoHub");
            });

            var cancellationTokenSource = new CancellationTokenSource();

            var thread = new Thread(() =>
            {
                while (!cancellationTokenSource.IsCancellationRequested)
                {
                    context.Clients.All.echo();
                }
            });

            thread.Start();

            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateHubProxy("EchoHub");

            try
            {
                connection.Start(host).Wait();

                Thread.Sleep(1000);
            }
            finally
            {
                connection.Stop();
            }

            return new DisposableAction(() =>
            {
                cancellationTokenSource.Cancel();

                thread.Join();

                host.Dispose();
            });
        }
开发者ID:armandoramirezdino,项目名称:SignalR,代码行数:57,代码来源:StressRuns.cs

示例12: GenericTaskWithException

        public void GenericTaskWithException()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var ex = Assert.Throws<AggregateException>(() => hub.Invoke("GenericTaskWithException").Wait());

            Assert.Equal("Exception of type 'System.Exception' was thrown.", ex.GetBaseException().Message);
        }
开发者ID:nightbob3,项目名称:SignalR,代码行数:14,代码来源:HubFacts.cs

示例13: GetValueFromServer

        public void GetValueFromServer()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var result = hub.Invoke<int>("GetValue").Result;

            Assert.Equal(10, result);
        }
开发者ID:nightbob3,项目名称:SignalR,代码行数:14,代码来源:HubFacts.cs

示例14: Overloads

        public void Overloads()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            hub.Invoke("Overload").Wait();
            int n = hub.Invoke<int>("Overload", 1).Result;

            Assert.Equal(1, n);
        }
开发者ID:nightbob3,项目名称:SignalR,代码行数:15,代码来源:HubFacts.cs

示例15: SettingState

        public void SettingState()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            hub["name"] = "test";

            connection.Start(host).Wait();

            var result = hub.Invoke<string>("ReadStateValue").Result;

            Assert.Equal("test", result);
        }
开发者ID:paulduran,项目名称:SignalR,代码行数:16,代码来源:HubFacts.cs


注:本文中的Client.Hubs.HubConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。