public async Task SetSessionId(string sessionId) { Log.Debug($"SetSessionId({sessionId})"); _connectionManager.AddConnection(new Connection { Id = Context.ConnectionId, SessionId = sessionId }); _dashboardService.EndpointService.SessionManager.StartSession(sessionId); await Clients.Client(Context.ConnectionId).SendAsync("setConnectionId", Context.ConnectionId); }
public void addConnection(string id, int gameId, int playerId) { ConnectionManager.AddConnection(new Connection { ConnectionId = id, PlayerId = playerId, GameId = gameId }); NotifyAll(gameId, (int)Events.OnJoinPLayer, new { playerId = playerId }); Debug.WriteLine(id + " has connected"); }
public virtual Task OnConnected(IConnection connection, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { connection.Close(); } else { _connectionManager.AddConnection(connection); } return(Task.CompletedTask); }
public void AddConnectionString_WhenExist_ShouldUpdate() { var connectionString = "createConnectionString"; ConnectionManager.AddConnection(HolidayPoolingDatabase.HP, connectionString); Assert.AreEqual(1, ConnectionManager.NumberOfConnections()); Assert.AreEqual(connectionString, ConnectionManager.GetConnectionString(HolidayPoolingDatabase.HP)); var update = "updateConnectionString"; ConnectionManager.AddConnection(HolidayPoolingDatabase.HP, update); Assert.AreEqual(1, ConnectionManager.NumberOfConnections()); Assert.AreEqual(update, ConnectionManager.GetConnectionString(HolidayPoolingDatabase.HP)); }
public async Task Invoke(HttpContext context, ILogger <PollConnection> logger) { connectionManager.CheckExistingConnections(); if (!AuthHelper.CheckApiAuth(context.Request.Headers["key"], context.Request.Headers["secret"], options)) { context.Response.StatusCode = StatusCodes.Status401Unauthorized; await context.Response.WriteAsync(JsonHelper.Serialize(new WrongApiResponse())); return; } if (context.Request.Method != "GET") { await next(context); return; } PollConnection connection; if (context.Request.Path.Value.ToLowerInvariant().EndsWith("/init")) { connection = new PollConnection(context); connectionManager.AddConnection(connection); await context.Response.WriteAsync(JsonHelper.Serialize(new ConnectionResponse() { ConnectionId = connection.Id })); logger.LogInformation("Created new poll connection"); } else { connection = (PollConnection)connectionManager.GetConnection(context); if (connection != null) { IEnumerable <object> messages = await connection.GetMessages(); await context.Response.WriteAsync(JsonHelper.Serialize(messages)); } else { context.Response.StatusCode = StatusCodes.Status404NotFound; await context.Response.WriteAsync("No connection was found."); } } }
public virtual async Task OnConnected(Client client, WebSocket socket) { ConnectionManager.AddConnection(client, socket); if (client.ClientType == ClientType.ESP8266) { //TODO: Get ClientId from DB ClientHandler.OnConnected(1); } await SendMessageAsync(socket, new Message() { MessageType = MessageType.ConnectionEvent, Data = client.Id }).ConfigureAwait(false); }
public async Task Invoke(HttpContext context, CommandExecutor commandExecutor, IServiceProvider serviceProvider, ILogger <SSEConnection> logger) { SSEConnection connection = null; try { if (context.Request.Headers["Accept"] == "text/event-stream") { context.Response.Headers["Cache-Control"] = "no-cache"; context.Response.Headers["X-Accel-Buffering"] = "no"; context.Response.ContentType = "text/event-stream"; await context.Response.Body.FlushAsync(); connection = new SSEConnection(context); if (!AuthHelper.CheckApiAuth(context.Request.Query["key"], context.Request.Query["secret"], options)) { await connection.Send(new WrongApiResponse()); context.Response.Body.Close(); return; } connectionManager.AddConnection(connection); await connection.Send(new ConnectionResponse() { ConnectionId = connection.Id }); context.RequestAborted.WaitHandle.WaitOne(); } } catch (Exception ex) { await context.Response.WriteAsync(ex.Message); } finally { if (connection != null) { connectionManager.RemoveConnection(connection); } } }
private void UnrootedConnectionsGetRemovedFromHeartbeatInnerScope( string connectionId, ConnectionManager httpConnectionManager, Mock <IKestrelTrace> trace) { var mock = new Mock <TransportConnection>(); mock.Setup(m => m.ConnectionId).Returns(connectionId); var httpConnection = new KestrelConnection(mock.Object); httpConnectionManager.AddConnection(0, httpConnection); var connectionCount = 0; httpConnectionManager.Walk(_ => connectionCount++); Assert.Equal(1, connectionCount); trace.Verify(t => t.ApplicationNeverCompleted(connectionId), Times.Never()); // Ensure httpConnection doesn't get GC'd before this point. GC.KeepAlive(httpConnection); }
public async Task Invoke(HttpContext context, CommandExecutor commandExecutor, IServiceProvider serviceProvider, ILogger <WebsocketConnection> logger) { if (context.WebSockets.IsWebSocketRequest) { WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); if (!AuthHelper.CheckApiAuth(context.Request.Query["key"], context.Request.Query["secret"], options)) { await webSocket.Send(new WrongApiResponse()); await webSocket.CloseAsync(WebSocketCloseStatus.PolicyViolation, "Wrong API key or secret", CancellationToken.None); return; } WebsocketConnection connection = new WebsocketConnection(webSocket, context); connectionManager.AddConnection(connection); await connection.Send(new ConnectionResponse() { ConnectionId = connection.Id }); while (webSocket.State == WebSocketState.Open || webSocket.State == WebSocketState.Connecting) { try { string message = await connection.Websocket.Receive(); if (!string.IsNullOrEmpty(message)) { _ = Task.Run(async() => { CommandBase command = JsonHelper.DeserializeCommand(message); if (command != null) { ResponseBase response = await commandExecutor.ExecuteCommand(command, serviceProvider.CreateScope().ServiceProvider, connection.Information, logger, connection); if (response != null) { await connection.Send(response); } } }); } } catch (OperationCanceledException) { break; } catch (Exception ex) { logger.LogError(ex.Message); } } connectionManager.RemoveConnection(connection); } }
void Awake() { ConnectionManager.AddConnection(this); }
public void AddConnectionString_WhenDbIsNone_ShouldThrowArgumentException() { Assert.Throws <ArgumentException>(() => ConnectionManager.AddConnection(HolidayPoolingDatabase.None, "connection")); }
public void AddConnectionString_WhenConnectionStringIsNullOrEmpty_ShouldThrowArgumentNullException(string connection) { Assert.Throws <ArgumentNullException>(() => ConnectionManager.AddConnection(HolidayPoolingDatabase.HP, connection)); }