private static async Task <bool> EnsureInputExists(string file) { Console.WriteLine($"Checking if input {file} is in bucket {getInputBucketKey()}..."); string localPath = "../../" + s_Config.InputPath + "/" + file; if (!File.Exists(localPath)) { Console.WriteLine($"Cannot read local input file: {localPath}"); return(false); } ForgeRestResponse response = await s_ForgeDmClient.GetBucketObjectDetails(getInputBucketKey(), file); if (!response.IsSuccessStatusCode()) { if (response.Status == HttpStatusCode.Forbidden) { response.ReportError("InputBucketId and OutputBucketId in config.json must be unique (not created by another forge application)"); return(false); } else if (response.Status == HttpStatusCode.NotFound) { Console.WriteLine($"Uploading input {localPath}..."); HttpResponseMessage message = await s_ForgeDmClient.UploadBucketObject(localPath, getInputBucketKey(), file); if (!message.IsSuccessStatusCode) { Console.WriteLine($"Exception uploading input: {response.Status} {response.ResponseContent}"); return(false); } } } else { Console.WriteLine("Found existing input"); } return(true); }
/// <summary> /// Create an activity (or new version of it) /// </summary> /// <returns>true if successful, false otherwise</returns> private static async Task <bool> CreateActivity(string id, string commandLineParameters, JObject parameters) { Console.WriteLine($"Checking if activity {id} exists..."); ForgeRestResponse response = await s_ForgeDaClient.GetActivities(); string activities = response.GetResponseContentProperty("data"); bool activityExists = activities.Contains(id); dynamic payload = new JObject(); payload.engine = s_Config.EngineName; payload.appbundles = new JArray($"{s_nickname}.{s_Config.AppId}+{s_alias}"); payload.commandLine = $"$(engine.path)\\InventorCoreConsole.exe /i \"$(args[{s_Config.ReqInputArgName}].path)\" /al \"$(appbundles[{s_Config.AppId}].path)\" \"$(args[{s_Config.ParamArgNameSmall}].path)\" \"$(args[{s_Config.ParamArgNameLarge}].path)\""; payload.settings = new JObject(); payload.parameters = parameters; if (!activityExists) { Console.WriteLine($"Creating activity {id}..."); payload.id = id; response = await s_ForgeDaClient.PostActivity(payload.ToString()); if (response.ReportIfError("Exception creating activity.")) { return(false); } } else { Console.WriteLine($"Creating new version for activity {id}..."); response = await s_ForgeDaClient.PostActivityVersion(id, payload.ToString()); if (response.ReportIfError("Exception creating activity version.")) { return(false); } } string version = response.GetResponseContentProperty("version"); Console.WriteLine($"Checking if \"{s_alias}\" alias exists for activity {id}"); response = await s_ForgeDaClient.GetActivityAlias(id, s_alias); if (!response.IsSuccessStatusCode() && !(response.Status == HttpStatusCode.NotFound)) { response.ReportError("Exception getting activity alias."); return(false); } payload = new JObject(); payload.version = version; if (response.Status == HttpStatusCode.NotFound) { Console.WriteLine($"Creating new \"{s_alias}\" alias for activity {id}"); payload.id = s_alias; response = await s_ForgeDaClient.PostActivityAlias(id, payload.ToString()); if (response.ReportIfError("Exception creating activity alias.")) { return(false); } } else { Console.WriteLine($"Updating \"{s_alias}\" alias for activity {id}"); response = await s_ForgeDaClient.PatchActivityAlias(id, s_alias, payload.ToString()); if (response.ReportIfError("Exception updating activity alias.")) { return(false); } } return(true); }
/// <summary> /// Create the app (or new version of it) that will be used with both the assembly and part activities and workItems /// </summary> /// <returns>true if successful, false otherwise</returns> private static async Task <bool> CreateApp() { Console.WriteLine($"Checking if app {s_Config.AppId} exists..."); // Check to see if the app exists ForgeRestResponse response = await s_ForgeDaClient.GetAppBundles(); string appsData = response.GetResponseContentProperty("data"); string appName = $"{s_nickname}.{s_Config.AppId}+{s_alias}"; bool appExists = appsData.Contains(appName); dynamic payload = new JObject(); payload.engine = s_Config.EngineName; if (!appExists) { Console.WriteLine($"Creating app {s_Config.AppId}..."); payload.id = s_Config.AppId; response = await s_ForgeDaClient.PostAppBundle(payload.ToString()); if (response.ReportIfError("Exception creating app.")) { return(false); } } else { Console.WriteLine($"Creating new version for app {s_Config.AppId}..."); response = await s_ForgeDaClient.PostAppBundleVersion(s_Config.AppId, payload.ToString()); if (response.ReportIfError("Exception creating app version.")) { return(false); } } JObject responseObj = JObject.Parse(response.ResponseContent); JToken uploadParams = responseObj["uploadParameters"]; if (uploadParams == null) { Console.WriteLine($"App {s_Config.AppId} does not provide upload data."); return(false); } string uploadUrl = uploadParams["endpointURL"]?.ToString(); string version = responseObj["version"]?.ToString(); Console.WriteLine($"Checking if \"{s_alias}\" alias exists for app {s_Config.AppId}"); response = await s_ForgeDaClient.GetAppBundleAlias(s_Config.AppId, s_alias); if (!response.IsSuccessStatusCode() && !(response.Status == HttpStatusCode.NotFound)) { response.ReportError("Exception getting app alias."); return(false); } payload = new JObject(); payload.version = version.ToString(); if (response.Status == HttpStatusCode.NotFound) { Console.WriteLine($"Creating new \"{s_alias}\" alias for app {s_Config.AppId}"); payload.id = s_alias; response = await s_ForgeDaClient.PostAppBundleAlias(s_Config.AppId, payload.ToString()); if (response.ReportIfError("Exception creating app alias.")) { return(false); } } else { Console.WriteLine($"Updating \"{s_alias}\" alias for app {s_Config.AppId}"); response = await s_ForgeDaClient.PatchAppBundleAlias(s_Config.AppId, s_alias, payload.ToString()); if (response.ReportIfError("Exception updating app alias.")) { return(false); } } string absolutePath = Path.GetFullPath("../../" + s_Config.LocalAppPackage); Console.WriteLine($"Uploading zip file " + absolutePath + "..."); bool uploadSuccessful = await UploadFileAsync(uploadParams["formData"], uploadUrl, absolutePath); if (!uploadSuccessful) { Console.WriteLine("Failed to upload zip file."); return(false); } return(true); }