Exemple #1
0
        public async Task <WorkItemStatus> RunWorkItemAsync(Dictionary <string, IArgument> workItemArgs, ForgeAppBase config)
        {
            // create work item
            var wi = new WorkItem
            {
                ActivityId = await GetFullActivityId(config),
                Arguments  = workItemArgs
            };

            // run WI and wait for completion
            System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
            WorkItemStatus status           = await _client.CreateWorkItemAsync(wi);

            Trace($"Created WI {status.Id}");
            while (status.Status == Status.Pending || status.Status == Status.Inprogress)
            {
                await Task.Delay(2000);

                status = await _client.GetWorkitemStatusAsync(status.Id);
            }

            Trace($"WI {status.Id} completed with {status.Status} in {sw.ElapsedMilliseconds} ms");
            Trace($"{status.ReportUrl}");

            await _postProcessing.HandleStatus(status);

            return(status);
        }
Exemple #2
0
        /// <summary>
        /// The SubmitWorkItemAsync.
        /// </summary>
        /// <param name="myActivity">The myActivity<see cref="string"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        private async Task SubmitWorkItemAsync(string myActivity)
        {
            Console.WriteLine("Submitting up workitem...");

            var workItemStatus = await api.CreateWorkItemAsync(
                new Autodesk.Forge.DesignAutomation.Model.WorkItem()
            {
                ActivityId = myActivity,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    {
                        "inputFile",
                        new XrefTreeArgument()
                        {
                            Url = "http://download.autodesk.com/us/support/files/autocad_2015_templates/acad.dwt"
                        }
                    }, {
                        "inputZip",
                        new XrefTreeArgument()
                        {
                            Url = DownloadUrl, Verb = Verb.Get, LocalName = "export"
                        }
                    }, {
                        "Result",
                        new XrefTreeArgument()
                        {
                            Verb = Verb.Put, Url = UploadUrl
                        }
                    }
                }
            });

            Console.Write("\tPolling status");
            while (!workItemStatus.Status.IsDone())
            {
                await Task.Delay(TimeSpan.FromSeconds(2));

                workItemStatus = await api.GetWorkitemStatusAsync(workItemStatus.Id);

                Console.Write(".");
            }
            Console.WriteLine($"{workItemStatus.Status}.");
            var fname = await DownloadToDocsAsync(workItemStatus.ReportUrl, "Das-report.txt");

            if (workItemStatus.Status != Status.Success)
            {
                Console.WriteLine($"{workItemStatus.Status} Please refer log {fname} further details.. exiting! ");
                return;
            }
            Console.WriteLine($"Downloaded {fname}.");
            var result = await DownloadToDocsAsync(UploadUrl, outputFileNameOSS, true);

            Console.WriteLine($"Downloaded {result}.");
        }
        /// <summary>
        /// The SubmitWorkItemAsync.
        /// </summary>
        /// <param name="myActivity">The myActivity<see cref="string"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        private async Task SubmitWorkItemAsync(string myActivity)
        {
            Console.WriteLine("Submitting up WorkItem...");
            dynamic oauth = await GetInternalAsync();

            string outputFileOssName = string.Format("{0}_input_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), "result.pdf");;
            var    workItemStatus    = await api.CreateWorkItemAsync(new Autodesk.Forge.DesignAutomation.Model.WorkItem()
            {
                ActivityId = myActivity,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "HostDwg", new XrefTreeArgument()
                      {
                          Verb = Verb.Get, Url = downloadUrl
                      } },
                    { "Result", new XrefTreeArgument()
                      {
                          Verb    = Verb.Put,
                          Url     = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", Owner.ToLower(), outputFileOssName),
                          Headers = new Dictionary <string, string>()
                          {
                              { "Authorization", "Bearer " + oauth.access_token }
                          }
                      } }
                }
            });

            Console.Write("\tPolling status");
            while (!workItemStatus.Status.IsDone())
            {
                await Task.Delay(TimeSpan.FromSeconds(2));

                workItemStatus = await api.GetWorkitemStatusAsync(workItemStatus.Id);

                Console.Write(".");
            }
            Console.WriteLine($"{workItemStatus.Status}.");
            var fname = await DownloadToDocsAsync(workItemStatus.ReportUrl, "Das-report.txt");

            Console.WriteLine($"Downloaded {fname}.");
            UploadUrl = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", Owner.ToLower(), outputFileOssName);
            var result = await DownloadToDocsAsync(UploadUrl, outputFileOssName, true);

            Console.WriteLine($"Downloaded {result}.");
        }
