private void ExecExecute(KiiServerCodeEntryArgument argument, KiiHttpClientFactory factory, KiiServerCodeEntryCallback callback) { if (argument == null) { argument = KiiServerCodeEntryArgument.NewArgument(new JsonObject()); } string url = Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "server-code", "versions", this.version, this.entryName); if (this.environmentVersion.HasValue) { url += "?environment-version=" + this.environmentVersion.Value.GetValue(); } KiiHttpClient client = factory.Create(url, Kii.AppId, Kii.AppKey, KiiHttpMethod.POST); KiiCloudEngine.SetAuthBearer(client); client.ContentType = "application/json"; client.SendRequest(argument.ToJson().ToString(), (ApiResponse response, Exception e) => { if (callback == null) { return; } if (e != null) { callback(this, argument, null, e); return; } // parse X-step-count int steps; try { steps = int.Parse(response.GetHeader("X-Step-count")); } catch { steps = 0; } // X-Environment-version KiiServerCodeEnvironmentVersion?environmentVersion = KiiServerCodeEnvironmentVersionExtensions.FromValue(response.GetHeader("X-Environment-version")); // parse body JsonObject resultBody; try { resultBody = new JsonObject(response.Body); } catch (JsonException e2) { callback(this, argument, null, new IllegalKiiBaseObjectFormatException(e2.Message)); return; } callback(this, argument, new KiiServerCodeExecResult(resultBody, steps, environmentVersion), null); }); }
/// <summary> /// Asynchronous version of <see cref = 'Execute(KiiServerCodeEntryArgument)'/>. /// </summary> /// <remarks> /// This API will be executed on background thread. /// </remarks> /// <param name="argument"> /// The argument that will be passed to the entry of script in the cloud. /// If null is specified, no argument will be passed to the script. /// </param> /// <param name="callback"> /// Callback. /// </param> public void Execute(KiiServerCodeEntryArgument argument, KiiServerCodeEntryCallback callback) { ExecExecute(argument, Kii.AsyncHttpClientFactory, callback); }