public async Task <string> SendGameRequestAsync(GameImageryItemViewModel balloonImage, GameImageryItemViewModel backgroundImage, User user) { string gameGuid = Guid.NewGuid().ToString(); GameModel model = new GameModel(); model.GameGUID = gameGuid; model.GameRequesterId = this.buddyUser.ID; model.GameResponderId = user.ID; model.State = GameState.REQUEST_SENT; model.TotalDuration = new Random().Next((int)GameModel.BalloonMinTime, (int)GameModel.BalloonMaxTime); model.UpdatedTime = DateTime.UtcNow; model.BalloonImageUrl = balloonImage.ImageUrl; model.BackgroundImageUrl = backgroundImage.ImageUrl; if (await AddGameModelAsync(model) && await this.buddyUser.Messages.SendAsync(user, string.Format(messageFormatString, gameGuid, newRequestMessage), "newGameRequest")) { PushNotificationData pushData = new PushNotificationData(); pushData.Action = PushNotificationData.PushAction.GAME_CREATED; pushData.MoveDuration = 0; pushData.OpponentName = this.buddyUser.Name; pushData.ThumbnailUri = ""; await SendPushAsync(pushData, user.ID); return(gameGuid); } else { return(null); } }
public async Task <bool> SendPushAsync(PushNotificationData data, int receiverId) { var dataString = JsonConvert.SerializeObject(data); bool result = await this.buddyUser.PushNotifications.Android.SendRawMessageAsync(dataString, this.buddyUser.ID, default(DateTime), receiverId.ToString()); return(result); }
public async Task <bool> UpdateGameModelAsync(GameModel model, User opponent = null, Stream photoStream = null) { model.UpdatedTime = DateTime.UtcNow; // Console.WriteLine(output); string thumbnail = ""; PushNotificationData.PushAction pushAction = PushNotificationData.PushAction.MADE_MOVE; if (opponent != null && photoStream != null) { var userExtraData = JsonConvert.DeserializeObject <UserExtraData> (this.buddyUser.ApplicationTag); var opponentExtraData = JsonConvert.DeserializeObject <UserExtraData> (opponent.ApplicationTag); var album = await this.buddyUser.PhotoAlbums.GetAsync(userExtraData.UploadAlbumId); PicturePublic uploadedPicture = await album.AddPictureAsync(photoStream, "", 0, 0, model.GameGUID); var virtualAlbum = await buddyUser.VirtualAlbums.GetAsync(opponentExtraData.WinnerAblumVirtualId); var imageId = await virtualAlbum.AddPictureAsync(uploadedPicture); // TODO make this happen in parallel { var profileStream = PlatformSpecificOperations.CreateProfilePicture(photoStream); bool profileSuccess = await this.buddyUser.AddProfilePhotoAsync(profileStream); } model.ImageIds.Add(imageId); thumbnail = uploadedPicture.ThumbnailUrl; pushAction = PushNotificationData.PushAction.LOST_GAME; } string output = JsonConvert.SerializeObject(model); bool metadata = await this.buddyClient.Metadata.SetAsync(model.GameGUID, output); PushNotificationData pushData = new PushNotificationData(); pushData.Action = pushAction; pushData.MoveDuration = model.GameMoves.LastOrDefault().HoldDuration; pushData.OpponentName = this.buddyUser.Name; pushData.ThumbnailUri = thumbnail; bool messageResult = await SendPushAsync(pushData, model.OtherUser(this.buddyUser.ID)); return(messageResult && metadata); }
public static void GetDetailedActionDescription(PushNotificationData data, out string titleDescription, out string detailedDescription) { titleDescription = "Unknown"; detailedDescription = "Unknown"; switch (data.Action) { case PushNotificationData.PushAction.GAME_CREATED: titleDescription = "New Game Created"; detailedDescription = string.Format("{0} invited you to play popPIC", data.OpponentName); break; case PushNotificationData.PushAction.MADE_MOVE: titleDescription = "It's Your Turn"; detailedDescription = string.Format("{0} pressed for {1}", data.OpponentName, FormattingUtilities.FormatMilliseconds(data.MoveDuration, true)); break; case PushNotificationData.PushAction.LOST_GAME: titleDescription = "You Won!"; detailedDescription = string.Format("{0} popped the balloon", data.OpponentName); break; } }