Created
October 16, 2020 18:41
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Azure.WebJobs.Extensions.Http; | |
using Microsoft.Extensions.Logging; | |
using PlayFab.Plugins.CloudScript; | |
using PlayFab.ServerModels; | |
namespace YourNameSpace | |
{ | |
public static class CountPlayersInSegmentAndUpdateTitleData | |
{ | |
[FunctionName("GetCountPlayersInSegmentAndUpdateTitleData")] | |
public static async Task<dynamic> GetCountPlayersInSegmentAndUpdateTitleData( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, ILogger log) | |
{ | |
log.LogDebug("Started before context"); | |
var context = await FunctionContext<dynamic>.Create(req); | |
string NUMBER_OF_PLAYER_TODAY_TITLE_DATA_KEY = "NumberOfPlayersToday"; | |
var getPlayersInSegmentRequest = new GetPlayersInSegmentRequest() | |
{ | |
// This already includes all Api data needed like TitleId or DevSecret | |
AuthenticationContext = context.AuthenticationContext, | |
MaxBatchSize = 1, | |
SegmentId = "XXXXXX" | |
}; | |
var getPlayersInSegmentResult = await PlayFab.PlayFabServerAPI.GetPlayersInSegmentAsync(getPlayersInSegmentRequest); | |
log.LogDebug("getPlayersInSegmentResult - ", getPlayersInSegmentResult); | |
SetTitleDataRequest setTitleDataRequest = new SetTitleDataRequest() | |
{ | |
Key = NUMBER_OF_PLAYER_TODAY_TITLE_DATA_KEY, | |
Value = getPlayersInSegmentResult.Result.ProfilesInSegment.ToString() | |
}; | |
var result = await PlayFab.PlayFabServerAPI.SetTitleDataAsync(setTitleDataRequest); | |
return result.Error != null ? "Update Done" : "Failed"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment