From 07cd3e985504858a7b39c9ed50b998430e0378e5 Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Sun, 31 Oct 2021 03:42:19 +0100 Subject: [PATCH] Add CloudScript models --- .../Controllers/CloudScriptController.cs | 26 ++++++ .../Client/Data/CloudScriptRevisionOption.cs | 9 ++ .../Client/Data/FFunctionExecutionError.cs | 29 +++++++ .../Models/Client/Data/FLogStatement.cs | 28 ++++++ .../Client/Data/FScriptExecutionError.cs | 29 +++++++ .../Client/FExecuteCloudScriptResult.cs | 85 +++++++++++++++++++ .../FExecuteCloudScriptServerRequest.cs | 60 +++++++++++++ .../Models/Client/FExecuteFunctionRequest.cs | 44 ++++++++++ .../Models/Client/FExecuteFunctionResult.cs | 41 +++++++++ .../Models/Client/FGetUserInventoryRequest.cs | 1 + .../FUpdateUserTitleDisplayNameRequest.cs | 1 + 11 files changed, 353 insertions(+) create mode 100644 src/Prospect.Server.Api/Controllers/CloudScriptController.cs create mode 100644 src/Prospect.Server.Api/Models/Client/Data/CloudScriptRevisionOption.cs create mode 100644 src/Prospect.Server.Api/Models/Client/Data/FFunctionExecutionError.cs create mode 100644 src/Prospect.Server.Api/Models/Client/Data/FLogStatement.cs create mode 100644 src/Prospect.Server.Api/Models/Client/Data/FScriptExecutionError.cs create mode 100644 src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptResult.cs create mode 100644 src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptServerRequest.cs create mode 100644 src/Prospect.Server.Api/Models/Client/FExecuteFunctionRequest.cs create mode 100644 src/Prospect.Server.Api/Models/Client/FExecuteFunctionResult.cs diff --git a/src/Prospect.Server.Api/Controllers/CloudScriptController.cs b/src/Prospect.Server.Api/Controllers/CloudScriptController.cs new file mode 100644 index 0000000..893298a --- /dev/null +++ b/src/Prospect.Server.Api/Controllers/CloudScriptController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; +using Prospect.Server.Api.Models.Client; + +namespace Prospect.Server.Api.Controllers +{ + [Route("CloudScript")] + [ApiController] + public class CloudScriptController : Controller + { + [HttpPost("ExecuteFunction")] + [Produces("application/json")] + public IActionResult ExecuteFunction(FExecuteFunctionRequest request) + { + return Ok(new ClientResponse + { + Code = 200, + Status = "OK", + Data = new FExecuteFunctionResult + { + ExecutionTimeMilliseconds = 12, + FunctionName = request.FunctionName + } + }); + } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/Data/CloudScriptRevisionOption.cs b/src/Prospect.Server.Api/Models/Client/Data/CloudScriptRevisionOption.cs new file mode 100644 index 0000000..11789ae --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/Data/CloudScriptRevisionOption.cs @@ -0,0 +1,9 @@ +namespace Prospect.Server.Api.Models.Client.Data +{ + public enum CloudScriptRevisionOption + { + Live, + Latest, + Specific + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/Data/FFunctionExecutionError.cs b/src/Prospect.Server.Api/Models/Client/Data/FFunctionExecutionError.cs new file mode 100644 index 0000000..52210ae --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/Data/FFunctionExecutionError.cs @@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; + +namespace Prospect.Server.Api.Models.Client.Data +{ + public class FFunctionExecutionError + { + /// + /// [optional] Error code, such as CloudScriptAzureFunctionsExecutionTimeLimitExceeded, CloudScriptAzureFunctionsArgumentSizeExceeded, + /// CloudScriptAzureFunctionsReturnSizeExceeded or CloudScriptAzureFunctionsHTTPRequestError + /// + [JsonPropertyName("Error")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Error { get; set; } + + /// + /// [optional] Details about the error + /// + [JsonPropertyName("Message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Message { get; set; } + + /// + /// [optional] Point during the execution of the function at which the error occurred, if any + /// + [JsonPropertyName("StackTrace")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string StackTrace { get; set; } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/Data/FLogStatement.cs b/src/Prospect.Server.Api/Models/Client/Data/FLogStatement.cs new file mode 100644 index 0000000..2e1d178 --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/Data/FLogStatement.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; + +namespace Prospect.Server.Api.Models.Client.Data +{ + public class FLogStatement + { + /// + /// [optional] Optional object accompanying the message as contextual information + /// + [JsonPropertyName("Data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public object Data { get; set; } + + /// + /// [optional] 'Debug', 'Info', or 'Error' + /// + [JsonPropertyName("Level")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Level { get; set; } + + /// + /// [optional] undefined + /// + [JsonPropertyName("Message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/Data/FScriptExecutionError.cs b/src/Prospect.Server.Api/Models/Client/Data/FScriptExecutionError.cs new file mode 100644 index 0000000..e88af0f --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/Data/FScriptExecutionError.cs @@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; + +namespace Prospect.Server.Api.Models.Client.Data +{ + public class FScriptExecutionError + { + /// + /// [optional] Error code, such as CloudScriptNotFound, JavascriptException, CloudScriptFunctionArgumentSizeExceeded, + /// CloudScriptAPIRequestCountExceeded, CloudScriptAPIRequestError, or CloudScriptHTTPRequestError + /// + [JsonPropertyName("Error")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Error { get; set; } + + /// + /// [optional] Details about the error + /// + [JsonPropertyName("Message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Message { get; set; } + + /// + /// [optional] Point during the execution of the script at which the error occurred, if any + /// + [JsonPropertyName("StackTrace")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string StackTrace { get; set; } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptResult.cs b/src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptResult.cs new file mode 100644 index 0000000..6af4ae3 --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptResult.cs @@ -0,0 +1,85 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using Prospect.Server.Api.Models.Client.Data; + +namespace Prospect.Server.Api.Models.Client +{ + public class FExecuteCloudScriptResult + { + /// + /// Number of PlayFab API requests issued by the CloudScript function + /// + [JsonPropertyName("APIRequestsIssued")] + public int APIRequestsIssued { get; set; } + + /// + /// [optional] Information about the error, if any, that occurred during execution + /// + [JsonPropertyName("Error")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public FScriptExecutionError Error { get; set; } + + [JsonPropertyName("ExecutionTimeSeconds")] + public double? ExecutionTimeSeconds { get; set; } + + /// + /// [optional] The name of the function that executed + /// + [JsonPropertyName("FunctionName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string FunctionName { get; set; } + + /// + /// [optional] The object returned from the CloudScript function, if any + /// + [JsonPropertyName("FunctionResult")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public object FunctionResult { get; set; } + + /// + /// [optional] Flag indicating if the FunctionResult was too large and was subsequently dropped from this event. This only occurs if + /// the total event size is larger than 350KB. + /// + [JsonPropertyName("FunctionResultTooLarge")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? FunctionResultTooLarge { get; set; } + + /// + /// Number of external HTTP requests issued by the CloudScript function + /// + [JsonPropertyName("HttpRequestsIssued")] + public int HttpRequestsIssued { get; set; } + + /// + /// [optional] Entries logged during the function execution. These include both entries logged in the function code using log.info() + /// and log.error() and error entries for API and HTTP request failures. + /// + [JsonPropertyName("Logs")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public List Logs { get; set; } + + /// + /// [optional] Flag indicating if the logs were too large and were subsequently dropped from this event. This only occurs if the total + /// event size is larger than 350KB after the FunctionResult was removed. + /// + [JsonPropertyName("LogsTooLarge")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? LogsTooLarge { get; set; } + + [JsonPropertyName("MemoryConsumedBytes")] + public uint MemoryConsumedBytes { get; set; } + + /// + /// Processor time consumed while executing the function. This does not include time spent waiting on API calls or HTTP + /// requests. + /// + [JsonPropertyName("ProcessorTimeSeconds")] + public double ProcessorTimeSeconds { get; set; } + + /// + /// The revision of the CloudScript that executed + /// + [JsonPropertyName("Revision")] + public int Revision { get; set; } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptServerRequest.cs b/src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptServerRequest.cs new file mode 100644 index 0000000..f11db87 --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/FExecuteCloudScriptServerRequest.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using Prospect.Server.Api.Models.Client.Data; + +namespace Prospect.Server.Api.Models.Client +{ + public class FExecuteCloudScriptServerRequest + { + /// + /// [optional] The optional custom tags associated with the request (e.g. build number, external trace identifiers, etc.). + /// + [JsonPropertyName("CustomTags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public Dictionary CustomTags { get; set; } + + /// + /// The name of the CloudScript function to execute + /// + [JsonPropertyName("FunctionName")] + public string FunctionName { get; set; } + + /// + /// [optional] Object that is passed in to the function as the first argument + /// + [JsonPropertyName("FunctionParameter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string FunctionParameter { get; set; } + + /// + /// [optional] Generate a 'player_executed_cloudscript' PlayStream event containing the results of the function execution and other + /// contextual information. This event will show up in the PlayStream debugger console for the player in Game Manager. + /// + [JsonPropertyName("GeneratePlayStreamEvent")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? GeneratePlayStreamEvent { get; set; } + + /// + /// The unique user identifier for the player on whose behalf the script is being run + /// + [JsonPropertyName("PlayFabId")] + public string PlayFabId { get; set; } + + /// + /// [optional] Option for which revision of the CloudScript to execute. 'Latest' executes the most recently created revision, 'Live' + /// executes the current live, published revision, and 'Specific' executes the specified revision. The default value is + /// 'Specific', if the SpeificRevision parameter is specified, otherwise it is 'Live'. + /// + [JsonPropertyName("RevisionSelection")] + [JsonConverter(typeof(JsonStringEnumConverter))] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public CloudScriptRevisionOption? RevisionSelection { get; set; } + + /// + /// [optional] The specivic revision to execute, when RevisionSelection is set to 'Specific' + /// + [JsonPropertyName("SpecificRevision")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public int? SpecificRevision { get; set; } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/FExecuteFunctionRequest.cs b/src/Prospect.Server.Api/Models/Client/FExecuteFunctionRequest.cs new file mode 100644 index 0000000..5d12eed --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/FExecuteFunctionRequest.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using Prospect.Server.Api.Models.Client.Data; + +namespace Prospect.Server.Api.Models.Client +{ + public class FExecuteFunctionRequest + { + /// + /// [optional] The optional custom tags associated with the request (e.g. build number, external trace identifiers, etc.). + /// + [JsonPropertyName("CustomTags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public Dictionary CustomTags { get; set; } + + /// + /// [optional] The entity to perform this action on. + /// + [JsonPropertyName("Entity")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public FEntityKey Entity { get; set; } + + /// + /// The name of the CloudScript function to execute + /// + [JsonPropertyName("FunctionName")] + public string FunctionName { get; set; } + + /// + /// [optional] Object that is passed in to the function as the FunctionArgument field of the FunctionExecutionContext data structure + /// + [JsonPropertyName("FunctionParameter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string FunctionParameter { get; set; } + + /// + /// [optional] Generate a 'entity_executed_cloudscript_function' PlayStream event containing the results of the function execution and + /// other contextual information. This event will show up in the PlayStream debugger console for the player in Game Manager. + /// + [JsonPropertyName("GeneratePlayStreamEvent")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? GeneratePlayStreamEvent { get; set; } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/FExecuteFunctionResult.cs b/src/Prospect.Server.Api/Models/Client/FExecuteFunctionResult.cs new file mode 100644 index 0000000..e5af4c0 --- /dev/null +++ b/src/Prospect.Server.Api/Models/Client/FExecuteFunctionResult.cs @@ -0,0 +1,41 @@ +using System.Text.Json.Serialization; +using Prospect.Server.Api.Models.Client.Data; + +namespace Prospect.Server.Api.Models.Client +{ + public class FExecuteFunctionResult + { + /// + /// [optional] Error from the CloudScript Azure Function. + /// + [JsonPropertyName("Error")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public FFunctionExecutionError Error { get; set; } + + /// + /// The amount of time the function took to execute + /// + [JsonPropertyName("ExecutionTimeMilliseconds")] + public int ExecutionTimeMilliseconds { get; set; } + + /// + /// [optional] The name of the function that executed + /// + [JsonPropertyName("FunctionName")] + public string FunctionName { get; set; } + + /// + /// [optional] The object returned from the function, if any + /// + [JsonPropertyName("FunctionResult")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public object FunctionResult { get; set; } + + /// + /// [optional] Flag indicating if the FunctionResult was too large and was subsequently dropped from this event. + /// + [JsonPropertyName("FunctionResultTooLarge")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? FunctionResultTooLarge { get; set; } + } +} \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/FGetUserInventoryRequest.cs b/src/Prospect.Server.Api/Models/Client/FGetUserInventoryRequest.cs index de6ea89..ce58d39 100644 --- a/src/Prospect.Server.Api/Models/Client/FGetUserInventoryRequest.cs +++ b/src/Prospect.Server.Api/Models/Client/FGetUserInventoryRequest.cs @@ -9,6 +9,7 @@ namespace Prospect.Server.Api.Models.Client /// [optional] The optional custom tags associated with the request (e.g. build number, external trace identifiers, etc.). /// [JsonPropertyName("CustomTags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Dictionary CustomTags { get; set; } } } \ No newline at end of file diff --git a/src/Prospect.Server.Api/Models/Client/FUpdateUserTitleDisplayNameRequest.cs b/src/Prospect.Server.Api/Models/Client/FUpdateUserTitleDisplayNameRequest.cs index 8fa99f3..051b5a3 100644 --- a/src/Prospect.Server.Api/Models/Client/FUpdateUserTitleDisplayNameRequest.cs +++ b/src/Prospect.Server.Api/Models/Client/FUpdateUserTitleDisplayNameRequest.cs @@ -9,6 +9,7 @@ namespace Prospect.Server.Api.Models.Client /// [optional] The optional custom tags associated with the request (e.g. build number, external trace identifiers, etc.). /// [JsonPropertyName("CustomTags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Dictionary CustomTags { get; set; } ///