示例#1
0
 public UserGamesRs GetUserGames(UserGamesRq request)
 {
     if (request == null || string.IsNullOrEmpty(request.SessionId))
         return new UserGamesRs() { ErrorMessage = "Invalid GetUserGames request!!", IsSucess = false };
     UserGamesRs response = new UserGamesRs() { IsSucess = true };
     try
     {
         IGameProvider gameProvider = GameProviderFactory.GetGameProvider();
         var session = GetSession(request.SessionId, response);
         if (session == null)
             return response;
         if (session.ActiveGames != null)
         {
             response.UserGames = new List<Game>();
             foreach (var gameId in session.ActiveGames)
             {
                 response.UserGames.Add(gameProvider.GetGame(gameId).ToDataContract(session.Account.Id));
             }
         }
         else
         {
             IGameDataProvider gameDataProvider = GameDataProviderFactory.GetGameDataProvider();
             var myGames = gameDataProvider.GetUserActiveGames(session.Account.Id);
             response.UserGames = gameProvider.LoadGamesFromAppacitive(myGames).ToDataContract(session.Account.Id);
             session.ActiveGames = myGames;
             var gameTiles = gameDataProvider.GetGameTiles(session.ActiveGames);
             foreach (var activeGameId in session.ActiveGames)
             {
                 gameProvider.SetGameTiles(activeGameId, gameTiles[activeGameId], false);
             }
         }
     }
     catch (Exception ex)
     {
         response.IsSucess = false;
         response.ErrorMessage = "Failed to pull your games!";
         LoggingDataProviderFactory.GetLoggingDataProvider().LogException(ex, Source, "GetUserGames", Model.Severity.Critical);
     }
     return response;
 }
示例#2
0
 public UserGamesRs GetPreviousGames(UserGamesRq request)
 {
     if (request == null || request.SessionId == null)
         return new UserGamesRs() { IsSucess = false, ErrorMessage = "Invalid GetPreviousGames request!" };
     var response = new UserGamesRs() { IsSucess = true };
     try
     {
         var session = GetSession(request.SessionId, response);
         if (session == null)
             return response;
         IGameDataProvider gameDataProvider = GameDataProviderFactory.GetGameDataProvider();
         response.UserGames = gameDataProvider.GetPreviousGames(session.Account.Id).ToDataContract(session.Account.Id);
         if (response.UserGames != null)
         {
             List<string> notStartedGames = new List<string>();
             foreach (var userGame in response.UserGames)
             {
                 if (userGame.Players.Count == 1)
                 {
                     notStartedGames.Add(userGame.Id);
                 }
             }
             response.UserGames.RemoveAll(g => notStartedGames.Contains(g.Id));
         }
     }
     catch (Exception ex)
     {
         response.IsSucess = false;
         response.ErrorMessage = "Failed to get your previous game history!";
         LoggingDataProviderFactory.GetLoggingDataProvider().LogException(ex, Source, "GetPreviousGames", Model.Severity.Normal);
     }
     return response;
 }