Exemple #4
0
        private async Task SubmitWorkItemAsync(string myActivity)
        {
            Console.WriteLine("Submitting up workitem...");
            var workItemStatus = await api.CreateWorkItemAsync(new Autodesk.Forge.DesignAutomation.Model.WorkItem()
            {
                ActivityId = myActivity,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "input", new XrefTreeArgument()
                      {
                          Url = "http://download.autodesk.com/us/support/files/autocad_2015_templates/acad.dwt"
                      } },
                    { "params", new XrefTreeArgument()
                      {
                          Url = $"data:application/json, {JsonConvert.SerializeObject(new Parameters{Width = 12, Height = 12, Pieces = 100, XRes = 300, YRes = 300 })}"
                      } },
                    { "pixels", new XrefTreeArgument()
                      {
                          Url = "http://through-the-interface.typepad.com/test/jigtest.json"
                      } },
                    //TODO: replace it with your own URL
                    { "result", new XrefTreeArgument()
                      {
                          Verb = Verb.Put, Url = UploadUrl
                      } }
                }
            });

            Console.Write("\tPolling status");
            while (!workItemStatus.Status.IsDone())
            {
                await Task.Delay(TimeSpan.FromSeconds(2));

                workItemStatus = await api.GetWorkitemStatusAsync(workItemStatus.Id);

                Console.Write(".");
            }
            Console.WriteLine($"{workItemStatus.Status}.");
            var fname = await DownloadToDocsAsync(workItemStatus.ReportUrl, "Das-report.txt");

            Console.WriteLine($"Downloaded {fname}.");
            var outputZip = await DownloadToDocsAsync(UploadUrl, "output.zip");

            Console.WriteLine($"Downloaded {outputZip}.");
        }
Exemple #5
0
        private async Task SubmitWorkItemAsync(string myActivity)
        {
            Console.WriteLine("Submitting up workitem...");
            var workItemStatus = await api.CreateWorkItemAsync(new WorkItem()
            {
                ActivityId = myActivity,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "input", new XrefTreeArgument()
                      {
                          Url = "http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg"
                      } },
                    { "params", new XrefTreeArgument()
                      {
                          Url = $"data:application/json, {JsonConvert.SerializeObject(new CrxApp.Parameters { ExtractBlockNames = true, ExtractLayerNames = true })}"
                      } },
                    //TODO: replace it with your own URL
                    { "result", new XrefTreeArgument()
                      {
                          Verb = Verb.Put, Url = UploadUrl
                      } }
                }
            });

            Console.Write("\tPolling status");
            while (!workItemStatus.Status.IsDone())
            {
                await Task.Delay(TimeSpan.FromSeconds(2));

                workItemStatus = await api.GetWorkitemStatusAsync(workItemStatus.Id);

                Console.Write(".");
            }
            Console.WriteLine($"{workItemStatus.Status}.");
            var fname = await DownloadToDocsAsync(workItemStatus.ReportUrl, "Das-report.txt");

            Console.WriteLine($"Downloaded {fname}.");
        }
        /// <summary>
        /// The SubmitWorkItemAsync.
        /// </summary>
        /// <param name="myActivity">The myActivity<see cref="string"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        private async Task SubmitWorkItemAsync(string myActivity)
        {
            Console.WriteLine("Submitting up workitem...");
            dynamic inputJson = new JObject();

            inputJson.Width  = "40.0";
            inputJson.Height = "80.0";
            var workItemStatus = await api.CreateWorkItemAsync(new Autodesk.Forge.DesignAutomation.Model.WorkItem()
            {
                ActivityId = myActivity,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    {
                        "inputFile",
                        new XrefTreeArgument()
                        {
                            Url  = DownloadUrl,
                            Verb = Verb.Get
                        }
                    },
                    {
                        "inputJson",
                        new XrefTreeArgument()
                        {
                            Url = "data:application/json, " + ((JObject)inputJson).ToString(Formatting.None).Replace("\"", "'")
                        }
                    },
                    {
                        "outputFile",
                        new XrefTreeArgument()
                        {
                            Verb    = Verb.Put,
                            Url     = UploadUrl,
                            Headers = new Dictionary <string, string>()
                            {
                                { "Content-Type", "application/octet-stream" },
                                { "x-ms-blob-type", "BlockBlob" }
                            }
                        }
                    }
                }
            });

            Console.Write("\tPolling status");
            while (!workItemStatus.Status.IsDone())
            {
                await Task.Delay(TimeSpan.FromSeconds(2));

                workItemStatus = await api.GetWorkitemStatusAsync(workItemStatus.Id);

                Console.Write(".");
            }
            Console.WriteLine($"{workItemStatus.Status}.");
            var fname = await DownloadToDocsAsync(workItemStatus.ReportUrl, "Das-report.txt");

            if (workItemStatus.Status != Status.Success)
            {
                Console.WriteLine($"{workItemStatus.Status} Please refer log {fname} further details.. exiting! ");
                return;
            }
            Console.WriteLine($"Downloaded {fname}.");
            var urlString = await GetAzureUrlAsync(UrlType.downLoadUrl, outputFileNameOSS);

            var result = await DownloadToDocsAsync(urlString, outputFileNameOSS);

            Console.WriteLine($"Downloaded {result}.");
        }