本文整理汇总了C#中SignalR.Hosting.Memory.MemoryHost.MapConnection方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryHost.MapConnection方法的具体用法?C# MemoryHost.MapConnection怎么用?C# MemoryHost.MapConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SignalR.Hosting.Memory.MemoryHost
的用法示例。
在下文中一共展示了MemoryHost.MapConnection方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
{
}
});
}
示例2: 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");
}
示例3: 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));
}
示例4: 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);
}
}
示例5: 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");
}
示例6: 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]);
}
示例7: RunMemoryHost
private static MemoryHost RunMemoryHost()
{
var host = new MemoryHost();
host.MapConnection<StressConnection>("/echo");
string payload = GetPayload();
MeasureStats((MessageBus)host.DependencyResolver.Resolve<IMessageBus>());
Action<PersistentResponse> handler = (r) =>
{
Interlocked.Add(ref _received, r.TotalCount);
Interlocked.Add(ref _avgLastReceivedCount, r.TotalCount);
};
LongPollingTransport.SendingResponse += handler;
ForeverFrameTransport.SendingResponse += handler;
for (int i = 0; i < _clients; i++)
{
ThreadPool.QueueUserWorkItem(state =>
{
Interlocked.Increment(ref _clientsRunning);
string connectionId = state.ToString();
//LongPollingLoop(host, connectionId);
ProcessRequest(host, "serverSentEvents", connectionId);
}, i);
}
for (var i = 1; i <= _senders; i++)
{
ThreadPool.QueueUserWorkItem(_ =>
{
var context = host.ConnectionManager.GetConnectionContext<StressConnection>();
StartSendLoop(i.ToString(), (source, key, value) => context.Connection.Broadcast(value), payload);
});
}
return host;
}
示例8: ReconnectFiresAfterTimeOutSSE
public void ReconnectFiresAfterTimeOutSSE()
{
var host = new MemoryHost();
var conn = new MyReconnect();
host.Configuration.KeepAlive = null;
host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(5);
host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(5);
host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
host.MapConnection<MyReconnect>("/endpoint");
var connection = new Client.Connection("http://foo/endpoint");
connection.Start(new Client.Transports.ServerSentEventsTransport(host)).Wait();
Thread.Sleep(TimeSpan.FromSeconds(15));
connection.Stop();
Assert.InRange(conn.Reconnects, 1, 4);
}
示例9: ReconnectFiresAfterHostShutDown
public void ReconnectFiresAfterHostShutDown()
{
var host = new MemoryHost();
var conn = new MyReconnect();
host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
host.MapConnection<MyReconnect>("/endpoint");
var connection = new Client.Connection("http://foo/endpoint");
connection.Start(host).Wait();
host.Dispose();
Thread.Sleep(TimeSpan.FromSeconds(5));
Assert.Equal(Client.ConnectionState.Reconnecting, connection.State);
connection.Stop();
}
示例10: GroupsRejoinedWhenOnRejoiningGroupsOverridden
public void GroupsRejoinedWhenOnRejoiningGroupsOverridden()
{
var host = new MemoryHost();
host.Configuration.KeepAlive = null;
host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(2);
host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(2);
host.MapConnection<MyRejoinGroupConnection>("/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();
// Force Reconnect
Thread.Sleep(TimeSpan.FromSeconds(5));
// 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(2, list.Count);
Assert.Equal("hello to group test", list[0]);
Assert.Equal("goodbye to group test", list[1]);
}
示例11: 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]);
}
示例12: ReconnectFiresAfterTimeOutSSE
public void ReconnectFiresAfterTimeOutSSE()
{
var host = new MemoryHost();
var conn = new MyReconnect();
host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(5);
host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
host.MapConnection<MyReconnect>("/endpoint");
var connection = new Client.Connection("http://foo/endpoint");
connection.Start(host).Wait();
Thread.Sleep(TimeSpan.FromSeconds(15));
Assert.Equal(2, conn.Reconnects);
}
示例13: SendToAllButCaller
public void SendToAllButCaller()
{
var host = new MemoryHost();
host.MapConnection<FilteredConnection>("/filter");
var connection1 = new Client.Connection("http://foo/filter");
var connection2 = new Client.Connection("http://foo/filter");
var wh1 = new ManualResetEventSlim(initialState: false);
var wh2 = new ManualResetEventSlim(initialState: false);
connection1.Received += data => wh1.Set();
connection2.Received += data => wh2.Set();
connection1.Start(host).Wait();
connection2.Start(host).Wait();
connection1.Send("test").Wait();
Assert.False(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
Assert.True(wh2.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
connection1.Stop();
connection2.Stop();
}