private static dynamic GetManifest(string urn) { try { Console.WriteLine("**** Getting Manifest of: " + urn); dynamic response = DerivativesAPI.GetManifest(urn); return(response); } catch (Exception) { Console.WriteLine("**** Failed getting Manifest of: " + urn); return(null); } }
/** * Example of how to query the status of a translate job. * Uses the oauth2TwoLegged and twoLeggedCredentials objects that you retrieved previously. * @param base64Urn - the urn of the file to translate in base 64 format */ private static dynamic verifyJobComplete(string base64Urn) { Console.WriteLine("***** Sending getManifest request"); while (true) { dynamic response = derivativesApi.GetManifest(base64Urn); if (hasOwnProperty(response, "progress") && response.progress == "complete") { Console.WriteLine("***** Finished translating your file to SVF - status: " + response.status + ", progress: " + response.progress); return(response); } else { Console.WriteLine("***** Haven't finished translating your file to SVF - status: " + response.status + ", progress: " + response.progress); Thread.Sleep(1000); } } return(null); }
public ActionResult Upload(HttpPostedFileBase file) { if (file == null || file.ContentLength == 0) { return(RedirectToAction("Index")); } string fileName = Path.GetFileName(file.FileName); string fileSavePath = Path.Combine(Server.MapPath("~/App_Data/"), fileName); file.SaveAs(fileSavePath); // get a write enabled token TwoLeggedApi oauthApi = new TwoLeggedApi(); dynamic bearer = oauthApi.Authenticate( WebConfigurationManager.AppSettings["FORGE_CLIENT_ID"], WebConfigurationManager.AppSettings["FORGE_CLIENT_SECRET"], "client_credentials", new Scope[] { Scope.BucketCreate, Scope.DataCreate, Scope.DataWrite, Scope.DataRead }); // create a randomg bucket name (fixed prefix + randomg guid) string bucketKey = "forgeapp" + Guid.NewGuid().ToString("N").ToLower(); // create the Forge bucket PostBucketsPayload postBucket = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient /* erase after 24h*/); BucketsApi bucketsApi = new BucketsApi(); bucketsApi.Configuration.AccessToken = bearer.access_token; dynamic newBucket = bucketsApi.CreateBucket(postBucket); // upload file (a.k.a. Objects) ObjectsApi objectsApi = new ObjectsApi(); oauthApi.Configuration.AccessToken = bearer.access_token; dynamic newObject; using (StreamReader fileStream = new StreamReader(fileSavePath)) { newObject = objectsApi.UploadObject(bucketKey, fileName, (int)fileStream.BaseStream.Length, fileStream.BaseStream, "application/octet-stream"); } // translate file string objectIdBase64 = ToBase64(newObject.objectId); List <JobPayloadItem> postTranslationOutput = new List <JobPayloadItem>() { new JobPayloadItem( JobPayloadItem.TypeEnum.Svf /* Viewer*/, new List <JobPayloadItem.ViewsEnum>() { JobPayloadItem.ViewsEnum._3d, JobPayloadItem.ViewsEnum._2d }) }; JobPayload postTranslation = new JobPayload( new JobPayloadInput(objectIdBase64), new JobPayloadOutput(postTranslationOutput)); DerivativesApi derivativeApi = new DerivativesApi(); derivativeApi.Configuration.AccessToken = bearer.access_token; dynamic translation = derivativeApi.Translate(postTranslation); // check if is ready int progress = 0; do { System.Threading.Thread.Sleep(1000); // wait 1 second try { dynamic manifest = derivativeApi.GetManifest(objectIdBase64); progress = (string.IsNullOrWhiteSpace(Regex.Match(manifest.progress, @"\d+").Value) ? 100 : Int32.Parse(Regex.Match(manifest.progress, @"\d+").Value)); } catch (Exception ex) { } } while (progress < 100); // clean up System.IO.File.Delete(fileSavePath); //Directory.Delete(fileSavePath, true); return(RedirectToAction("DisplayModel", "Home", new { characterName = objectIdBase64 })); }