public async Task ObserveExistingAssetConversion() { string localFilePath = assetLocalFilePath; Vector3 assetGravity = new Vector3(assetGravityX, assetGravityY, assetGravityZ); float scale = assetScale; var clientWithWorkingInternalMethods = CreateClient(); ObjectAnchorsConversionClient client = InstrumentClient(clientWithWorkingInternalMethods); AssetUploadUriResult uploadUriResult = await client.GetAssetUploadUriAsync(); Uri uploadedInputAssetUri = uploadUriResult.UploadUri; BlobClient uploadBlobClient = InstrumentClient(new BlobClient(uploadedInputAssetUri, InstrumentClientOptions(new BlobClientOptions(BlobClientOptions.ServiceVersion.V2019_12_12)))); using (FileStream fs = File.OpenRead(localFilePath)) { await uploadBlobClient.UploadAsync(fs); } AssetConversionOptions assetConversionOptions = new AssetConversionOptions(uploadedInputAssetUri, AssetFileType.FromFilePath(localFilePath), assetGravity, scale); assetConversionOptions.JobId = Recording.Random.NewGuid(); Guid jobId = new Guid((await client.StartAssetConversionAsync(assetConversionOptions)).Id); AssetConversionOperation operation = InstrumentOperation(new AssetConversionOperation(jobId, clientWithWorkingInternalMethods)); await operation.WaitForCompletionAsync(); if (!operation.HasCompletedSuccessfully) { throw new Exception("The asset conversion operation completed with an unsuccessful status"); } string localFileDownloadPath = modelDownloadLocalFilePath; BlobClient downloadBlobClient = InstrumentClient(new BlobClient(operation.Value.OutputModelUri, InstrumentClientOptions(new BlobClientOptions(BlobClientOptions.ServiceVersion.V2019_12_12)))); BlobDownloadInfo downloadInfo = await downloadBlobClient.DownloadAsync(); using (FileStream file = File.OpenWrite(localFileDownloadPath)) { await downloadInfo.Content.CopyToAsync(file); var fileInfo = new FileInfo(localFileDownloadPath); Assert.Greater(fileInfo.Length, 0); } }
public async Task WaitForAssetConversionToComplete(Guid jobId) { Guid accountId = new Guid(TestEnvironment.AccountId); string accountDomain = TestEnvironment.AccountDomain; AzureKeyCredential credential = new AzureKeyCredential(TestEnvironment.AccountKey); ObjectAnchorsConversionClient client = new ObjectAnchorsConversionClient(accountId, accountDomain, credential); AssetConversionOperation operation = new AssetConversionOperation(jobId, client); await operation.WaitForCompletionAsync(); if (!operation.HasCompletedSuccessfully) { throw new Exception("The asset conversion operation completed with an unsuccessful status"); } }
public async Task RunFailedAssetConversion() { ( ObjectAnchorsConversionClient clientWithWorkingInternalMethods, ObjectAnchorsConversionClient client, AssetConversionOptions assetConversionOptions ) = await GetClientsAndConversionOptionsForAsset(fakeAssetLocalFilePath); AssetConversionOperation operation = await client.StartAssetConversionAsync(assetConversionOptions); await operation.WaitForCompletionAsync(); if (operation.HasCompletedSuccessfully) { throw new Exception("The asset conversion operation completed with an unexpected successful status"); } // ScaledAssetDimensions should be null when asset conversion fails due to an invalid asset file format // But should not throw an exception trying to access it if (operation.Value.ScaledAssetDimensions != null) { throw new Exception("ScaledAssetDimensions isn't null for a failed job on an invalid asset"); } }