private static async Task PostFunctionResultToPlayFab(FunctionExecutionContext ctx, object result, long executionTime, ILogger log)
 {
     if (ctx.GeneratePlayStreamEvent.HasValue && ctx.GeneratePlayStreamEvent.Value)
     {
         await HelperFunctions.PostResults(ctx, nameof(MatchFoundQueueTriggerTest), result, (int)executionTime, log);
     }
 }
Beispiel #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] FunctionExecutionContext <dynamic> req,
            HttpRequest httpRequest,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            dynamic args = req.FunctionArgument;
            dynamic name = null;

            if (args != null && args["name"] != null)
            {
                name = args["name"];
            }

            string  requestBody = await new StreamReader(httpRequest.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name = name ?? data?.name;

            string responseMessage = Object.ReferenceEquals(null, name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. PlayFab.TitleId:{Settings.TitleId}, PlayFab.TitleSecret:{Settings.TitleSecret}, PlayFab.Cloud:{Settings.Cloud}";

            return(new OkObjectResult(responseMessage));
        }
        public static async Task Run(
            [QueueTrigger("matchqueue", Connection = "AzureWebJobsStorage")] string req,
            ILogger log)
        {
            Stopwatch sw     = Stopwatch.StartNew();
            object    result = null;

            log.LogInformation($"{nameof(MatchFoundQueueTriggerTest)} C# queue trigger function processed a request; {req}");

            var ctx = JsonConvert.DeserializeObject <dynamic>(req);

            var msg = $"context is {JsonConvert.SerializeObject(ctx)}\n";

            log.LogInformation($"{msg}");

            var authCtx = ctx?.TitleAuthenticationContext;
            var payload = ctx?.PlayStreamEvent?.Payload;

            if (payload != null && authCtx != null)
            {
                var titleId   = authCtx?.Id;
                var eToken    = authCtx?.EntityToken;
                var matchId   = payload?.MatchId;
                var queueName = payload?.QueueName;
                //log.LogInformation($"MatchId: {matchId}, QueueName: {queueName}");

                var matchData = await GetMatchRequest(Convert.ToString(titleId), Convert.ToString(eToken), Convert.ToString(matchId), Convert.ToString(queueName), log);

                var members = matchData?.Members;
                var msg2    = $"Members is {JsonConvert.SerializeObject(members)}\n";
                log.LogInformation($"{msg2}");

                var ms       = JsonConvert.DeserializeObject <List <Member> >(JsonConvert.SerializeObject(members));
                var matchIPs = new List <string>();
                foreach (var m in ms)
                {
                    string ip = m.Attributes.DataObject?.MatchIP;
                    if (!string.IsNullOrEmpty(ip))
                    {
                        matchIPs.Add(ip);
                    }
                }

                matchIPs = matchIPs.Distinct().ToList();

                matchIPs.ForEach(x => { SendToMatchServerRequest(x, "9000", Convert.ToString(matchId), Convert.ToString(queueName), log); });

                result = new { Status = "OK", Message = "Success" };
            }
            else
            {
                result = new { Status = "BadRequest", Message = "Authentication Context or PlayStream Payload is missing" };
            }

            // Post results
            FunctionExecutionContext ctx2 = JsonConvert.DeserializeObject <FunctionExecutionContext>(req);

            await PostFunctionResultToPlayFab(ctx2, result, sw.ElapsedMilliseconds, log);
        }
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]  HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            dynamic args = context.FunctionArgument;
            var message = $"Hello {context.CallerEntityProfile.Lineage.MasterPlayerAccountId} (MasterPlayerAccountId)!";
            log.LogInformation(message);
            dynamic inputValue = null;
            if(args != null && args["inputValue"] != null)
            {
            inputValue = args["inputValue"];
            }
            log.LogInformation($"HelloWorld args: {new { input=inputValue}}");
            return new { messageValue = message };
        }
