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); } }
public MasterMessageDispatcher( IOptions<ServerSettings> settings, IClientMessageFactory clientMessageFactory, WebSocket webSocket, Guid masterClientId, ClientType clientType) :base(settings, clientMessageFactory, webSocket, masterClientId, clientType) { }
public MasterMessageDispatcher( IOptions <ServerSettings> settings, IClientMessageFactory clientMessageFactory, WebSocket webSocket, Guid masterClientId, ClientType clientType) : base(settings, clientMessageFactory, webSocket, masterClientId, clientType) { }
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); } }
public MessageDispatcher( IOptions<ServerSettings> settings, IClientMessageFactory clientMessageFactory, WebSocket webSocket, Guid clientId, ClientType clientType) { _settings = settings; _clientMessageFactory = clientMessageFactory; _webSocket = webSocket; _clientId = clientId; _clientType = clientType; _createdDate = DateTime.Now; }
public MessageDispatcher( IOptions <ServerSettings> settings, IClientMessageFactory clientMessageFactory, WebSocket webSocket, Guid clientId, ClientType clientType) { _settings = settings; _clientMessageFactory = clientMessageFactory; _webSocket = webSocket; _clientId = clientId; _clientType = clientType; _createdDate = DateTime.Now; }