SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void SendRoundDataToFirebase()
  2.     {
  3.         List<FirestoreDocumentModel> playerRoundDataNested = new List<FirestoreDocumentModel>();
  4.  
  5.         IEnumerable<PlayerOffline> sortedQuery = from player in playersOffline orderby player.corrects descending, player.time ascending select player;
  6.  
  7.         string[] playerList = new string[playersOffline.Count];
  8.  
  9.         int index = 0;
  10.         foreach (PlayerOffline player in sortedQuery)
  11.         {
  12.             List<FirestoreDocumentModel> playerRoundDataDoubleNested = new List<FirestoreDocumentModel>();
  13.             //Double nested mapped values for the player, using the player name as the key
  14.             playerRoundDataDoubleNested.Add(new FirestoreDocumentModel("Corrects", FirestoreDocumentModel.ValueType.integerValue, player.corrects.ToString()));
  15.             playerRoundDataDoubleNested.Add(new FirestoreDocumentModel("Incorrects", FirestoreDocumentModel.ValueType.integerValue, player.incorrects.ToString()));
  16.             playerRoundDataDoubleNested.Add(new FirestoreDocumentModel("Time", FirestoreDocumentModel.ValueType.doubleValue, player.time.ToString("N2")));
  17.             playerRoundDataDoubleNested.Add(new FirestoreDocumentModel("AverageBuzzTime", FirestoreDocumentModel.ValueType.doubleValue, player.averageBuzzTime.ToString("N2")));
  18.             playerRoundDataDoubleNested.Add(new FirestoreDocumentModel("ThumbsUp", FirestoreDocumentModel.ValueType.booleanValue, player.thumbsUp.ToString()));
  19.  
  20.             if (player.name != "Player" && string.IsNullOrWhiteSpace(player.name) != true)
  21.             {
  22.                 playerRoundDataNested.Add(new FirestoreDocumentModel(player.name, FirestoreDocumentModel.ValueType.mapValue, FirestoreUtility.CreateJsonString(playerRoundDataDoubleNested)));
  23.  
  24.                 playerList[index] = player.name;
  25.             }
  26.             else
  27.             {
  28.                 playerRoundDataNested.Add(new FirestoreDocumentModel(player.name + player.assignedLetter, FirestoreDocumentModel.ValueType.mapValue, FirestoreUtility.CreateJsonString(playerRoundDataDoubleNested)));
  29.  
  30.                 playerList[index] = player.name + player.assignedLetter;
  31.             }
  32.  
  33.             index++;
  34.         }
  35.  
  36.         List<FirestoreDocumentModel> finalRoundData = new List<FirestoreDocumentModel>();
  37.         finalRoundData.Add(new FirestoreDocumentModel("Judge", FirestoreDocumentModel.ValueType.stringValue, Global.PlayFabID));
  38.         finalRoundData.Add(new FirestoreDocumentModel("Title", FirestoreDocumentModel.ValueType.stringValue, roundName));
  39.         finalRoundData.Add(new FirestoreDocumentModel("RoundFileName", FirestoreDocumentModel.ValueType.stringValue, QuestionDatabase.RoundName));
  40.         finalRoundData.Add(new FirestoreDocumentModel("RoundFilePath", FirestoreDocumentModel.ValueType.stringValue, QuestionDatabase.RoundPath));
  41.  
  42.         finalRoundData.Add(new FirestoreDocumentModel("PlayerList", FirestoreDocumentModel.ValueType.arrayValue, playerList));
  43.         finalRoundData.Add(new FirestoreDocumentModel("Players", FirestoreDocumentModel.ValueType.mapValue, FirestoreUtility.CreateJsonString(playerRoundDataNested)));
  44.  
  45.         string jsonData = FirestoreUtility.CreateJsonString(finalRoundData);
  46.  
  47.         var request = new ExecuteCloudScriptRequest();
  48.         Debug.Log(jsonData);
  49.         request.FunctionName = "addRoundData";
  50.         request.FunctionParameter = jsonData;
  51.         PlayFab.PlayFabClientAPI.ExecuteCloudScript(request, SendSuccess, SendFailed);
  52.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top