private static async Task PostFunctionResultToPlayFab(EntityPlayStreamFunctionExecutionContext ctx, object result, long executionTime, ILogger log)
 {
     if (ctx.GeneratePlayStreamEvent.HasValue && ctx.GeneratePlayStreamEvent.Value)
     {
         await HelperFunctions.PostResults(ctx, nameof(IdentityQueuedPSV2), result, (int)executionTime, log);
     }
 }
        public static async Task Run(
            [QueueTrigger("identitypsv2", Connection = "AzureWebJobsStorage")] string msg,
            ILogger log)
        {
            Stopwatch sw = Stopwatch.StartNew();

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

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

            // Simulate work
            await Task.Delay(IdentityQueuedPSV2.delayMilliseconds);

            // Post results
            await PostFunctionResultToPlayFab(ctx, ctx.FunctionArgument, sw.ElapsedMilliseconds, log);
        }
        public static Task PostResults(EntityPlayStreamFunctionExecutionContext ctx, string functionName, object functionResult, int executionTime, ILogger log)
        {
            //     public CloudScriptModels.EntityKey Entity { get; set; }
            var request = new PostFunctionResultForEntityTriggeredActionRequest
            {
                Entity = new EntityKey
                {
                    Id   = ctx.CallerEntityProfile.Entity.Id,
                    Type = ctx.CallerEntityProfile.Entity.Type
                },
                //CallerEntityProfile = ctx.CallerEntityProfile,
                //PlayStreamEvent = ctx.PlayStreamEvent,
                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 PostFunctionResultForEntityTriggeredAction
            return(CallPostResultApi("PostFunctionResultForEntityTriggeredAction", ctx.TitleAuthenticationContext, request, log));
        }