public async Task <dynamic> DownloadObject([FromBody] DownloadFile input) { // get the bucket dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; // collect information about file string bucketKey = input.bucketKey; string fileToDownload = input.fileToDownload; PostBucketsSigned postBucketsSigned = new PostBucketsSigned(20); try { dynamic result = await objects.CreateSignedResourceAsync(bucketKey, fileToDownload, postBucketsSigned); return(result); } catch (Exception ex) { } return(null); }
public async Task <dynamic> TranslateZipObject([FromBody] TranslateZipObjectModel zipObjModel) { 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(zipObjModel.objectName, true, "Main element.iam"), new JobPayloadOutput(outputs)); DerivativesApi derivative = new DerivativesApi(); derivative.Configuration.AccessToken = oauth.access_token; dynamic jobPosted = await derivative.TranslateAsync(job); return(jobPosted); }
public async Task <dynamic> UploadObject([FromForm] UploadFile input) { // save the file on the server var fileSavePath = Path.Combine(_env.WebRootPath, Path.GetFileName(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, Path.GetFileName(input.fileToUpload.FileName), (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); } // cleanup System.IO.File.Delete(fileSavePath); return(uploadedObj); }
public async Task <dynamic> CreateNewBucket([FromBody] BucketModel bucket) { dynamic bucketOutput = null;; 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); // obavezna je provera da li kanta već postoji!!! try { bucketOutput = await buckets.CreateBucketAsync(bucketPayload, "US"); } catch (Exception ex) { if (ex.Message == "Error calling CreateBucket: {\"reason\":\"Bucket already exists\"}") { dynamic allBuckets = await buckets.GetBucketsAsync("US", 100); foreach (KeyValuePair <string, dynamic> actualBucket in new DynamicDictionaryItems(allBuckets.items)) { string bucketName = actualBucket.Value.bucketKey; if (bucketName.Contains(BucketName)) //kitchenconfig designautomation { bucketOutput = actualBucket; } } } } return(bucketOutput); }
public async Task DeleteBucket([FromBody] BucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; await buckets.DeleteBucketAsync(bucket.bucketKey); }
public async Task <dynamic> DeleteObject([FromBody] DeleteObjectModel objInfo) { ObjectsApi objs = new ObjectsApi(); dynamic token = await OAuthController.GetInternalAsync(); objs.Configuration.AccessToken = token.access_token; await objs.DeleteObjectAsync(objInfo.bucketKey, objInfo.objectKey); return(Task.CompletedTask); }
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 <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); foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { string actualBucket = bucket.Value.bucketKey; if (actualBucket.Contains(BucketName)) //kitchenconfig designautomation { 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)) { string fileName = objInfo.Value.objectKey; fileName.ToLower(); if (fileName.Contains("zip") && fileName.Contains("output")) //result output { nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId), objInfo.Value.objectKey, "zipfile", false)); } /* ovaj deo mi ne treba ovde jer neću da prikazujem ništa što nije rezult*.zip * else * { * nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId), * objInfo.Value.objectKey, "object", false)); * }*/ } } return(nodes); }
public async Task <IActionResult> StartWorkitem([FromForm] StartWorkitemInput input) { // basic input validation JObject workItemData = JObject.Parse(input.data); string uniqueActivityName = string.Format("{0}.{1}+{2}", NickName, ActivityName, Alias); string browerConnectionId = workItemData["browerConnectionId"].Value <string>(); // save the file on the server var fileSavePath = Path.Combine(LocalDataSetFolder, "Kitchen.zip"); //using (var stream = new FileStream(fileSavePath, FileMode.Create)) await input.inputFile.CopyToAsync(stream); // OAuth token dynamic oauth = await OAuthController.GetInternalAsync(); string inputFileNameOSS = string.Format("{0}_input_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), "Kitchen.zip"); // avoid overriding ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; using (StreamReader streamReader = new StreamReader(fileSavePath)) await objects.UploadObjectAsync(bucketKey, inputFileNameOSS, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); //System.IO.File.Delete(fileSavePath);// delete server copy // prepare workitem arguments // 1. input file XrefTreeArgument inputFileArgument = new XrefTreeArgument() { Verb = Verb.Get, LocalName = "Kitchen", PathInZip = "CleanSlate.iam", Url = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, inputFileNameOSS), Headers = new Dictionary <string, string>() { { "Authorization", "Bearer " + oauth.access_token } } }; // 2b. input json from viewer string inputJsonStr = workItemData.ToString(Newtonsoft.Json.Formatting.None).Replace("\"", "'"); XrefTreeArgument inputJsonArgument = new XrefTreeArgument() { Verb = Verb.Get, Url = "data:application/json, " + inputJsonStr }; // 3. output file string outputFileNameOSS = string.Format("{0}_output_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), "Kitchen.zip"); // 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/designautomation?id={1}&outputFileName={2}", /* OAuthController.GetAppSetting("FORGE_WEBHOOK_URL"),*/ "https://webkitchenbuilder.herokuapp.com", browerConnectionId, outputFileNameOSS ); WorkItem workItemSpec = new WorkItem() { ActivityId = uniqueActivityName, Arguments = new Dictionary <string, IArgument>() { { "inputFile", inputFileArgument }, { "inputJson", inputJsonArgument }, { "outputFile", outputFileArgument }, { "onComplete", new XrefTreeArgument { Verb = Verb.Post, Url = callbackUrl } } } }; try { WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemAsync(workItemSpec); return(Ok(new { workItemId = workItemStatus.Id })); } catch (Exception ex) { return(Ok(new { workItemId = ex.Message })); } }