private async static Task <bool> Translate2Svf2(string urn, JobPayloadDestination.RegionEnum targetRegion = JobPayloadDestination.RegionEnum.US) { try { Console.WriteLine("**** Requesting SVF2 translation for: " + urn); JobPayloadInput jobInput = new JobPayloadInput(urn); JobPayloadOutput jobOutput = new JobPayloadOutput( new List <JobPayloadItem> ( new JobPayloadItem [] { new JobPayloadItem( JobPayloadItem.TypeEnum.Svf2, new List <JobPayloadItem.ViewsEnum> ( new JobPayloadItem.ViewsEnum [] { JobPayloadItem.ViewsEnum._2d, JobPayloadItem.ViewsEnum._3d } ), null ) } ), new JobPayloadDestination(targetRegion) ); JobPayload job = new JobPayload(jobInput, jobOutput); bool bForce = true; ApiResponse <dynamic> response = await DerivativesAPI.TranslateAsyncWithHttpInfo(job, bForce); httpErrorHandler(response, "Failed to register file for SVF2 translation"); return(true); } catch (Exception) { Console.WriteLine("**** Failed to register file for SVF2 translation"); return(false); } }
// app cleanup US US // app US US US static async Task Main(string [] args) { Console.WriteLine("Hello World!"); //region = Region.US; // Done while initializing //DerivativesAPI = USDerivativesAPI; readConfigFromEnvOrSettings(); string urn = BuildURN(BucketKey, ObjectKey); if (args [0] == "cleanup") { try { Region endpoint = Enum.Parse <Region> (args [1], true); Region storage = Enum.Parse <Region> (args [2], true); await CleanUP( urn, endpoint == Region.US?USDerivativesAPI : EMEADerivativesAPI, storage ); } catch (Exception) {} } else { try { Region endpoint = Enum.Parse <Region> (args [0], true); Region storage = Enum.Parse <Region> (args [1], true); JobPayloadDestination.RegionEnum target = Enum.Parse <JobPayloadDestination.RegionEnum> (args [2], true); urn = await TryWorkflow( endpoint == Region.US?USDerivativesAPI : EMEADerivativesAPI, storage, target ); } catch (Exception) {} } Console.WriteLine("Done"); }
static async Task <string> TryWorkflow(DerivativesApi endpoint, Region storage = Region.US, JobPayloadDestination.RegionEnum derivativeRegion = JobPayloadDestination.RegionEnum.US) { Console.WriteLine("Running Endpoint: " + (endpoint.RegionIsEMEA ? "EMEA" : "US") + " server - Storage: " + storage.ToString() + " - Derivative Region: " + derivativeRegion.ToString()); region = storage; DerivativesAPI = endpoint; dynamic response = await oauthExecAsync(); if (response == null) { return(null); } response = CreateBucketIfNotExist(); if (!response) { return(null); } //DeleteSampleFile(); response = UploadSampleFile(); if (response == null) { return(null); } string urn = SafeBase64Encode(response); //DeleteManifest (urn); response = GetManifest(urn); if (response != null) { Console.WriteLine(response.ToString()); } string found = FindDerivativesNodeStatus("svf2", response); if (found == null) { response = await Translate2Svf2(urn, derivativeRegion); if (!response) { return(null); } Console.WriteLine("Please wait for SVF2 translation to complete"); return(null); } else if (found != "complete") { Console.WriteLine("Translation Failed or Still translating..."); return(null); } found = FindDerivativesNodeStatus("obj", response); string guid = null; if (found == null) { response = GetMetadata(urn); if (response == null) { return(urn); } guid = response.data.metadata [0].guid; response = await Translate2Obj(urn, guid, JobObjOutputPayloadAdvanced.UnitEnum.Meter, derivativeRegion); if (!response) { return(urn); } Console.WriteLine("Please wait for OBJ translation to complete"); return(urn); } else if (found != "complete") { Console.WriteLine("Translation Failed or Still translating..."); return(urn); } dynamic node = FindDerivativesNode("obj", response); response = GetMetadata(urn); if (response == null) { return(urn); } guid = response.data.metadata [0].guid; for (int i = 0; i < node.children.Count; i++) { dynamic elt = node.children [i]; if (elt.type != "resource" || elt.status != "success" || elt.modelGuid != guid || elt.role != "obj") { continue; } Console.WriteLine(elt.urn); IDictionary <string, string> headers = GetDerivativesManifestHeaders(urn, elt.urn); Console.WriteLine("\t size: " + headers ["Content-Length"]); System.IO.MemoryStream stream = GetDerivativesManifest(urn, elt.urn); if (stream == null) { continue; } stream.Seek(0, SeekOrigin.Begin); string name = elt.urn.Substring(elt.urn.LastIndexOf('/') + 1); File.WriteAllBytes(name, stream.ToArray()); } Console.WriteLine("Done"); return(urn); }
private async static Task <bool> Translate2Stl(string urn, string guid, JobObjOutputPayloadAdvanced.UnitEnum unit = JobObjOutputPayloadAdvanced.UnitEnum.Meter, JobPayloadDestination.RegionEnum targetRegion = JobPayloadDestination.RegionEnum.US) { try { Console.WriteLine("**** Requesting STL translation for: " + urn); JobPayloadInput jobInput = new JobPayloadInput(urn); JobPayloadOutput jobOutput = new JobPayloadOutput( new List <JobPayloadItem> ( new JobPayloadItem [] { new JobPayloadItem( JobPayloadItem.TypeEnum.Stl, null, new JobStlOutputPayloadAdvanced(JobStlOutputPayloadAdvanced.FormatEnum.Ascii, true, JobStlOutputPayloadAdvanced.ExportFileStructureEnum.Single) ) } ), new JobPayloadDestination(targetRegion) ); JobPayload job = new JobPayload(jobInput, jobOutput); bool bForce = true; ApiResponse <dynamic> response = await DerivativesAPI.TranslateAsyncWithHttpInfo(job, bForce); httpErrorHandler(response, "Failed to register file for STL translation"); return(true); } catch (Exception) { Console.WriteLine("**** Failed to register file for STL translation"); return(false); } }
private async static Task <bool> Translate2Obj(string urn, string guid, JobObjOutputPayloadAdvanced.UnitEnum unit = JobObjOutputPayloadAdvanced.UnitEnum.Meter, JobPayloadDestination.RegionEnum targetRegion = JobPayloadDestination.RegionEnum.US) { try { Console.WriteLine("**** Requesting OBJ translation for: " + urn); JobPayloadInput jobInput = new JobPayloadInput(urn); JobPayloadOutput jobOutput = new JobPayloadOutput( new List <JobPayloadItem> ( new JobPayloadItem [] { new JobPayloadItem( JobPayloadItem.TypeEnum.Obj, null, //new JobObjOutputPayloadAdvanced (null, guid, new List<int> () { -1 }, unit) // all new JobObjOutputPayloadAdvanced(null, guid, new List <int> () { 1526, 1527 }, unit) ) } ), new JobPayloadDestination(targetRegion) ); JobPayload job = new JobPayload(jobInput, jobOutput); bool bForce = true; ApiResponse <dynamic> response = await DerivativesAPI.TranslateAsyncWithHttpInfo(job, bForce); httpErrorHandler(response, "Failed to register file for OBJ translation"); return(true); } catch (Exception) { Console.WriteLine("**** Failed to register file for OBJ translation"); return(false); } }