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


C# MemoryHost.Get方法代码示例

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


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

示例1: ConnectionIdsCantBeUsedAsGroups

        public void ConnectionIdsCantBeUsedAsGroups()
        {
            using (var host = new MemoryHost())
            {
                IProtectedData protectedData = null;

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

                    app.MapSignalR<MyConnection>("/echo", config);

                    protectedData = config.Resolver.Resolve<IProtectedData>();
                });

                var connection = new Client.Connection("http://memoryhost/echo");

                using (connection)
                {
                    var connectionTcs = new TaskCompletionSource<string>();
                    var spyTcs = new TaskCompletionSource<string>();

                    connection.Received += data =>
                    {
                        connectionTcs.SetResult(data.Trim());
                    };

                    connection.Start(host).Wait();

                    var tcs = new TaskCompletionSource<object>();
                    EventSourceStreamReader reader = null;

                    Task.Run(async () =>
                    {
                        try
                        {
                            string url = GetUrl(protectedData, connection);
                            var response = await host.Get(url, r => { }, isLongRunning: true);
                            reader = new EventSourceStreamReader(connection, response.GetStream());

                            reader.Message = sseEvent =>
                            {
                                if (sseEvent.EventType == EventType.Data &&
                                    sseEvent.Data != "initialized" &&
                                    sseEvent.Data != "{}")
                                {
                                    spyTcs.TrySetResult(sseEvent.Data);
                                }
                            };

                            reader.Start();
                            tcs.TrySetResult(null);
                        }
                        catch (Exception ex)
                        {
                            tcs.TrySetException(ex);
                        }
                    });

                    tcs.Task.Wait();

                    connection.SendWithTimeout("STUFFF");

                    Assert.True(connectionTcs.Task.Wait(TimeSpan.FromSeconds(5)));
                    Assert.Equal("STUFFF", connectionTcs.Task.Result);
                    Assert.False(spyTcs.Task.Wait(TimeSpan.FromSeconds(5)));
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:72,代码来源:SecurityFacts.cs

示例2: ProcessRequest

 private static Task ProcessRequest(MemoryHost host, string transport, string connectionToken)
 {
     return host.Get("http://foo/echo/connect?transport=" + transport + "&connectionToken=" + connectionToken);
 }
开发者ID:nirmana,项目名称:SignalR,代码行数:4,代码来源:PersistentConnectionFacts.cs

示例3: GroupsTokenIsPerConnectionId

        public async Task GroupsTokenIsPerConnectionId()
        {
            using (var host = new MemoryHost())
            {
                IProtectedData protectedData = null;

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

                    app.MapSignalR<MyGroupConnection>("/echo", config);

                    protectedData = config.Resolver.Resolve<IProtectedData>();
                });

                var connection = new Client.Connection("http://memoryhost/echo");

                using (connection)
                {
                    var inGroup = new AsyncManualResetEvent();

                    connection.Received += data =>
                    {
                        if (data == "group")
                        {
                            inGroup.Set();
                        }
                    };

                    await connection.Start(host);

                    await inGroup.WaitAsync(TimeSpan.FromSeconds(10));

                    Assert.NotNull(connection.GroupsToken);

                    var spyWh = new AsyncManualResetEvent();
                    var hackerConnection = new Client.Connection(connection.Url)
                    {
                        ConnectionId = "hacker"
                    };

                    var url = GetUrl(protectedData, connection, connection.GroupsToken);
                    var response = await host.Get(url, r => { }, isLongRunning: true);
                    var reader = new EventSourceStreamReader(hackerConnection, response.GetStream());

                    reader.Message = sseEvent =>
                    {
                        if (sseEvent.EventType == EventType.Data &&
                            sseEvent.Data != "initialized" &&
                            sseEvent.Data != "{}")
                        {
                            spyWh.Set();
                        }
                    };

                    reader.Start();
                    await connection.Send("random");

                    Assert.False(await spyWh.WaitAsync(TimeSpan.FromSeconds(5)));
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:65,代码来源:SecurityFacts.cs


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