/// <summary>
 /// Действие при таймауте хода
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnTurnTimeout(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).onTurnTimeout(new
     {
         turn = args.NextTurn
     });
 }
        /// <summary>
        /// Обработчик события изменения состояния игры
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnStateChanged(object sender, GameChangedEventArgs args)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
            context.Clients.Group(args.GameName).onStateChanged(new { State = args.Status, GameId = args.Id });

            var context2 = GlobalHost.ConnectionManager.GetHubContext<GameHub>();
            context2.Clients.All.changeGameState(new
            {
                GameId = args.Id,
                State = args.Status
            });
        }
 /// <summary>
 /// Обработчик события завершения хода
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnTurnFinished(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).onTurnFinished(
         new {
             turnWinner = args.TurnWinner,
             player1Points = args.Player1Points,
             player2Points = args.Player2Points,
             currentTurn = args.CurrentTurn,
             nextTurn = args.NextTurn,
             time = args.Time,
             player1Action = args.Player1Action,
             player2Action = args.Player2Action,
             player1Name = args.Player1Name,
             player2Name = args.Player2Name,
             isDraw = args.IsDraw
         }
     );
 }
 /// <summary>
 /// Обработкчик события, когда игрок покинул не начатую игру
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnPlayerLeaveNotStartedGame(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).onPlayerLeaveNotStartedGame(new { PlayerName = args.Player });
 }
        /// <summary>
        /// Оповещение таблицы игр об изменении количества игроков в игре.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnPlayersCountChanged(object sender, GameChangedEventArgs args)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
            context.Clients.Group(args.GameName).onPlayersCountChanged(new { PlayersCount = args.PlayersCount, GameId = args.Id });

            var context2 = GlobalHost.ConnectionManager.GetHubContext<GameHub>();
            context2.Clients.All.updateGamePlayers(new
            {
                GameId = args.Id,
                PlayersCount = args.PlayersCount + "/2"
            });
        }
 /// <summary>
 /// Действие при подключении игрока к игре
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnPlayerConnected(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).addPlayer2(new { Player2Name = args.Player2Name });
     //TODO сообщить в лобби
 }
 /// <summary>
 /// Обработчик события действия игрока
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnPlayerAction(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).onPlayerAction(args.Status);
 }
 /// <summary>
 /// Обработчик события поступления уведомления
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnNotification(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).onNotification(new { Message = args.Message, Time = DateTime.Now.ToShortTimeString() } );
 }
 /// <summary>
 /// Обработчик события завершения игры
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnGameFinished(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).onGameFinished(
         new
         {
             gameWinner = args.GameWinner,
             time = args.Time
         }
     );
 }
 /// <summary>
 /// Логирование ходов, формирование разметки
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void LogTurn(object sender, GameChangedEventArgs args)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<PlayHub>();
     context.Clients.Group(args.GameName).turnLog(
         new
         {
             CurrentTurn = args.CurrentTurn,
             TurnWinner = args.TurnWinner,
             Player1Name = args.Player1Name,
             Player1Action = GetActionByCode(args.Player1Action),
             Player1UsedHint = args.Player1UsedHint,
             Player2Name = args.Player2Name,
             Player2Action = GetActionByCode(args.Player2Action),
             Player2UsedHint = args.Player2UsedHint
         }
     );
 }