本文整理汇总了C#中HttpContext.DispatcherHelper方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContext.DispatcherHelper方法的具体用法?C# HttpContext.DispatcherHelper怎么用?C# HttpContext.DispatcherHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpContext
的用法示例。
在下文中一共展示了HttpContext.DispatcherHelper方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public async Task Invoke(HttpContext httpContext,
IServiceCollection services,
ILoggerFactory loggerFactory,
IOptions<ServerSettings> settings,
IClientMessageFactory messageFactory,
ConcurrentBag<IMessageDispatcher> dispatcherBag)
{
var logger = loggerFactory.CreateLogger(nameof(SocketRequestMiddleware));
if (httpContext.WebSockets.IsWebSocketRequest)
{
var webSocket = await httpContext.WebSockets.AcceptWebSocketAsync();
if (webSocket != null && webSocket.State == WebSocketState.Open)
{
// ClientId, Type and IsMaster
Tuple<Guid, ClientType, bool> dispatchObjs = httpContext.DispatcherHelper();
IMessageDispatcher dispatcher;
if (dispatchObjs.Item3)
{
dispatcher = new MasterMessageDispatcher(settings,
messageFactory,
webSocket,
dispatchObjs.Item1,
dispatchObjs.Item2);
// DI Container Registration for controller simple access to Master Dispatcher
services.AddSingleton(typeof(IMasterMessageDispatcher), dispatcher);
}
else
{
dispatcher = new MessageDispatcher(settings,
messageFactory,
webSocket,
dispatchObjs.Item1,
dispatchObjs.Item2);
}
dispatcherBag.Add(dispatcher);
logger.LogInformation("WebSocket Initiated");
// Ignore notification for self connection of Master App
if (!dispatchObjs.Item3)
await NotifyToMaster(dispatcherBag, dispatchObjs.Item1, dispatchObjs.Item2);
}
else
{
// noop
}
}
else
{
// Nothing to do here, pass downstream.
await next(httpContext);
}
}