Exemplo n.º 1
0
        public async Task DeleteGamePlayer(string gameId, string playerId, bool synchronize = false)
        {
            var gamePlayer = await GetGamePlayer(gameId, playerId).ConfigureAwait(false);

            if (gamePlayer != null)
            {
                await GamePlayersTable.DeleteAsync(gamePlayer).ConfigureAwait(false);
                await SyncAsync();
            }
        }
Exemplo n.º 2
0
        public async Task SyncAsync()
        {
            if (!IsOnline)
            {
                return;
            }
            ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null;

            try
            {
                await App.MobileService.SyncContext.PushAsync().ConfigureAwait(false);

                await GamesTable.PullAsync("AllGames", this.GamesTable.CreateQuery()).ConfigureAwait(false);

                await PlayersTable.PullAsync("AllPlayers", this.PlayersTable.CreateQuery()).ConfigureAwait(false);

                await VenuesTable.PullAsync("AllVenues", this.PlayersTable.CreateQuery()).ConfigureAwait(false);

                await GamePlayersTable.PullAsync("AllGamePlayers", this.GamePlayersTable.CreateQuery()).ConfigureAwait(false);

                await TeesTable.PullAsync("AllTees", this.TeesTable.CreateQuery()).ConfigureAwait(false);

                await ScoresTable.PullAsync("AllScores", this.ScoresTable.CreateQuery()).ConfigureAwait(false);
            }
            catch (MobileServicePushFailedException exc)
            {
                if (exc.PushResult != null)
                {
                    syncErrors = exc.PushResult.Errors;
                }
            }

            // Simple error/conflict handling.
            if (syncErrors != null)
            {
                foreach (var error in syncErrors)
                {
                    if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null)
                    {
                        //Update failed, reverting to server's copy.
                        await error.CancelAndUpdateItemAsync(error.Result).ConfigureAwait(false);
                    }
                    else
                    {
                        // Discard local change.
                        await error.CancelAndDiscardItemAsync().ConfigureAwait(false);
                    }

                    Debug.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.",
                                    error.TableName, error.Item["id"]);
                }
            }
        }
Exemplo n.º 3
0
        public async Task <List <PlayerDto> > GetPlayersForGame(string gameId)
        {
            var gamePlayers = await GamePlayersTable.Where(x => x.GameId == gameId).ToListAsync().ConfigureAwait(false);

            var result = new List <PlayerDto>();

            foreach (var gamePlayer in gamePlayers)
            {
                result.Add(await GetPlayer(gamePlayer.PlayerId));
            }

            return(result);
        }
Exemplo n.º 4
0
        private async Task CleanupGames()
        {
            var now   = DateTimeOffset.Now.AddDays(-2);
            var games = await GamesTable.Where(x => x.CreatedAt < now).ToListAsync().ConfigureAwait(false);

            foreach (var game in games)
            {
                if ((int)game.GameStatus < (int)GameStatus.Started)
                {
                    var gamePlayers = await GamePlayersTable.Where(x => x.GameId == game.Id).ToListAsync().ConfigureAwait(false);

                    foreach (var gamePlayer in gamePlayers)
                    {
                        await GamePlayersTable.DeleteAsync(gamePlayer).ConfigureAwait(false);
                    }
                    await GamesTable.DeleteAsync(game).ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 5
0
        public async Task <List <Game> > GetGames(string playerId)
        {
            if (string.IsNullOrEmpty(playerId))
            {
                return(new List <Game>());
            }
            var gamePlayers = await GamePlayersTable.Where(x => x.PlayerId == playerId && x.Hide == false).ToListAsync().ConfigureAwait(false);

            var games = await GamesTable.ToListAsync().ConfigureAwait(false);

            var result = new List <Game>();

            foreach (var gamePlayer in gamePlayers)
            {
                var game = games.FirstOrDefault(x => x.Id == gamePlayer.GameId);
                if (game != null)
                {
                    result.Add(game);
                }
            }

            return(result);
        }
Exemplo n.º 6
0
 public async Task <List <GamePlayer> > GetGamePlayers(string gameId)
 {
     return(await GamePlayersTable.Where(x => x.GameId == gameId).ToListAsync());
 }
Exemplo n.º 7
0
        public async Task <GamePlayer> GetGamePlayer(string gameId, string playerId)
        {
            var result = await GamePlayersTable.Where(x => x.GameId == gameId && x.PlayerId == playerId).ToListAsync().ConfigureAwait(false);

            return(result.FirstOrDefault());
        }