/// <summary>
        /// Generate a PlayStream event for the provided function result.
        /// </summary>
        public void PostFunctionResultForScheduledTask(PostFunctionResultForScheduledTaskRequest request, Action <EmptyResult> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            var context      = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
            var callSettings = apiSettings ?? PlayFabSettings.staticSettings;

            if (!context.IsEntityLoggedIn())
            {
                throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn, "Must be logged in to call this method");
            }
            PlayFabHttp.MakeApiCall("/CloudScript/PostFunctionResultForScheduledTask", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
        }
Пример #2
0
        public static Task PostResults(ScheduledTaskFunctionExecutionContext ctx, string functionName, object functionResult, int executionTime, ILogger log)
        {
            var request = new PostFunctionResultForScheduledTaskRequest
            {
                Entity = new EntityKey
                {
                    Id   = ctx.TitleAuthenticationContext.Id,
                    Type = "title"
                },
                ScheduledTaskId = ctx.ScheduledTaskNameId,
                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 PostFunctionResultForScheduledTask
            return(CallPostResultApi("PostFunctionResultForScheduledTask", ctx.TitleAuthenticationContext, request, log));
        }
        /// <summary>
        /// Generate a PlayStream event for the provided function result.
        /// </summary>
        public async Task <PlayFabResult <EmptyResult> > PostFunctionResultForScheduledTaskAsync(PostFunctionResultForScheduledTaskRequest request, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            await new PlayFabUtil.SynchronizationContextRemover();

            var requestContext  = request?.AuthenticationContext ?? authenticationContext;
            var requestSettings = apiSettings ?? PlayFabSettings.staticSettings;

            if (requestContext.EntityToken == null)
            {
                throw new PlayFabException(PlayFabExceptionCode.EntityTokenNotSet, "Must call Client Login or GetEntityToken before calling this method");
            }

            var httpResult = await PlayFabHttp.DoPost("/CloudScript/PostFunctionResultForScheduledTask", request, "X-EntityToken", requestContext.EntityToken, extraHeaders, requestSettings);

            if (httpResult is PlayFabError)
            {
                var error = (PlayFabError)httpResult;
                PlayFabSettings.GlobalErrorHandler?.Invoke(error);
                return(new PlayFabResult <EmptyResult> {
                    Error = error, CustomData = customData
                });
            }

            var resultRawJson = (string)httpResult;
            var resultData    = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <PlayFabJsonSuccess <EmptyResult> >(resultRawJson);
            var result        = resultData.data;

            return(new PlayFabResult <EmptyResult> {
                Result = result, CustomData = customData
            });
        }