本文整理汇总了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)));
}
}
}
示例2: ProcessRequest
private static Task ProcessRequest(MemoryHost host, string transport, string connectionToken)
{
return host.Get("http://foo/echo/connect?transport=" + transport + "&connectionToken=" + connectionToken);
}
示例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)));
}
}
}