Beispiel #5
0
        public static async Task <dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"{nameof(TimeoutHttpTriggerTest)} C# HTTP trigger function processed a request.");

            FunctionExecutionContext <dynamic> context = JsonConvert.DeserializeObject <FunctionExecutionContext <dynamic> >(await req.ReadAsStringAsync());
            dynamic args = context.FunctionArgument;

            int delayMilliseconds = 0;

            if (args != null && args["delayMilliseconds"] != null)
            {
                delayMilliseconds = args["delayMilliseconds"];
            }
            // Simulate work
            await Task.Delay(delayMilliseconds);

            return(new { delayMilliseconds = delayMilliseconds });
        }
Beispiel #6
0
        public static Task PostResults(FunctionExecutionContext ctx, string functionName, object functionResult, int executionTime, ILogger log)
        {
            var request = new PostFunctionResultForFunctionExecutionRequest
            {
                Entity = new EntityKey
                {
                    Id   = ctx.CallerEntityProfile.Entity.Id,
                    Type = ctx.CallerEntityProfile.Entity.Type,
                },
                FunctionResult = new ExecuteFunctionResult
                {
                    ExecutionTimeMilliseconds = executionTime,
                    Error          = null,
                    FunctionName   = functionName,
                    FunctionResult = functionResult
                }
            };

            // TODO: Replace this code with an SDK call once an SDK is published that supports PostFunctionResultForFunctionExecution
            return(CallPostResultApi("PostFunctionResultForFunctionExecution", ctx.TitleAuthenticationContext, request, log));
        }
        public static async Task <dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"{nameof(GetCharacterInventoryFunc)} C# HTTP trigger function processed a request.");
            var serverSettings = new PlayFab.PlayFabApiSettings()
            {
                TitleId            = Environment.GetEnvironmentVariable("PlayFab.TitleId", EnvironmentVariableTarget.Process),
                DeveloperSecretKey = Environment.GetEnvironmentVariable("PlayFab.TitleSecret", EnvironmentVariableTarget.Process),
            };

            var authAPI       = new PlayFabAuthenticationInstanceAPI(serverSettings);
            var titleResponse = await authAPI.GetEntityTokenAsync(new PlayFab.AuthenticationModels.GetEntityTokenRequest());

            var title      = titleResponse.Result.Entity;
            var titleToken = titleResponse.Result.EntityToken;

            var titleAuthContext = new PlayFabAuthenticationContext();

            titleAuthContext.EntityToken = titleToken;

            FunctionExecutionContext <dynamic> context = JsonConvert.DeserializeObject <FunctionExecutionContext <dynamic> >(await req.ReadAsStringAsync());
            dynamic args    = context.FunctionArgument;
            var     message = $"Args: {args}";

            log.LogInformation(message);

            var request = new GetCharacterInventoryRequest {
                PlayFabId   = args["playfabId"] ?? context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                CharacterId = args["characterId"]
            };

            var serverApi = new PlayFabServerInstanceAPI(serverSettings, titleAuthContext);

            return(await serverApi.GetCharacterInventoryAsync(request));
        }
        public static async Task Run(
            [QueueTrigger("timeoutqueue", Connection = "AzureWebJobsStorage")] string msg,
            ILogger log)
        {
            Stopwatch sw = Stopwatch.StartNew();

            log.LogInformation($"{nameof(TimeoutQueueTriggerTest)} C# queue trigger function processed a request; {msg}");

            FunctionExecutionContext ctx = JsonConvert.DeserializeObject <FunctionExecutionContext>(msg);

            dynamic args = ctx.FunctionArgument;

            int delayMilliseconds = 0;

            if (args != null && args["delayMilliseconds"] != null)
            {
                delayMilliseconds = args["delayMilliseconds"];
            }
            // Simulate work
            await Task.Delay(delayMilliseconds);

            // Post results
            await PostFunctionResultToPlayFab(ctx, ctx.FunctionArgument, sw.ElapsedMilliseconds, log);
        }