本文整理汇总了C#中ConnectionManager.GetConnectionContext方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionManager.GetConnectionContext方法的具体用法?C# ConnectionManager.GetConnectionContext怎么用?C# ConnectionManager.GetConnectionContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager.GetConnectionContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectionRun
public ConnectionRun(RunData runData)
: base(runData)
{
var connectionManager = new ConnectionManager(Resolver);
_context = connectionManager.GetConnectionContext<StressConnection>();
_transportConnection = (ITransportConnection)_context.Connection;
}
示例2: ReceiveLoopRun
internal static IDisposable ReceiveLoopRun(int connections, int senders, string payload)
{
var resolver = new DefaultDependencyResolver();
var connectionManager = new ConnectionManager(resolver);
var subscriptions = new List<IDisposable>();
var senderCountDown = new CountdownEvent(senders);
var connectionCountDown = new CountdownEvent(connections);
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
var context = connectionManager.GetConnectionContext<StressConnection>();
// Initialize performance counters for this run
Utility.InitializePerformanceCounters(resolver, cancellationTokenSource.Token);
for (int i = 0; i < connections; i++)
{
var transportConnection = (ITransportConnection)context.Connection;
ThreadPool.QueueUserWorkItem(_ =>
{
ReceiveLoop(connectionCountDown,
transportConnection,
messageId: null,
cancellationToken: cancellationToken);
});
}
for (var i = 1; i <= senders; i++)
{
ThreadPool.QueueUserWorkItem(_ =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
context.Connection.Broadcast(payload);
}
senderCountDown.Signal();
});
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
// Wait for each loop
connectionCountDown.Wait(TimeSpan.FromMilliseconds(500 * connections));
// Wait for all senders to stop
senderCountDown.Wait(TimeSpan.FromMilliseconds(1000 * senders));
subscriptions.ForEach(s => s.Dispose());
});
}
示例3: RunConnectionTest
private static void RunConnectionTest()
{
string payload = GetPayload();
var dr = new DefaultDependencyResolver();
MeasureStats((MessageBus)dr.Resolve<IMessageBus>());
var connectionManager = new ConnectionManager(dr);
var context = connectionManager.GetConnectionContext<StressConnection>();
for (int i = 0; i < _clients; i++)
{
ThreadPool.QueueUserWorkItem(state =>
{
Interlocked.Increment(ref _clientsRunning);
var transportConnection = (ITransportConnection)context.Connection;
transportConnection.Receive(null, r =>
{
Interlocked.Add(ref _received, r.TotalCount);
Interlocked.Add(ref _avgLastReceivedCount, r.TotalCount);
return TaskAsyncHelper.True;
},
maxMessages: 10);
}, i);
}
for (var i = 1; i <= _senders; i++)
{
ThreadPool.QueueUserWorkItem(_ =>
{
StartSendLoop(i.ToString(), (source, key, value) => context.Connection.Broadcast(value), payload);
});
}
}
示例4: RunConnectionReceiveLoopTest
private static void RunConnectionReceiveLoopTest()
{
string payload = GetPayload();
var dr = new DefaultDependencyResolver();
MeasureStats((MessageBus)dr.Resolve<IMessageBus>());
var connectionManager = new ConnectionManager(dr);
var context = connectionManager.GetConnectionContext<StressConnection>();
for (int i = 0; i < _clients; i++)
{
ThreadPool.QueueUserWorkItem(state =>
{
Interlocked.Increment(ref _clientsRunning);
var transportConnection = (ITransportConnection)context.Connection;
ReceiveLoop(transportConnection, null);
}, i);
}
for (var i = 1; i <= _senders; i++)
{
ThreadPool.QueueUserWorkItem(_ =>
{
StartSendLoop(i.ToString(), (source, key, value) => context.Connection.Broadcast(value), payload);
});
}
}