public async Task <bool> InitializeAsync() { var repository = new GameImageryRepository(); this.BalloonImages = await repository.GetBalloonImagesAsync(); this.BackgroundImages = await repository.GetBackgroundImagesAsync(); this.CurrentBackgroundImage = repository.DefaultBackground; this.CurrentBalloonImage = repository.DefaultBallon; return(this.IsInitialized = true); }
public async Task <bool> InitializeAsync() { var tasks = new List <Task> (); this.requester = await this.repository.GetUserAsync(this.model.GameRequesterId); this.responder = await this.repository.GetUserAsync(this.model.GameResponderId); this.currentUser = this.requester.ID == this.repository.CurrentUserBuddyId ? this.requester : this.responder; this.otherUser = this.requester.ID == this.repository.CurrentUserBuddyId ? this.responder : this.requester; totalElapsedSession = 0; playerTime1 = playerTime2 = playerAddedTime1 = playerAddedTime2 = 0; isPlayer1Turn = this.model.GameMoves.Count % 2 == 0; User lastPlayer = null, winner = null; for (int i = 0; i < this.model.GameMoves.Count; i++) { var move = this.model.GameMoves [i]; lastPlayer = move.PlayerId == this.requester.ID ? requester : responder; if (i % 2 == 0) { playerTime1 += move.HoldDuration; } else { playerTime2 += move.HoldDuration; } } if (lastPlayer != null) { winner = lastPlayer.ID == this.requester.ID ? this.responder : this.requester; } totalElapsedStart = playerTime1 + playerTime2; if (model.State == GameState.COMPLETED && model.ImageIds.Count > 0) { // TODO crash or something if there is no image LoserImgData = await this.repository.GetLoserPictureImageStreamAsync(model.ImageIds[0], winner, model.GameGUID); } if (!string.IsNullOrEmpty(this.model.BalloonImageUrl) && !string.IsNullOrEmpty(this.model.BackgroundImageUrl)) { var imageRepository = new GameImageryRepository(); tasks.Add(imageRepository.GetImageAsync(this.model.BalloonImageUrl).ContinueWith(t => this.BalloonImageStream = t.Result)); tasks.Add(imageRepository.GetImageAsync(this.model.BackgroundImageUrl).ContinueWith(t => this.BackgroundImageStream = t.Result)); await Task.WhenAll(tasks); } else { this.BalloonImageStream = this.BackgroundImageStream = null; } // // this.requester = await this.repository.GetUserAsync (this.model.GameRequesterId); // this.responder = await this.repository.GetUserAsync (this.model.GameResponderId); // // this.currentUser = this.requester.ID == this.repository.CurrentUserBuddyId ? this.requester : this.responder; // this.otherUser = this.requester.ID == this.repository.CurrentUserBuddyId ? this.responder : this.requester; // // totalElapsedSession = 0; // playerTime1 = playerTime2 = playerAddedTime1 = playerAddedTime2 = 0; // isPlayer1Turn = this.model.GameMoves.Count % 2 == 0; // User lastPlayer = null, winner = null; // // for (int i=0; i<this.model.GameMoves.Count; i++) { // var move = this.model.GameMoves [i]; // lastPlayer = move.PlayerId == this.requester.ID ? requester : responder; // if (i % 2 == 0) { // playerTime1 += move.HoldDuration; // } else { // playerTime2 += move.HoldDuration; // } // } // // if (lastPlayer != null) { // winner = lastPlayer.ID == this.requester.ID ? this.responder : this.requester; // } // // totalElapsedStart = playerTime1 + playerTime2; // // if (model.State == GameState.COMPLETED && model.ImageIds.Count > 0) { // // TODO crash or something if there is no image // LoserImgData = await this.repository.GetLoserPictureImageStreamAsync (model.ImageIds [0], winner, model.GameGUID); // } return(true); }