/// <summary>
        /// Создание новой игры
        /// </summary>
        /// <param name="sessionId">Идентификатор игры (равен идентификатору пользователя)</param>
        /// <param name="game">описание игры</param>
        public static void CreateGame(string sessionId, GameInformation game)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                throw new ArgumentException("sessionId is null or empety");
            }

            if (game == null)
            {
                throw new ArgumentException("Not game");
            }

            GameLock.EnterWriteLock();
            try
            {
                GameInformation temp;
                bool            isNewGame = !Games.TryGetValue(sessionId, out temp);
                if (!isNewGame)
                {
                    Games.Remove(sessionId);
                }
                Games.Add(sessionId, game);
            }
            finally
            {
                GameLock.ExitWriteLock();
            }
        }
        public GameInformation CreateGame(string uid, string parameters)
        {
            var newGame = new GameInformation();

            newGame.Parameters = parameters;
            newGame.NumPlayers = 2;
            newGame.SessionId  = uid;
            newGame.Players    = new List <ClientInformation>(2);
            newGame.Players.Add(SessionManager.GetSession(uid));
            GameManager.CreateGame(uid, newGame);
            NotifyConnectedClientsGame(newGame);
            return(newGame);
        }
 private static void NotifyConnectedClientsGame(GameInformation gameInfo)
 {
     foreach (SessionInformation client in SessionManager.GetActiveSessions())
     {
         if (client.Callback != null)
         {
             try
             {
                 client.Callback.UpdateGameList(gameInfo);
             }
             catch (TimeoutException timeoutException)
             {
                 Trace.TraceError("Unable to notify client '{0}'. The service operation timed out. {1}", client.UserName, timeoutException.Message);
                 client.Callback = null;
             }
             catch (CommunicationException communicationException)
             {
                 Trace.TraceError("Unable to notify client '{0}'. There was a communication problem. {1} - {2}", client.UserName, communicationException.Message, communicationException.StackTrace);
                 client.Callback = null;
             }
         }
     }
 }