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


C# HttpContext.DispatcherHelper方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:gencebay,项目名称:CloudBuilder,代码行数:55,代码来源:SocketRequestMiddleware.cs


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