public void AddBinding(ConnectionBinding <T> binding) { lock (_lock) { _bindings.Add(binding); if (_bound) { binding.Bind(_connection); } } }
public void RemoveBinding(ConnectionBinding <T> binding) { lock (_lock) { if (_bound) { binding.Unbind(_connection); } _bindings.Remove(binding); } }
public void RemoveBinding(ConnectionBinding <T> binding) { lock (_lock) { try { if (_bound) { binding.Unbind(_connection); } } catch (Exception ex) { _log.Error("Failed to unbind", ex); } _bindings.Remove(binding); } }
public async Task StartValidationForNextThemeAsync(Guid gameId, int roundNumber) { RemoveGameTimer(gameId); var themeToValidate = await _gameManager.StartValidationForNextThemeAsync(gameId); if (!string.IsNullOrEmpty(themeToValidate)) { var playersValidations = await _gameManager.GetPlayersDefaultValidationsAsync(gameId, themeToValidate); foreach (var(playerId, validations, totalValidations, validationsNumber) in playersValidations) { string connectionId = ConnectionBinding.GetPlayerConnectionId(gameId, playerId); await _gameHub.Clients.Client(connectionId).SendAsync("validation_started", new { theme = themeToValidate, validations, totalValidations, validationsNumber }); } StartValidationTimer(gameId, roundNumber, themeToValidate); } else { await _gameManager.FinishCurrentRoundAsync(gameId, async (game) => { var roundScoreboard = game.GetScoreboard(game.CurrentRoundNumber); if (game.IsFinalRound()) { var winners = game.GetWinners(); await _gameHub.Clients.GameRoundGroup(gameId, roundNumber).SendAsync("game_finished", new { lastRoundScoreboard = roundScoreboard, winners }); await _lobbyHubContext.Clients.All.SendAsync("game_finished", gameId); } else { await _gameHub.Clients.GameRoundGroup(gameId, roundNumber).SendAsync("round_finished", new { scoreboard = roundScoreboard }); } foreach (var player in game.Players) { var playerPontuationInRound = player.GetPontuationsInRound(game.CurrentRoundNumber); var playerConnectionId = ConnectionBinding.GetPlayerConnectionId(game.Id, player.Id); await _gameHub.Clients.Client(playerConnectionId).SendAsync("receive_my_pontuations_in_round", new { roundNumber = game.CurrentRoundNumber, pontuations = playerPontuationInRound }); } }); } }