Exemplo n.º 1
0
        protected override IPromise <JsonValue> PerformFacetCall(
            string facetName,
            string methodName,
            JsonArray arguments
            )
        {
            var promise = new Promise <JsonValue>();

            http.Post(
                app.Resolve <ApiUrl>().CallFacet(),
                new JsonObject()
                .Add("facetName", facetName)
                .Add("methodName", methodName)
                .Add("arguments", arguments)
                .Add("sessionId", SessionId)
                .Add("deviceId", DeviceIdRepository.GetDeviceId())
                .Add("device", DeviceIdRepository.GetDeviceInfo())
                .Add("gameToken", app.Preferences.GameToken)
                .Add("editorKey", app.Preferences.EditorKey)
                .Add("client", new JsonObject()
                     .Add("backendHash", app.Preferences.BackendHash)
                     .Add("frameworkVersion", FrameworkMeta.Version)
                     .Add("assetVersion", AssetMeta.Version)
                     .Add("buildGuid", Application.buildGUID)
                     .Add("versionString", Application.version)
                     ),
                response => {
                if (response.IsOk)
                {
                    HandleSuccessfulRequest(response, promise);
                }
                else
                {
                    HandleFailedRequest(response, promise);
                }
            }
                );

            return(promise);
        }
        protected override IPromise <JsonValue> PerformFacetCall(
            string facetName,
            string methodName,
            JsonArray arguments
            )
        {
            var promise = new Promise <JsonValue>();

            Http.Post(
                app.Resolve <ApiUrl>().CallFacet(),
                new JsonObject()
                .Add("facetName", facetName)
                .Add("methodName", methodName)
                .Add("arguments", arguments)
                .Add("sessionId", SessionId)
                .Add("deviceId", DeviceIdRepository.GetDeviceId())
                .Add("device", DeviceIdRepository.GetDeviceInfo())
                .Add("gameToken", app.Preferences.GameToken)
                .Add("editorKey", app.Preferences.EditorKey)
                .Add("client", new JsonObject()
                     .Add("backendHash", app.Preferences.BackendHash)
                     .Add("frameworkVersion", FrameworkMeta.Version)
                     .Add("assetVersion", AssetMeta.Version)
                     .Add("buildGuid", Application.buildGUID)
                     .Add("versionString", Application.version)
                     ),
                "200"
                ).Then(response => {
                JsonObject executionResult = response["executionResult"];

                JsonObject specialValues = executionResult["special"].AsJsonObject
                                           ?? new JsonObject();

                // remember the session id
                string givenSessionId = specialValues["sessionId"].AsString;
                if (givenSessionId != null)
                {
                    SessionId = givenSessionId;
                }

                // print logs
                LogPrinter.PrintLogsFromFacetCall(specialValues["logs"]);

                switch (executionResult["result"].AsString)
                {
                case "ok":
                    promise.Resolve(executionResult["returned"]);
                    break;

                case "exception":
                    var e = Serializer.FromJson <Exception>(
                        executionResult["exception"]
                        );
                    PreserveStackTrace(e);
                    promise.Reject(e);
                    break;

                default:
                    promise.Reject(
                        new UnisaveException(
                            "Server sent unknown response for facet call:\n"
                            + response
                            )
                        );
                    break;
                }
            }).Catch(e => {
                if (e is HttpException he)
                {
                    if (he.Response.StatusCode == 422)
                    {
                        Debug.LogError(
                            "Facet call failed:\n" + he.Response.TextContent
                            );
                    }
                }

                promise.Reject(e);
            });

            return(promise);
        }