public async Task EnsureAppBundle(string contentRootPath) { // get the list and check for the name Page <string> appBundles = await _designAutomation.GetAppBundlesAsync(); bool existAppBundle = false; foreach (string appName in appBundles.Data) { if (appName.Contains(AppBundleFullName)) { existAppBundle = true; continue; } } if (!existAppBundle) { // check if ZIP with bundle is here string packageZipPath = Path.Combine(contentRootPath + "/bundles/", APPBUNBLENAME); if (!File.Exists(packageZipPath)) { throw new Exception("FindColumns appbundle not found at " + packageZipPath); } AppBundle appBundleSpec = new AppBundle() { Package = APPNAME, Engine = ENGINE_NAME, Id = APPNAME, Description = string.Format("Description for {0}", APPBUNBLENAME), }; AppBundle 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(APPNAME, 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); } }
/// <summary> /// Creates Activity /// </summary> private async Task <dynamic> CreateActivity() { Page <string> appBundles = await _designAutomation.GetAppBundlesAsync(); string appBundleID = string.Format("{0}.{1}+{2}", nickName, APPNAME, ALIAS); if (!appBundles.Data.Contains(appBundleID)) { if (!System.IO.File.Exists(LocalAppPackageZip)) { throw new Exception("Appbundle not found at " + LocalAppPackageZip); } AppBundle appBundleSpec = new AppBundle() { Package = APPNAME, Engine = EngineName, Id = APPNAME, Description = string.Format("Description for {0}", APPNAME), }; AppBundle newApp = await _designAutomation.CreateAppBundleAsync(appBundleSpec); if (newApp == 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(APPNAME, aliasSpec); // upload the zip with .bundle RestClient uploadClient = new RestClient(newApp.UploadParameters.EndpointURL); RestRequest request = new RestRequest(string.Empty, Method.POST); request.AlwaysMultipartFormData = true; foreach (KeyValuePair <string, string> x in newApp.UploadParameters.FormData) { request.AddParameter(x.Key, x.Value); } request.AddFile("file", LocalAppPackageZip); request.AddHeader("Cache-Control", "no-cache"); await uploadClient.ExecuteTaskAsync(request); } Page <string> activities = await _designAutomation.GetActivitiesAsync(); string qualifiedActivityId = string.Format("{0}.{1}+{2}", nickName, ACTIVITY_NAME, ALIAS); if (!activities.Data.Contains(qualifiedActivityId)) { // define the activity string commandLine = string.Format(@"$(engine.path)\\inventorcoreconsole.exe /al $(appbundles[{0}].path) $(args[inputJson].path)", APPNAME); Activity activitySpec = new Activity() { Id = ACTIVITY_NAME, Appbundles = new List <string>() { string.Format("{0}.{1}+{2}", nickName, APPNAME, ALIAS) }, CommandLine = new List <string>() { commandLine }, Engine = EngineName, Parameters = new Dictionary <string, Parameter>() { { "inputJson", new Parameter() { Description = "input json", LocalName = "params.json", Ondemand = false, Required = false, Verb = Verb.Get, Zip = false } }, { "ResultIPT", new Parameter() { Description = "output IPT file", LocalName = outputIPTFile, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false } }, { "ResultIDW", new Parameter() { Description = "output IDW file", LocalName = outputIDWFile, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false } }, { "ResultPDF", new Parameter() { Description = "output PDF file", LocalName = outputPDFile, Ondemand = false, Required = true, Verb = Verb.Put, Zip = false } } } }; Activity newActivity = await _designAutomation.CreateActivityAsync(activitySpec); // specify the alias for this Activity Alias aliasSpec = new Alias() { Id = ALIAS, Version = 1 }; Alias newAlias = await _designAutomation.CreateActivityAliasAsync(ACTIVITY_NAME, aliasSpec); return(Ok(new { Activity = qualifiedActivityId })); } return(Ok(new { Activity = "Activity already defined" })); }
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 <IActionResult> CreateAppBundle([FromBody] JObject appBundleSpecs) // { //each call make new instance so every time i is nessessary to read Engine name string EngineName = appBundleSpecs["engine"].Value <string>(); // check if ZIP with bundle is here string packageZipPath = Path.Combine(LocalBundlesFolder, ZipFileName); 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 = packageZipPath, Engine = EngineName, Id = AppBundleName, Description = "Creates wall shelf based on JSON file", }; 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); //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.ExecuteAsync(request); } /* * else // TODO - Remove this code for creating versions. * { * // 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.ExecuteAsync(request); * * return Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version });*/ return(Ok(new { AppBundle = qualifiedAppBundleId, Version = "1" })); }
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 })); }
public async Task <IActionResult> CreateAppBundle() //([FromBody] JObject appBundleSpecs) { // check if ZIP with bundle is here string packageZipPath = Path.Combine(LocalBundlesFolder, ZipFileName); if (!System.IO.File.Exists(packageZipPath)) { throw new Exception("Appbundle not found at " + packageZipPath); } // get defined app bundles - but this line is wrong when running on heroku server instead of localhost. 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 = packageZipPath, //appBundleName, Engine = EngineName, Id = AppBundleName, Description = "Creates an kitchen elements based on template files" }; 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); // 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); } /* 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 });*/ return(Ok(new { AppBundle = qualifiedAppBundleId, Version = "1" })); }