public async Task <List <string> > GetAvailableEngines()
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            // define Engines API
            Page <string> engines = await _designAutomation.GetEnginesAsync();

            engines.Data.Sort();

            return(engines.Data); // return list of engines
        }
        public async Task <IActionResult> OnCallbackUpdategp([FromBody] dynamic body)
        {
            try
            {
                dynamic oauth = await OAuthController.GetInternalAsync();

                JObject bodyJson     = JObject.Parse((string)body.ToString());
                var     parentFolder = (string)body.payload.parentFolderUrn;
                var     status       = (string)body.payload.state;
                var     user         = (string)body.payload.context.lineage.createUserName;
                var     project      = (string)body.hook.hookAttribute.projectName;
                var     projectId    = (string)body.hook.hookAttribute.projectId;
                var     fileName     = (string)body.payload.name;
                var     hub          = (string)body.hook.hookAttribute.hubId;
                var     version      = (int)body.payload.version;
                var     rvt          = (string)body.payload.name;
                var     urn          = (string)body.payload.lineageUrn;
                urn = urn.Split(":").Last();
                var folderApi = new FoldersApi();
                folderApi.Configuration.AccessToken = oauth.access_token;
                var content = await folderApi.GetFolderContentsAsync(projectId, parentFolder);

                var included  = new DynamicDictionaryItems(content.included);
                var _included = included.FirstOrDefault(x => (new KeyValuePair <string, dynamic>(x.Key, x.Value).Value.id as string).Contains(urn));
                var guid      = ((string)((dynamic)_included.Value).relationships.storage.data.id).Split("/").Last();

                //var texto = bodyJson.ToString();
                var gp = await PostGoodPractices(project, version, hub, rvt, guid);

                // TODO: Enviar email si la respuesta es correcta.
                await SendEmail(user, fileName, project, version);
            }
            catch { }

            return(Ok());
        }
        private async Task <IActionResult> PostGoodPractices(string projectId, int version, string hubId, string rvt, string guid)
        {
            // basic input validation
            string activityName = "cyBnhhxpfsbhGC1jv4CdyDSLwj912JA4.UpdateRVTParamActivity+dev";
            //var projectId = (string)rvt.projectId;
            //var version = (int)rvt.version;

            // OAuth token
            dynamic oauth = await OAuthController.GetInternalAsync();

            // upload file to OSS Bucket
            // 1. ensure bucket existis
            string     bucketKey = NickName.ToLower() + "-designautomation";
            BucketsApi buckets   = new BucketsApi();

            buckets.Configuration.AccessToken = oauth.access_token;
            try
            {
                PostBucketsPayload bucketPayload = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient);
                await buckets.CreateBucketAsync(bucketPayload, "US");
            }
            catch { };

            // prepare workitem arguments
            // 1. input file
            //var guid = (string)rvt.guid;
            var rvtName = rvt;//(string)rvt.rvtName;
            XrefTreeArgument inputFileArgument = new XrefTreeArgument()
            {
                Url       = $"https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/{guid}",
                LocalName = "myzip",
                PathInZip = rvtName,
                Headers   = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };

            // 2. input json
            dynamic inputJson = new JObject();

            inputJson.HubId     = hubId;
            inputJson.ProjectId = projectId;
            inputJson.Version   = version;
            var inputJsonArgument = new XrefTreeArgument()
            {
                Url = "data:application/json, " + ((JObject)inputJson).ToString(Formatting.None).Replace("\"", "'")
            };

            // 3. output file
            string           outputFileNameOSS  = string.Format("{0}_output_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), Path.GetFileName("OutputFile.json")); // avoid overriding
            XrefTreeArgument outputFileArgument = new XrefTreeArgument()
            {
                Url     = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, outputFileNameOSS),
                Verb    = Verb.Put,
                Headers = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };

            // prepare & submit workitem
            // the callback contains the connectionId (used to identify the client) and the outputFileName of this workitem
            string   callbackUrl  = string.Format("{0}/api/forge/callback/mongo?id={1}&outputFileName={2}", Credentials.GetAppSetting("FORGE_WEBHOOK_URL"), "", outputFileNameOSS);
            WorkItem workItemSpec = new WorkItem()
            {
                ActivityId = activityName,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "inputFile", inputFileArgument },
                    { "inputJson", inputJsonArgument },
                    { "outputFile", outputFileArgument },
                    { "onComplete", new XrefTreeArgument {
                          Verb = Verb.Post, Url = callbackUrl
                      } }
                }
            };

            WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemAsync(workItemSpec);

            return(Ok(new { WorkItemId = workItemStatus.Id }));
        }