Beispiel #1
0
        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 part params if necessary
                if (!await EnsureInputExists(s_Config.ParamFileLarge))
                {
                    return;
                }

                // Upload images
                if (!await EnsureInputExists(s_Config.LightFile))
                {
                    return;
                }
                if (!await EnsureInputExists(s_Config.HeavyFile))
                {
                    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);
                DownloadToDocs(await GetSignedOutputUrl(s_Config.OutputPartSmallFile), s_Config.OutputPartSmallFile);
                DownloadToDocs(await GetSignedOutputUrl(s_Config.OutputPartLargeFile), s_Config.OutputPartLargeFile);
                DownloadToDocs(await GetSignedOutputUrl(s_Config.OutputPartSmallThumb), s_Config.OutputPartSmallThumb);
                DownloadToDocs(await GetSignedOutputUrl(s_Config.OutputPartLargeThumb), s_Config.OutputPartLargeThumb);
                DownloadToDocs(await GetSignedOutputUrl(s_Config.OutputImageSmallFile), s_Config.OutputImageSmallFile);
                DownloadToDocs(await GetSignedOutputUrl(s_Config.OutputImageLargeFile), s_Config.OutputImageLargeFile);

                // 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);
                DownloadToDocs(await GetSignedOutputUrl(s_Config.OutputZipAssemblyFile), s_Config.OutputZipAssemblyFile);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception: {e.ToString()}");
            }
            finally
            {
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }