public async Task <IActionResult> StartTranslation([FromBody] JObject translateSpecs) { string urn = translateSpecs["urn"].Value <string>(); dynamic oauth = await OAuthController.GetInternalAsync(); List <JobPayloadItem> outputs = new List <JobPayloadItem>() { new JobPayloadItem( JobPayloadItem.TypeEnum.Svf, new List <JobPayloadItem.ViewsEnum>() { JobPayloadItem.ViewsEnum._2d, JobPayloadItem.ViewsEnum._3d }) }; JobPayload job; job = new JobPayload(new JobPayloadInput(urn), new JobPayloadOutput(outputs)); // translationを開始する DerivativesApi derivative = new DerivativesApi(); derivative.Configuration.AccessToken = oauth.access_token; dynamic jobPosted = await derivative.TranslateAsync(job); return(Ok()); }
public async Task <IList <TreeNode> > GetOSSAsync(string id) { IList <TreeNode> nodes = new List <TreeNode>(); dynamic oauth = await OAuthController.GetInternalAsync(); if (id == "#") // root { // in this case, let's return all buckets BucketsApi appBckets = new BucketsApi(); appBckets.Configuration.AccessToken = oauth.access_token; // to simplify, let's return only the first 100 buckets dynamic buckets = await appBckets.GetBucketsAsync("US", 100); string clientId = await GetClientIdAsync(); foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { nodes.Add(new TreeNode(bucket.Value.bucketKey, bucket.Value.bucketKey.Replace(clientId + "-", string.Empty), "bucket", true)); } } else { // as we have the id (bucketKey), let's return all ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; var objectsList = objects.GetObjects(id); foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectsList.items)) { nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId), objInfo.Value.objectKey, "object", false)); } } return(nodes); }
private async Task TranslateFile(string objectId, string rootFileName) { dynamic oauth = await OAuthController.GetInternalAsync(); // prepare the payload List <JobPayloadItem> outputs = new List <JobPayloadItem>() { new JobPayloadItem( JobPayloadItem.TypeEnum.Svf, new List <JobPayloadItem.ViewsEnum>() { JobPayloadItem.ViewsEnum._2d, JobPayloadItem.ViewsEnum._3d } ) }; JobPayload job; string urn = Base64Encode(objectId); if (rootFileName != null) { job = new JobPayload(new JobPayloadInput(urn, true, rootFileName), new JobPayloadOutput(outputs)); } else { job = new JobPayload(new JobPayloadInput(urn), new JobPayloadOutput(outputs)); } // start the translation DerivativesApi derivative = new DerivativesApi(); derivative.Configuration.AccessToken = oauth.access_token; await derivative.TranslateAsync(job); }
public async Task <dynamic> TranslateObject([FromBody] TranslateObjectModel objModel) { dynamic oauth = await OAuthController.GetInternalAsync(); // prepare the payload List <JobPayloadItem> outputs = new List <JobPayloadItem>() { new JobPayloadItem( JobPayloadItem.TypeEnum.Svf, new List <JobPayloadItem.ViewsEnum>() { JobPayloadItem.ViewsEnum._2d, JobPayloadItem.ViewsEnum._3d }) }; JobPayload job; job = new JobPayload(new JobPayloadInput(objModel.objectName), new JobPayloadOutput(outputs)); // start the translation DerivativesApi derivative = new DerivativesApi(); derivative.Configuration.AccessToken = oauth.access_token; dynamic jobPosted = await derivative.TranslateAsync(job); return(jobPosted); }
public async Task <dynamic> TranslateObject([FromBody] ObjectModel objModel) { dynamic oauth = await OAuthController.GetInternalAsync(); // prepare the payload List <JobPayloadItem> outputs = new List <JobPayloadItem>() { new JobPayloadItem( JobPayloadItem.TypeEnum.Svf, new List <JobPayloadItem.ViewsEnum>() { JobPayloadItem.ViewsEnum._2d, JobPayloadItem.ViewsEnum._3d }) }; JobPayload job; if (string.IsNullOrEmpty(objModel.rootFilename)) { job = new JobPayload(new JobPayloadInput(objModel.objectName), new JobPayloadOutput(outputs)); } else { job = new JobPayload(new JobPayloadInput(objModel.objectName, true, objModel.rootFilename), new JobPayloadOutput(outputs)); } // start the translation DerivativesApi derivative = new DerivativesApi(); derivative.Configuration.AccessToken = oauth.access_token; dynamic jobPosted = await derivative.TranslateAsync(job, true /* force re-translate if already here, required data:write*/); return(jobPosted); }
public async Task <dynamic> UploadObject([FromForm] UploadFile input) { // save the file on the server var fileSavePath = Path.Combine(_env.ContentRootPath, input.fileToUpload.FileName); using (var stream = new FileStream(fileSavePath, FileMode.Create)) { await input.fileToUpload.CopyToAsync(stream); } // get the bucket... dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; // upload the file/object, which will create a new object dynamic uploadedObj; using (StreamReader streamReader = new StreamReader(fileSavePath)) { uploadedObj = await objects.UploadObjectAsync(input.bucketKey, input.fileToUpload.FileName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); } // cleanup System.IO.File.Delete(fileSavePath); return(uploadedObj); }
public async Task <IActionResult> StartTranslation([FromBody] JObject input) { string browerConnectionId = input["browerConnectionId"].Value <string>(); bool isSimplified = input["isSimplified"].Value <bool>(); string rootFilename = isSimplified ? "output.ipt" : input["rootFilename"].Value <string>(); // OAuth token dynamic oauth = await OAuthController.GetInternalAsync(); string zipFileName = browerConnectionId + ((isSimplified) ? ".min.zip" : ".zip"); try { await TranslateFile( string.Format("urn:adsk.objects:os.object:{0}/{1}", TransientBucketKey, zipFileName), rootFilename, WorkflowId ); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public async Task <IActionResult> StartWorkitems([FromBody] JObject input) { System.Diagnostics.Debug.WriteLine("StartWorkitem"); string browerConnectionId = input["browerConnectionId"].Value <string>(); bool isDefault = input["isDefault"].Value <bool>(); if (isDefault) { input["options"]["MainAssembly"] = new JObject(new JProperty("value", DefaultFileName.Replace(".zip", ""))); } bool createRfa = input["options"]["CreateRfa"]["value"].Value <bool>(); // OAuth token dynamic oauth = await OAuthController.GetInternalAsync(); string inputBucket = isDefault ? PersistentBucketKey : TransientBucketKey; string inputZip = isDefault ? DefaultFileName : browerConnectionId + ".zip"; string outputZip = browerConnectionId + ".min.zip"; string outputRfa = createRfa ? browerConnectionId + ".rfa" : null; string zipWorkItemId = await CreateWorkItem( input["options"], new Dictionary <string, string>() { { "Authorization", "Bearer " + oauth.access_token } }, browerConnectionId, inputBucket, inputZip, outputZip, outputRfa ); return(Ok(new { ZipWorkItemId = zipWorkItemId })); }
public async Task <ActionResult <IList <string> > > GetFileInBucket() { dynamic oauth = await OAuthController.GetInternalAsync(); // define Engines API string bucketKey = NickName.ToLower() + "_designautomation"; ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; try { dynamic response = await objects.GetObjectsAsyncWithHttpInfo(bucketKey); IDictionary <string, dynamic> dict = response.Data.Dictionary["items"].Dictionary; List <string> list = new List <string>(); foreach (dynamic item in dict) { list.Add(item.Value.Dictionary["objectKey"]); } return(Ok(list)); // return list of objects in bucket } catch { return(BadRequest()); } }
public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs) { // basic input validation string zipFileName = activitySpecs["zipFileName"].Value <string>(); string engineName = activitySpecs["engine"].Value <string>(); // define Activities API dynamic oauth = await OAuthController.GetInternalAsync(); ActivitiesApi activitiesApi = new ActivitiesApi(); activitiesApi.Configuration.AccessToken = oauth.access_token; // standard name for this sample string appBundleName = zipFileName + "AppBundle"; string activityName = zipFileName + "Activity"; // PageString activities = await activitiesApi.ActivitiesGetItemsAsync(); string qualifiedActivityId = string.Format("{0}.{1}+{2}", NickName, activityName, Alias); if (!activities.Data.Contains(qualifiedActivityId)) { // define the activity // ToDo: parametrize for different engines... string commandLine = string.Format(@"$(engine.path)\\{0} /i $(args[inputFile].path) /al $(appbundles[{1}].path)", Executable(engineName), appBundleName); ModelParameter inputFile = new ModelParameter(false, false, ModelParameter.VerbEnum.Get, "input file", true, "$(inputFile)"); ModelParameter inputJson = new ModelParameter(false, false, ModelParameter.VerbEnum.Get, "input json", false, "params.json"); ModelParameter outputFile = new ModelParameter(false, false, ModelParameter.VerbEnum.Put, "output file", true, "outputFile.rvt"); Activity activitySpec = new Activity( new List <string>() { commandLine }, new Dictionary <string, ModelParameter>() { { "inputFile", inputFile }, { "inputJson", inputJson }, { "outputFile", outputFile } }, engineName, new List <string>() { string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias) }, null, string.Format("Description for {0}", activityName), null, activityName); Activity newActivity = await activitiesApi.ActivitiesCreateItemAsync(activitySpec); // specify the alias for this Activity Alias aliasSpec = new Alias(1, null, Alias); Alias newAlias = await activitiesApi.ActivitiesCreateAliasAsync(activityName, aliasSpec); return(Ok(new { Activity = qualifiedActivityId })); } // as this activity points to a AppBundle "dev" alias (which points to the last version of the bundle), // there is no need to update it (for this sample), but this may be extended for different contexts return(Ok(new { Activity = "Activity already defined" })); }
public async void DeleteBucket([FromBody] DeleteBucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; buckets.DeleteBucket(bucket.bucketKey); }
public async Task <dynamic> CreateBucketAsync([FromBody] BucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; PostBucketsPayload bucketPayload = new PostBucketsPayload(bucket.bucketKey, null, bucket.policyKey); return(await buckets.CreateBucketAsync(bucketPayload, "US")); }
public async Task <IActionResult> DeleteBucketAsync([FromBody] BucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; await buckets.DeleteBucketAsync(bucket.bucketKey); return(Ok()); }
public async Task <IActionResult> DeleteObjectAsync([FromBody] ObjectModel objectModel) { dynamic token = await OAuthController.GetInternalAsync(); DerivativesApi derivative = new DerivativesApi(); derivative.Configuration.AccessToken = token.access_token; await derivative.DeleteManifestAsync(objectModel.objectName); return(Ok()); }
public async Task <IActionResult> DeleteObjectAsync([FromBody] ObjectModel objectModel) { ObjectsApi objects = new ObjectsApi(); dynamic token = await OAuthController.GetInternalAsync(); objects.Configuration.AccessToken = token.access_token; string objectName = Base64Decode(objectModel.objectName).Split("/")[1]; await objects.DeleteObjectAsync(objectModel.bucketKey, objectName); return(Ok()); }
public async Task <dynamic> CreateBucket([FromBody] CreateBucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; PostBucketsPayload bucketPayload = new PostBucketsPayload(string.Format("{0}-{1}", ClientId, bucket.bucketKey.ToLower()), null, PostBucketsPayload.PolicyKeyEnum.Transient); return(await buckets.CreateBucketAsync(bucketPayload, "US")); }
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> ClearAccount() { if (OAuthController.GetAppSetting("DISABLE_SETUP") == "true") { return(Unauthorized()); } // clear account await _designAutomation.DeleteForgeAppAsync("me"); return(Ok()); }
public async Task <List <string> > GetAvailableEngines() { dynamic oauth = await OAuthController.GetInternalAsync(); // define Engines API EnginesApi enginesApi = new EnginesApi(); enginesApi.Configuration.AccessToken = oauth.access_token; PageString engines = await enginesApi.EnginesGetItemsAsync(); engines.Data.Sort(); return(engines.Data); // return list of engines }
public async Task <IActionResult> GetOssFiles() { System.Diagnostics.Debug.WriteLine("GetOssFiles"); // OAuth token dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; dynamic res = await objects.GetObjectsAsync(BucketKey); return(Ok(res)); }
public async Task <IActionResult> GetUploadUrl(string id) { var fileName = id + ".zip"; dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; dynamic signedUrl = await objects.CreateSignedResourceAsyncWithHttpInfo(TransientBucketKey, fileName, new PostBucketsSigned(10), "write"); return(Ok(new { SignedUrl = signedUrl })); }
public async Task <IActionResult> GetResults() { dynamic oauth = await OAuthController.GetInternalAsync(); string bucketKey = NickName.ToLower() + "_designautomation"; string outputFileNameOSS = string.Format("{0}_output_{1}", _createTime, "max sample file.max"); // avoid overriding ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; System.IO.FileStream result = objects.GetObject(bucketKey, outputFileNameOSS); if (result == null) { return(NotFound()); } return(Ok(result.Name)); }
/// <summary> /// Define a new activity /// </summary> public static async Task <bool> IsInCache(string fileName) { dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; try { dynamic res = await objects.GetObjectDetailsAsync(BucketKey, fileName); return(true); } catch {} return(false); }
public async Task <IActionResult> ClearAccount() { if (!_env.IsDevelopment()) { return(BadRequest()); // disable when published :-) } dynamic oauth = await OAuthController.GetInternalAsync(); // define the account api (ForgeApps) Autodesk.Forge.DesignAutomation.v3.ForgeAppsApi forgeAppApi = new ForgeAppsApi(); forgeAppApi.Configuration.AccessToken = oauth.access_token; // clear account await forgeAppApi.ForgeAppsDeleteUserAsync("me"); return(Ok()); }
public async Task <IActionResult> UploadOssFiles([FromBody] JObject appBundleSpecs) { if (OAuthController.GetAppSetting("DISABLE_SETUP") == "true") { return(Unauthorized()); } System.Diagnostics.Debug.WriteLine("UploadOssFiles"); // OAuth token dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; DerivativesApi derivatives = new DerivativesApi(); derivatives.Configuration.AccessToken = oauth.access_token; // upload file to OSS Bucket // 1. ensure bucket existis 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 { }; // in case bucket already exists string [] filePaths = System.IO.Directory.GetFiles(LocalFilesFolder); foreach (string filePath in filePaths) { string fileName = System.IO.Path.GetFileName(filePath); using (StreamReader streamReader = new StreamReader(filePath)) { dynamic res = await objects.UploadObjectAsync(BucketKey, fileName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); TranslateFile(res.objectId, null); } } return(Ok()); }
public async Task <dynamic> UploadObject() { // basic input validation HttpRequest req = HttpContext.Current.Request; if (string.IsNullOrWhiteSpace(req.Params["bucketKey"])) { throw new System.Exception("BucketKey parameter was not provided."); } if (req.Files.Count != 1) { throw new System.Exception("Missing file to upload"); // for now, let's support just 1 file at a time } string bucketKey = req.Params["bucketKey"]; HttpPostedFile file = req.Files[0]; // save the file on the server var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), file.FileName); file.SaveAs(fileSavePath); // get the bucket... dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; // upload the file/object, which will create a new object dynamic uploadedObj; using (StreamReader streamReader = new StreamReader(fileSavePath)) { uploadedObj = await objects.UploadObjectAsync(bucketKey, file.FileName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); } // cleanup File.Delete(fileSavePath); return(uploadedObj); }
public async Task <IActionResult> OnComplete(string id, string outputFile, [FromBody] dynamic body) { System.Diagnostics.Debug.WriteLine($"OnComplete, id = {id}, outputFile = {outputFile}"); try { // your webhook should return immediately! we can use Hangfire to schedule a job JObject bodyJson = JObject.Parse((string)body.ToString()); await _hubContext.Clients.Client(id).SendAsync("onComplete", bodyJson.ToString()); var client = new RestClient(bodyJson["reportUrl"].Value <string>()); var request = new RestRequest(string.Empty); byte[] bs = client.DownloadData(request); string report = System.Text.Encoding.Default.GetString(bs); await _hubContext.Clients.Client(id).SendAsync("onComplete", report); if (outputFile.EndsWith(".png")) { dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; dynamic signedUrl = await objects.CreateSignedResourceAsyncWithHttpInfo(BucketKey, outputFile, new PostBucketsSigned(10), "read"); await _hubContext.Clients.Client(id).SendAsync("onPicture", (string)(signedUrl.Data.signedUrl)); } if (outputFile.EndsWith(".zip")) { string objectId = "urn:adsk.objects:os.object:" + BucketKey + "/" + outputFile; TranslateFile(objectId, "shelves.iam"); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("OnComplete, e.Message = " + e.Message); } // ALWAYS return ok (200) return(Ok()); }
public async Task <List <string> > GetAvailableEngines() { dynamic oauth = await OAuthController.GetInternalAsync(); List <string> allEngines = new List <string>(); // define Engines API string paginationToken = null; while (true) { Page <string> engines = await _designAutomation.GetEnginesAsync(paginationToken); allEngines.AddRange(engines.Data); if (engines.PaginationToken == null) { break; } paginationToken = engines.PaginationToken; } allEngines.Sort(); return(allEngines); // return list of engines }
public async Task <IActionResult> OnComplete(string id, string outputFile, string outputRfaFile, [FromBody] dynamic body) { System.Diagnostics.Debug.WriteLine($"OnComplete, id = {id}, outputFile = {outputFile}, outputRfaFile = {outputRfaFile}"); try { JObject bodyJson = JObject.Parse((string)body.ToString()); // your webhook should return immediately! we can use Hangfire to schedule a job var client = new RestClient(bodyJson["reportUrl"].Value <string>()); var request = new RestRequest(string.Empty); byte[] bs = client.DownloadData(request); string report = System.Text.Encoding.Default.GetString(bs); await _hubContext.Clients.Client(id).SendAsync("onReport", report); await _hubContext.Clients.Client(id).SendAsync("onComplete", bodyJson.ToString()); // If we got a reasonable file name if (outputRfaFile != null) { dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; dynamic signedUrl = await objects.CreateSignedResourceAsyncWithHttpInfo(TransientBucketKey, outputRfaFile, new PostBucketsSigned(30), "read"); string url = signedUrl.Data.signedUrl; await _hubContext.Clients.Client(id).SendAsync("onUrl", "{ \"url\": \"" + url + "\", \"text\": \"Download output.rfa\" }"); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("OnComplete, e.Message = " + e.Message); } // ALWAYS return ok (200) return(Ok()); }
private async Task <string> CreateWorkItem(JObject input, Dictionary <string, string> headers, string browerConnectionId, string outputName, string fileName, string url) { input["output"] = outputName; XrefTreeArgument inputJsonArgument = new XrefTreeArgument() { Url = "data:application/json," + input.ToString(Formatting.None) }; XrefTreeArgument outputArgument = new XrefTreeArgument() { Url = url, Verb = Verb.Put, Headers = headers }; string callbackComplete = string.Format( "{0}/api/forge/callback/oncomplete?id={1}&outputFile={2}", OAuthController.GetAppSetting("FORGE_WEBHOOK_URL"), browerConnectionId, fileName); WorkItem workItemSpec = new WorkItem() { ActivityId = QualifiedBundleActivityName, Arguments = new Dictionary <string, IArgument>() { { "inputJson", inputJsonArgument }, { outputName, outputArgument }, { "onComplete", new XrefTreeArgument { Verb = Verb.Post, Url = callbackComplete } } } }; WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemAsync(workItemSpec); return(workItemStatus.Id); }