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 <IList <TreeNode> > GetOSSAsync([FromUri] 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)) { 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); }
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 <dynamic> DeleteBucket([FromBody] CreateBucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; await buckets.DeleteBucketAsync(bucket.bucketKey); //or //buckets.DeleteBucket(bucket.bucketKey); return(Task.CompletedTask); }
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); }