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


C# Client.Hubs.HubConnection.CreateProxy方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: ComplexPersonState

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

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

            var wh = new ManualResetEvent(false);

            connection.Start(host).Wait();

            var person = new SignalR.Samples.Hubs.DemoHub.DemoHub.Person
            {
                Address = new SignalR.Samples.Hubs.DemoHub.DemoHub.Address
                {
                    Street = "Redmond",
                    Zip = "98052"
                },
                Age = 25,
                Name = "David"
            };

            var person1 = hub.Invoke<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("ComplexType", person).Result;
            var person2 = hub.GetValue<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("person");
            JObject obj = ((dynamic)hub).person;
            var person3 = obj.ToObject<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>();

            Assert.NotNull(person1);
            Assert.NotNull(person2);
            Assert.NotNull(person3);
            Assert.Equal("David", person1.Name);
            Assert.Equal("David", person2.Name);
            Assert.Equal("David", person3.Name);
            Assert.Equal(25, person1.Age);
            Assert.Equal(25, person2.Age);
            Assert.Equal(25, person3.Age);
            Assert.Equal("Redmond", person1.Address.Street);
            Assert.Equal("Redmond", person2.Address.Street);
            Assert.Equal("Redmond", person3.Address.Street);
            Assert.Equal("98052", person1.Address.Zip);
            Assert.Equal("98052", person2.Address.Zip);
            Assert.Equal("98052", person3.Address.Zip);

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

示例7: ChangeHubUrl

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

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

            var wh = new ManualResetEvent(false);

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

            connection.Start(host).Wait();

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

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
        }
开发者ID:nightbob3,项目名称:SignalR,代码行数:22,代码来源:HubFacts.cs

示例8: AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedWithRoles

        public void AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedWithRoles()
        {
            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.CreateProxy("AdminAuthHub");
            var wh = new ManualResetEvent(false);
            hub.On<string, string>("invoked", (id, time) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

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

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

示例9: DisconnectFiresForHubsWhenConnectionGoesAway

        public void DisconnectFiresForHubsWhenConnectionGoesAway()
        {
            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.CreateProxy("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:paulduran,项目名称:SignalR,代码行数:24,代码来源:DisconnectFacts.cs

示例10: UnauthenticatedUserCanInvokeMethodsInOutgoingAuthorizedHubs

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

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

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

            connection.Start(host).Wait();

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

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

示例11: RejoiningGroupsOnlyReceivesGroupsBelongingToHub

        public void RejoiningGroupsOnlyReceivesGroupsBelongingToHub()
        {
            var host = new MemoryHost();
            var groupsRequestedToBeRejoined = new List<string>();
            var groupsRequestedToBeRejoined2 = new List<string>();
            host.DependencyResolver.Register(typeof(RejoinMultGroupHub), () => new RejoinMultGroupHub(groupsRequestedToBeRejoined));
            host.DependencyResolver.Register(typeof(RejoinMultGroupHub2), () => new RejoinMultGroupHub2(groupsRequestedToBeRejoined2));
            host.Configuration.KeepAlive = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.MapHubs();

            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("RejoinMultGroupHub");
            var proxy2 = connection.CreateProxy("RejoinMultGroupHub2");

            connection.Start(host).Wait();

            var user = new User { Name = "tester" };
            proxy.Invoke("login", user).Wait();
            proxy2.Invoke("login", user).Wait();

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            proxy.Invoke("joinRoom", user).Wait();
            proxy2.Invoke("joinRoom", user).Wait();

            Thread.Sleep(TimeSpan.FromSeconds(3));

            Assert.True(groupsRequestedToBeRejoined.Contains("foo"));
            Assert.True(groupsRequestedToBeRejoined.Contains("tester"));
            Assert.False(groupsRequestedToBeRejoined.Contains("foo2"));
            Assert.False(groupsRequestedToBeRejoined.Contains("tester2"));
            Assert.True(groupsRequestedToBeRejoined2.Contains("foo2"));
            Assert.True(groupsRequestedToBeRejoined2.Contains("tester2"));
            Assert.False(groupsRequestedToBeRejoined2.Contains("foo"));
            Assert.False(groupsRequestedToBeRejoined2.Contains("tester"));

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

示例12: UnauthenticatedUserCannotReceiveHubMessagesWhenAuthenticationRequiredGlobally

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

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

            var hub = connection.CreateProxy("NoAuthHub");
            var wh = new ManualResetEvent(false);
            hub.On<string, string, object>("joined", (id, time, authInfo) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

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

示例13: UnauthenticatedUserCannotInvokeMethodsWhenAuthenticationRequiredGlobally

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

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

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

            connection.Start(host).Wait();

            Assert.Throws<AggregateException>(() => hub.Invoke("InvokedFromClient").Wait());

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

示例14: UnauthorizedUserCannotInvokeMethodsInHubsAuthorizedSpecifyingUserAndRole

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

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

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

            connection.Start(host).Wait();

            Assert.Throws<AggregateException>(() => hub.Invoke("InvokedFromClient").Wait());

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

示例15: StressGroups

        public static void StressGroups()
        {
            var host = new MemoryHost();
            host.MapHubs();
            int max = 15;

            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<int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(new Client.Transports.ServerSentEventsTransport(host)).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                if (!countDown.Wait(TimeSpan.FromSeconds(10)))
                {
                    Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                    var bus = host.DependencyResolver.Resolve<INewMessageBus>();
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
开发者ID:jlogar,项目名称:SignalR,代码行数:49,代码来源:Program.cs


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