private async Task <dynamic> CreateNewVersion(string engineName, string appBundleName, string Alias) { AppBundle appBundleSpec = new AppBundle() { Engine = engineName, Description = appBundleName }; dynamic newAppVersion = await _repository.CreateAppBundleVersionAsync(appBundleName, appBundleSpec); CheckOutToNull(newAppVersion); AliasPatch aliasPatch = new AliasPatch() { Version = newAppVersion.Version }; await _repository.ModifyAsync(appBundleName, Alias, aliasPatch); return(newAppVersion); }
private async Task <AppBundle> UpdateBundleAsync(string engine, string packageName) { var bundle = new AppBundle(); bundle.Engine = engine; bundle.Description = $"Grid Generator: {packageName}"; var bundleVersion = await designAutoClient.CreateAppBundleVersionAsync(packageName, bundle); if (bundleVersion == null) { throw new Exception("Error trying to update existing bundle version"); } var alias = new AliasPatch(); alias.Version = (int)bundleVersion.Version; await this.designAutoClient.ModifyAppBundleAliasAsync(packageName, this.forgeEnv, alias); return(bundleVersion); }
public async Task <IActionResult> CreateAppBundle([FromBody] JObject appBundleSpecs) { // basic input validation string zipFileName = appBundleSpecs["zipFileName"].Value <string>(); string engineName = appBundleSpecs["engine"].Value <string>(); // standard name for this sample string appBundleName = zipFileName + "AppBundle"; // check if ZIP with bundle is here string packageZipPath = Path.Combine(LocalBundlesFolder, zipFileName + ".zip"); if (!System.IO.File.Exists(packageZipPath)) { throw new Exception("Appbundle not found at " + packageZipPath); } // get defined app bundles Page <string> appBundles = await _designAutomation.GetAppBundlesAsync(); // check if app bundle is already define dynamic newAppVersion; string qualifiedAppBundleId = string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias); if (!appBundles.Data.Contains(qualifiedAppBundleId)) { // create an appbundle (version 1) AppBundle appBundleSpec = new AppBundle() { Package = appBundleName, Engine = engineName, Id = appBundleName, Description = string.Format("Description for {0}", appBundleName), }; newAppVersion = await _designAutomation.CreateAppBundleAsync(appBundleSpec); if (newAppVersion == null) { throw new Exception("Cannot create new app"); } // create alias pointing to v1 Alias aliasSpec = new Alias() { Id = Alias, Version = 1 }; Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(appBundleName, aliasSpec); } else { // create new version AppBundle appBundleSpec = new AppBundle() { Engine = engineName, Description = appBundleName }; newAppVersion = await _designAutomation.CreateAppBundleVersionAsync(appBundleName, appBundleSpec); if (newAppVersion == null) { throw new Exception("Cannot create new version"); } // update alias pointing to v+1 AliasPatch aliasSpec = new AliasPatch() { Version = newAppVersion.Version }; Alias newAlias = await _designAutomation.ModifyAppBundleAliasAsync(appBundleName, Alias, aliasSpec); } // upload the zip with .bundle RestClient uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL); RestRequest request = new RestRequest(string.Empty, Method.POST); request.AlwaysMultipartFormData = true; foreach (KeyValuePair <string, string> x in newAppVersion.UploadParameters.FormData) { request.AddParameter(x.Key, x.Value); } request.AddFile("file", packageZipPath); request.AddHeader("Cache-Control", "no-cache"); await uploadClient.ExecuteTaskAsync(request); return(Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version })); }
public async Task <Alias> ModifyAsync(string appBundleName, string Alias, AliasPatch aliasSpec) { return(await _designAutomation.ModifyAppBundleAliasAsync(appBundleName, Alias, aliasSpec)); }
public async Task <IActionResult> CreateAppBundle([FromBody] JObject appBundleSpecs) { // 基本入力検証 string zipFileName = appBundleSpecs["zipFileName"].Value <string>(); string engineName = appBundleSpecs["engine"].Value <string>(); // このサンプルの標準名 string appBundleName = zipFileName + "AppBundle"; // ZIP with bundle がここに存在するかどうかを確認する string packageZipPath = Path.Combine(LocalBundlesFolder, zipFileName + ".zip"); if (!System.IO.File.Exists(packageZipPath)) { throw new Exception("Appbundle not found at " + packageZipPath); } // アプリケーションバンドルを定義する Page <string> appBundles = await _designAutomation.GetAppBundlesAsync(); // アプリケーションバンドルがすでに定義されているかどうかを確認する dynamic newAppVersion; string qualifiedAppBundleId = string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias); if (!appBundles.Data.Contains(qualifiedAppBundleId)) { // appbundle(version 1)を作成す AppBundle appBundleSpec = new AppBundle() { Package = appBundleName, Engine = engineName, Id = appBundleName, Description = string.Format("Description for {0}", appBundleName), }; newAppVersion = await _designAutomation.CreateAppBundleAsync(appBundleSpec); if (newAppVersion == null) { throw new Exception("Cannot create new app"); } // v1を指すエイリアスを作成する Alias aliasSpec = new Alias() { Id = Alias, Version = 1 }; Alias newAlias = await _designAutomation.CreateAppBundleAliasAsync(appBundleName, aliasSpec); } else { // 新しいバージョンを作成する AppBundle appBundleSpec = new AppBundle() { Engine = engineName, Description = appBundleName }; newAppVersion = await _designAutomation.CreateAppBundleVersionAsync(appBundleName, appBundleSpec); if (newAppVersion == null) { throw new Exception("Cannot create new version"); } // v+1を指す更新エイリアス AliasPatch aliasSpec = new AliasPatch() { Version = newAppVersion.Version }; Alias newAlias = await _designAutomation.ModifyAppBundleAliasAsync(appBundleName, Alias, aliasSpec); } // .bundleでzipをアップロードする RestClient uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL); RestRequest request = new RestRequest(string.Empty, Method.POST); request.AlwaysMultipartFormData = true; foreach (KeyValuePair <string, string> x in newAppVersion.UploadParameters.FormData) { request.AddParameter(x.Key, x.Value); } request.AddFile("file", packageZipPath); request.AddHeader("Cache-Control", "no-cache"); await uploadClient.ExecuteTaskAsync(request); return(Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version })); }
/// <summary> /// Modify alias details. Modify alias details. /// </summary> /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception> /// <param name="id">Name of AppBundle (unqualified).</param>/// <param name="aliasId">Name of alias.</param>/// <param name="alias">Alias details to be modified.</param> /// <returns>Task of ApiResponse<Alias></returns> public async System.Threading.Tasks.Task <ApiResponse <Alias> > ModifyAppBundleAliasAsync(string id, string aliasId, AliasPatch alias, string scopes = null, IDictionary <string, string> headers = null, bool throwOnError = true) { using (var request = new HttpRequestMessage()) { request.RequestUri = Marshalling.BuildRequestUri("/v3/appbundles/{id}/aliases/{aliasId}", routeParameters: new Dictionary <string, object> { { "id", id }, { "aliasId", aliasId }, }, queryParameters: new Dictionary <string, object> { } ); request.Headers.TryAddWithoutValidation("Accept", "application/json"); if (headers != null) { foreach (var header in headers) { request.Headers.TryAddWithoutValidation(header.Key, header.Value); } } request.Content = Marshalling.Serialize(alias); // http body (model) parameter // tell the underlying pipeline what scope we'd like to use if (scopes == null) { request.Properties.Add(ForgeConfiguration.ScopeKey, "code:all"); } else { request.Properties.Add(ForgeConfiguration.ScopeKey, scopes); } request.Method = new HttpMethod("PATCH"); // make the HTTP request var response = await this.Service.Client.SendAsync(request); if (throwOnError) { await response.EnsureSuccessStatusCodeAsync(); } else if (!response.IsSuccessStatusCode) { return(new ApiResponse <Alias>(response, default(Alias))); } return(new ApiResponse <Alias>(response, await Marshalling.DeserializeAsync <Alias>(response.Content))); } // using }
/// <summary> /// Modify alias details. /// </summary> /// <remarks> /// Modify alias details. /// </remarks> /// <exception cref="HttpRequestException">Thrown when fails to make API call</exception> /// <param name="id">Name of AppBundle (unqualified).</param> /// <param name="aliasId">Name of alias.</param> /// <param name="alias">Alias details to be modified.</param> /// <returns>Task of Alias</returns> public async System.Threading.Tasks.Task <Alias> ModifyAppBundleAliasAsync(string id, string aliasId, AliasPatch alias) { var response = await this.AppBundlesApi.ModifyAppBundleAliasAsync(id, aliasId, alias); return(response.Content); }