• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Memory.MemoryHost类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



MemoryHost类属于SignalR.Hosting.Memory命名空间,在下文中一共展示了MemoryHost类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: RunInMemoryHost

        private static void RunInMemoryHost()
        {
            var host = new MemoryHost();
            host.MapConnection<MyConnection>("/echo");

            var connection = new Connection("http://foo/echo");

            connection.Received += data =>
            {
                Console.WriteLine(data);
            };

            connection.Start(host).Wait();

            ThreadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    while (true)
                    {
                        connection.Send(DateTime.Now.ToString());

                        Thread.Sleep(2000);
                    }
                }
                catch
                {

                }
            });
        }
开发者ID:ninjaAB,项目名称:SignalR,代码行数:31,代码来源:Program.cs


示例3: SendingBigData

            public void SendingBigData()
            {
                var host = new MemoryHost();
                host.MapConnection<SampleConnection>("/echo");

                var connection = new Connection("http://foo/echo");

                var wh = new ManualResetEventSlim();
                var n = 0;
                var target = 20;

                connection.Received += data =>
                {
                    n++;
                    if (n == target)
                    {
                        wh.Set();
                    }
                };

                connection.Start(host).Wait();

                var conn = host.ConnectionManager.GetConnection<SampleConnection>();

                for (int i = 0; i < target; ++i)
                {
                    var node = new BigData();
                    conn.Broadcast(node).Wait();
                    Thread.Sleep(1000);
                }

                Assert.True(wh.Wait(TimeSpan.FromMinutes(1)), "Timed out");
            }
开发者ID:rhoadsce,项目名称:SignalR,代码行数:33,代码来源:ConnectionFacts.cs


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


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


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


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


示例8: GroupsAreNotReadOnConnectedAsync

            public void GroupsAreNotReadOnConnectedAsync()
            {
                var host = new MemoryHost();
                host.MapConnection<MyConnection>("/echo");

                var connection = new Client.Connection("http://foo/echo");
                connection.Groups = new List<string> { typeof(MyConnection).FullName + ".test" };
                connection.Received += data =>
                {
                    Assert.False(true, "Unexpectedly received data");
                };

                connection.Start(host).Wait();

                Thread.Sleep(TimeSpan.FromSeconds(10));
            }
开发者ID:ninjaAB,项目名称:SignalR,代码行数:16,代码来源:PersistentConnectionFacts.cs


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


示例10: ThrownWebExceptionShouldBeUnwrapped

            public void ThrownWebExceptionShouldBeUnwrapped()
            {
                var host = new MemoryHost();
                host.MapConnection<MyBadConnection>("/ErrorsAreFun");

                var connection = new Client.Connection("http://test/ErrorsAreFun");

                // Expecting 404
                var aggEx = Assert.Throws<AggregateException>(() => connection.Start(host).Wait());

                connection.Stop();

                using (var ser = aggEx.GetError())
                {
                    Assert.Equal(ser.StatusCode, HttpStatusCode.NotFound);
                    Assert.NotNull(ser.ResponseBody);
                    Assert.NotNull(ser.Exception);
                }
            }
开发者ID:neiz,项目名称:SignalR,代码行数:19,代码来源:ConnectionFacts.cs


示例11: HubNamesAreNotCaseSensitive

        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)));
        }
开发者ID:RodH257,项目名称:SignalR,代码行数:21,代码来源:HubProxyTest.cs


示例12: EndToEndTest

        public void EndToEndTest()
        {
            var host = new MemoryHost();
            host.MapHubs();

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

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

            hubConnection.Start(host).Wait();

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

            Assert.True(called);
        }
开发者ID:NickBourke,项目名称:SignalR,代码行数:21,代码来源:HubProxyTest.cs


示例13: DisconnectFiresForPersistentConnectionWhenClientGoesAway

        public void DisconnectFiresForPersistentConnectionWhenClientGoesAway()
        {
            var host = new MemoryHost();
            host.MapConnection<MyConnection>("/echo");
            host.Configuration.DisconnectTimeout = TimeSpan.Zero;
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(5);
            var connectWh = new ManualResetEventSlim();
            var disconnectWh = new ManualResetEventSlim();
            host.DependencyResolver.Register(typeof(MyConnection), () => new MyConnection(connectWh, disconnectWh));
            var connection = new Client.Connection("http://foo/echo");

            // 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,代码行数:22,代码来源:DisconnectFacts.cs


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


示例15: 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/");

            // Maximum wait time for disconnect to fire (2 heart beat intervals)
            var disconnectWait = host.Configuration.HeartBeatInterval + host.Configuration.HeartBeatInterval;

            connection.Start(host).Wait();

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

            connection.Stop();

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


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


示例17: SendRaisesOnReceivedFromAllEvents

            public void SendRaisesOnReceivedFromAllEvents()
            {
                var host = new MemoryHost();
                host.MapConnection<MySendingConnection>("/multisend");

                var connection = new Client.Connection("http://foo/multisend");
                var results = new List<string>();
                connection.Received += data =>
                {
                    results.Add(data);
                };

                connection.Start(host).Wait();
                connection.Send("").Wait();

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

                Debug.WriteLine(String.Join(", ", results));

                Assert.Equal(4, results.Count);
                Assert.Equal("OnConnectedAsync1", results[0]);
                Assert.Equal("OnConnectedAsync2", results[1]);
                Assert.Equal("OnReceivedAsync1", results[2]);
                Assert.Equal("OnReceivedAsync2", results[3]);
            }
开发者ID:ninjaAB,项目名称:SignalR,代码行数:25,代码来源:PersistentConnectionFacts.cs


示例18: GroupsReceiveMessages

            public void GroupsReceiveMessages()
            {
                var host = new MemoryHost();
                host.MapConnection<MyGroupConnection>("/groups");

                var connection = new Client.Connection("http://foo/groups");
                var list = new List<string>();
                connection.Received += data =>
                {
                    list.Add(data);
                };

                connection.Start(host).Wait();

                // Join the group
                connection.Send(new { type = 1, group = "test" }).Wait();

                // Sent a message
                connection.Send(new { type = 3, group = "test", message = "hello to group test" }).Wait();

                // Leave the group
                connection.Send(new { type = 2, group = "test" }).Wait();

                // Send a message
                connection.Send(new { type = 3, group = "test", message = "goodbye to group test" }).Wait();

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

                connection.Stop();

                Assert.Equal(1, list.Count);
                Assert.Equal("hello to group test", list[0]);
            }
开发者ID:Icenium,项目名称:SignalR,代码行数:33,代码来源:PersistentConnectionFacts.cs


示例19: DynamicInvokeTest

        public void DynamicInvokeTest()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");
            string callback = "!!!CallMeBack!!!";

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

            var wh = new ManualResetEvent(false);

            hub.On(callback, () => wh.Set());

            connection.Start(host).Wait();

            hub.Invoke("DynamicInvoke", callback).Wait();

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


示例20: TaskWithException

        public void TaskWithException()
        {
            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("TaskWithException").Wait());

            Assert.IsType<InvalidOperationException>(ex.GetBaseException());
            Assert.Contains("System.Exception", ex.GetBaseException().Message);
            connection.Stop();
        }
开发者ID:nairit,项目名称:SignalR,代码行数:16,代码来源:HubFacts.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ProtocolBuffers.ProtoMessage类代码示例发布时间:2022-05-26
下一篇:
C# Sifteo.Cube类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap