private static async Task <string> CreatePartWorkItem() { Console.WriteLine("Creating part work item..."); ForgeRestResponse response = await s_ForgeDmClient.CreateSignedUrl(getInputBucketKey(), s_Config.InputPartFile); if (response.ReportIfError("Exception creating signed url for work item input.")) { return(null); } string inputSignedUrl = response.GetResponseContentProperty("signedUrl"); JObject payload = new JObject( new JProperty("activityId", $"{s_nickname}.{s_Config.PartAssemblyActivityId}+{s_alias}"), // Must match the input parameter in activity new JProperty("arguments", new JObject( new JProperty(s_Config.ReqInputArgName, new JObject( new JProperty("url", inputSignedUrl) )), // This shows passing parameters and values into the plug-in new JProperty($"{s_Config.ParamArgName}", new JObject( new JProperty("url", "data:application/json,{\"height\":\"16 in\", \"width\":\"10 in\"}") )), // must match the output parameter in activity new JProperty(s_Config.OutputPartArgName, new JObject( new JProperty("url", s_Config.ForgeDMBaseUrl + "buckets/" + getOutputBucketKey() + "/objects/" + s_Config.OutputPartFile), new JProperty("verb", "put"), new JProperty("headers", new JObject( new JProperty("Authorization", s_ForgeDmClient.Authorization), new JProperty("Content-type", "application/octet-stream") )) )), new JProperty(s_Config.OutputImageArgName, new JObject( new JProperty("url", s_Config.ForgeDMBaseUrl + "buckets/" + getOutputBucketKey() + "/objects/" + s_Config.OutputImageFile), new JProperty("verb", "put"), new JProperty("headers", new JObject( new JProperty("Authorization", s_ForgeDmClient.Authorization), new JProperty("Content-type", "application/octet-stream") )) )) )) ); response = await s_ForgeDaClient.PostWorkItem(payload.ToString()); if (response.ReportIfError("Exception creating work item.")) { return(null); } string workItemId = response.GetResponseContentProperty("id"); if (string.IsNullOrEmpty(workItemId)) { Console.WriteLine("Failed to post work item"); return(null); } return(workItemId); }
private static async Task <string> GetSignedInputUrl(string strFile) { ForgeRestResponse responseFile = await s_ForgeDmClient.CreateSignedUrl(getInputBucketKey(), strFile); if (responseFile.ReportIfError("Exception creating signed url")) { return(null); } return(responseFile.GetResponseContentProperty("signedUrl")); }
static async Task MainAsync(string[] args) { try { LoadConfig(); // Create DesignAutomation object for making REST calls to the DesignAutomation APIs s_ForgeDaClient = new ForgeDaClient(s_Config.InventorIOBaseUrl, s_Creds.ConsumerKey, s_Creds.ConsumerSecret); // Get the user's nickname for querying if apps and activities exist. If no nickname is set, the forge app id will be returned ForgeRestResponse response = await s_ForgeDaClient.GetNickname(); if (!response.ReportIfError("Error retrieving nickname for user.")) { string content = response.ResponseContent; s_nickname = content.Replace("\"", String.Empty); } else { return; } // Create Forge DM object for making REST calls to the Forge Data Management APIs s_ForgeDmClient = new ForgeDmClient(s_Config.ForgeDMBaseUrl, s_Creds.ConsumerKey, s_Creds.ConsumerSecret); // Create the input bucket for input files if necessary if (!await EnsureBucketExists(getInputBucketKey())) { return; } // Upload part input if necessary if (!await EnsureInputExists(s_Config.InputPartFile)) { return; } // Upload assembly input if necessary if (!await EnsureInputExists(s_Config.InputAssemblyZipFile)) { return; } // Create the output bucket for result files if necessary if (!await EnsureBucketExists(getOutputBucketKey())) { return; } if (!await CreateApp()) { return; } // Setup a part & assembly activity to show how to interact with an Inventor Part file and assembly zip file if (!await CreatePartAssemblyActivity()) { return; } // Create a part activity work item string workItemId = await CreatePartWorkItem(); if (workItemId == null) { return; } // Wait for the result of the work item string status; do { Console.WriteLine("Sleeping for 2 sec..."); Thread.Sleep(2000); response = await s_ForgeDaClient.GetWorkItem(workItemId); if (response.ReportIfError("Exception getting work item status.")) { return; } status = response.GetResponseContentProperty("status"); Console.WriteLine($"Work item status: {status}"); }while (status == "pending" || status == "inprogress"); string reportUrl = response.GetResponseContentProperty("reportUrl"); if (status != "success") { Console.WriteLine("Work item failed. Writing report log to: " + s_Config.ErrorReport); DownloadToDocs(reportUrl, s_Config.ErrorReport); return; } Console.WriteLine("Writing report log to: " + s_Config.partReport); DownloadToDocs(reportUrl, s_Config.partReport); response = await s_ForgeDmClient.CreateSignedUrl(getOutputBucketKey(), s_Config.OutputPartFile); string outputDownloadUrl = response.GetResponseContentProperty("signedUrl"); DownloadToDocs(outputDownloadUrl, s_Config.OutputPartFile); // Create an assembly activity work item workItemId = await CreateAssemblyWorkItem(); if (workItemId == null) { return; } // Wait for the result of the work item do { Console.WriteLine("Sleeping for 2 sec..."); Thread.Sleep(2000); response = await s_ForgeDaClient.GetWorkItem(workItemId); if (response.ReportIfError("Exception getting work item status.")) { return; } status = response.GetResponseContentProperty("status"); Console.WriteLine($"Work item status: {status}"); }while (status == "pending" || status == "inprogress"); reportUrl = response.GetResponseContentProperty("reportUrl"); if (status != "success") { Console.WriteLine("Work item failed. Writing report log to: " + s_Config.ErrorReport); DownloadToDocs(reportUrl, s_Config.ErrorReport); return; } Console.WriteLine("Writing report log to: " + s_Config.assemblyReport); DownloadToDocs(reportUrl, s_Config.assemblyReport); response = await s_ForgeDmClient.CreateSignedUrl(getOutputBucketKey(), s_Config.OutputZipAssemblyFile); outputDownloadUrl = response.GetResponseContentProperty("signedUrl"); DownloadToDocs(outputDownloadUrl, s_Config.OutputZipAssemblyFile); } catch (Exception e) { Console.WriteLine($"Exception: {e.ToString()}"); } finally { Console.WriteLine("Press any key to exit."); Console.ReadKey(); } }