Exemple #1
0
        public async Task TestFailedConversionsMissingAsset()
        {
            var client = GetClient();

            Uri storageUri = new Uri($"https://{TestEnvironment.StorageAccountName}.blob.core.windows.net/{TestEnvironment.BlobContainerName}");

            AssetConversionInputOptions input = new AssetConversionInputOptions(storageUri, "boxWhichDoesNotExist.fbx")
            {
                // We use SAS for live testing, as there can be a delay before DRAM-based access is available for new accounts.
                StorageContainerReadListSas = TestEnvironment.SasToken,
                BlobPrefix = "Input"
            };
            AssetConversionOutputOptions output = new AssetConversionOutputOptions(storageUri)
            {
                StorageContainerWriteSas = TestEnvironment.SasToken,
                BlobPrefix = "Output"
            };
            AssetConversionOptions conversionOptions = new AssetConversionOptions(input, output);

            string conversionId = Recording.Random.NewGuid().ToString();

            AssetConversionOperation conversionOperation = await client.StartConversionAsync(conversionId, conversionOptions);

            AssetConversion conversion = await conversionOperation.WaitForCompletionAsync();

            Assert.AreEqual(AssetConversionStatus.Failed, conversion.Status);
            Assert.IsNotNull(conversion.Error);
            // Invalid input provided. Check logs in output container for details.
            Assert.IsTrue(conversion.Error.Message.ToLower().Contains("invalid input"));
            Assert.IsTrue(conversion.Error.Message.ToLower().Contains("logs"));
        }
Exemple #2
0
        public void TestFailedConversionsNoAccess()
        {
            var client = GetClient();

            Uri storageUri = new Uri($"https://{TestEnvironment.StorageAccountName}.blob.core.windows.net/{TestEnvironment.BlobContainerName}");

            AssetConversionInputOptions input = new AssetConversionInputOptions(storageUri, "testBox.fbx")
            {
                // Do not provide SAS access to the container, and assume the test account is not linked to the storage.
                BlobPrefix = "Input"
            };
            AssetConversionOutputOptions output = new AssetConversionOutputOptions(storageUri)
            {
                BlobPrefix = "Output"
            };
            AssetConversionOptions conversionOptions = new AssetConversionOptions(input, output);

            string conversionId = Recording.Random.NewGuid().ToString();

            RequestFailedException ex = Assert.ThrowsAsync <RequestFailedException>(() => client.StartConversionAsync(conversionId, conversionOptions));

            Assert.AreEqual(403, ex.Status);
            // Error accessing connected storage account due to insufficient permissions. Check if the Mixed Reality resource has correct permissions assigned
            Assert.IsTrue(ex.Message.ToLower().Contains("storage"));
            Assert.IsTrue(ex.Message.ToLower().Contains("permissions"));
        }
Exemple #3
0
        public void ConvertMoreComplexAsset()
        {
            RemoteRenderingClient client = GetClient();

            Uri inputStorageUri  = new Uri($"https://{TestEnvironment.StorageAccountName}.blob.core.windows.net/{TestEnvironment.BlobContainerName}");
            Uri outputStorageUri = new Uri($"https://{TestEnvironment.StorageAccountName}.blob.core.windows.net/{TestEnvironment.BlobContainerName}");

            #region Snippet:StartAComplexAssetConversion
            AssetConversionInputOptions inputOptions = new AssetConversionInputOptions(inputStorageUri, "bicycle.gltf")
            {
                BlobPrefix = "Bicycle"
            };
            AssetConversionOutputOptions outputOptions = new AssetConversionOutputOptions(outputStorageUri)
            {
                BlobPrefix = "ConvertedBicycle"
            };
            AssetConversionOptions conversionOptions = new AssetConversionOptions(inputOptions, outputOptions);

            string conversionId = Guid.NewGuid().ToString();

            AssetConversionOperation conversionOperation = client.StartConversion(conversionId, conversionOptions);
            #endregion Snippet:StartAComplexAssetConversion

            AssetConversion conversion = conversionOperation.WaitForCompletionAsync().Result;
            if (conversion.Status == AssetConversionStatus.Succeeded)
            {
                Console.WriteLine($"Conversion succeeded: Output written to {conversion.Output.OutputAssetUri}");
            }
            else if (conversion.Status == AssetConversionStatus.Failed)
            {
                Console.WriteLine($"Conversion failed: {conversion.Error.Code} {conversion.Error.Message}");
            }
        }
Exemple #4
0
        public void ConvertSimpleAsset()
        {
            RemoteRenderingClient client = GetClient();

            Uri storageUri = new Uri($"https://{TestEnvironment.StorageAccountName}.blob.core.windows.net/{TestEnvironment.BlobContainerName}");

            #region Snippet:StartAnAssetConversion

            AssetConversionInputOptions  inputOptions      = new AssetConversionInputOptions(storageUri, "box.fbx");
            AssetConversionOutputOptions outputOptions     = new AssetConversionOutputOptions(storageUri);
            AssetConversionOptions       conversionOptions = new AssetConversionOptions(inputOptions, outputOptions);

            // A randomly generated GUID is a good choice for a conversionId.
            string conversionId = Guid.NewGuid().ToString();

            AssetConversionOperation conversionOperation = client.StartConversion(conversionId, conversionOptions);

            #endregion Snippet:StartAnAssetConversion
            #region Snippet:QueryAssetConversion

            AssetConversion conversion = conversionOperation.WaitForCompletionAsync().Result;
            if (conversion.Status == AssetConversionStatus.Succeeded)
            {
                Console.WriteLine($"Conversion succeeded: Output written to {conversion.Output.OutputAssetUri}");
            }
            else if (conversion.Status == AssetConversionStatus.Failed)
            {
                Console.WriteLine($"Conversion failed: {conversion.Error.Code} {conversion.Error.Message}");
            }

            #endregion Snippet:QueryAssetConversion
        }
Exemple #5
0
        public async Task TestSimpleConversion()
        {
            var client = GetClient();

            Uri storageUri = new Uri($"https://{TestEnvironment.StorageAccountName}.blob.core.windows.net/{TestEnvironment.BlobContainerName}");

            AssetConversionInputOptions input = new AssetConversionInputOptions(storageUri, "testBox.fbx")
            {
                // We use SAS for live testing, as there can be a delay before DRAM-based access is available for new accounts.
                StorageContainerReadListSas = TestEnvironment.SasToken,
                BlobPrefix = "Input"
            };
            AssetConversionOutputOptions output = new AssetConversionOutputOptions(storageUri)
            {
                StorageContainerWriteSas = TestEnvironment.SasToken,
                BlobPrefix = "Output"
            };
            AssetConversionOptions conversionOptions = new AssetConversionOptions(input, output);

            string conversionId = Recording.Random.NewGuid().ToString();

            AssetConversionOperation conversionOperation = await client.StartConversionAsync(conversionId, conversionOptions);

            Assert.AreEqual(conversionId, conversionOperation.Id);
            Assert.AreEqual(conversionOptions.InputOptions.RelativeInputAssetPath, conversionOperation.Value.Options.InputOptions.RelativeInputAssetPath);
            Assert.AreNotEqual(AssetConversionStatus.Failed, conversionOperation.Value.Status);

            AssetConversion conversion = await client.GetConversionAsync(conversionId);

            Assert.AreEqual(conversion.ConversionId, conversionId);
            Assert.AreNotEqual(AssetConversionStatus.Failed, conversion.Status);

            AssetConversion conversion2 = await conversionOperation.WaitForCompletionAsync();

            Assert.AreEqual(conversionId, conversion2.ConversionId);
            Assert.AreEqual(AssetConversionStatus.Succeeded, conversion2.Status);
            Assert.IsTrue(conversionOperation.Value.Output.OutputAssetUri.EndsWith("Output/testBox.arrAsset"));

            bool foundConversion = false;

            await foreach (var s in client.GetConversionsAync())
            {
                if (s.ConversionId == conversionId)
                {
                    foundConversion = true;
                }
            }
            Assert.IsTrue(foundConversion);
        }
Exemple #6
0
    private async Task ConvertModel(string modelPath, Stream modelStream = null)
    {
        try
        {
            // Settings
            string       msg;
            const string inputContainerName  = "arrinput";
            const string outputContainerName = "arroutput";

            string modelFile  = Path.GetFileName(modelPath);
            string outputFile = Path.ChangeExtension(modelFile, "arrAsset");

            msg = $"File selected for conversion: {modelPath}\n{modelFile}.";
            AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Info);
            Debug.Log(msg);

            // Default model folder name
            string folderName = string.Empty;

            // AAR Profile
            var loadedProfile = AppServices.RemoteRendering.LoadedProfile;

            // Initialize storage
            var storageAccountData = loadedProfile.StorageAccountData;
            StorageCredentials storageCredentials;

            if (storageAccountData.AuthType == AuthenticationType.AccountKey)
            {
                string authKey = await loadedProfile.StorageAccountData.GetAuthData();

                storageCredentials = new StorageCredentials(loadedProfile.StorageAccountData.StorageAccountName, authKey);
                if (loadedProfile.StorageModelPathByUsername)
                {
                    folderName = AKStorageAccountData.MODEL_PATH_BY_USERNAME_FOLDER;
                }
            }
            else
            {
                string authToken = await loadedProfile.StorageAccountData.GetAuthData();

                storageCredentials = new StorageCredentials(new TokenCredential(authToken));
                if (loadedProfile.StorageModelPathByUsername)
                {
                    folderName = AADAuth.SelectedAccount.Username;
                }
            }
            var storageAccount = new CloudStorageAccount(storageCredentials, loadedProfile.StorageAccountData.StorageAccountName, null, true);

            // Storage client
            var blobClient = storageAccount.CreateCloudBlobClient();

            // Input container
            var inputContainer = blobClient.GetContainerReference(inputContainerName);
            await inputContainer.CreateIfNotExistsAsync();

            // Output container
            var outputContainer = blobClient.GetContainerReference(outputContainerName);
            await outputContainer.CreateIfNotExistsAsync();

            msg = $"Uploading model.";
            AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Info);
            Debug.Log(msg);

            // Upload model
            CloudBlockBlob modelBlockBlob;
            if (loadedProfile.StorageModelPathByUsername)
            {
                var modelFolder = inputContainer.GetDirectoryReference(folderName);
                modelBlockBlob = modelFolder.GetBlockBlobReference(modelFile);
            }
            else
            {
                modelBlockBlob = inputContainer.GetBlockBlobReference(modelFile);
            }

            // Upload using path or provided stream
            if (modelStream == null)
            {
                await modelBlockBlob.UploadFromFileAsync(modelPath);
            }
            else
            {
                await modelBlockBlob.UploadFromStreamAsync(modelStream);
            }

            // Conversion parameters
            string inputUri  = $"https://{loadedProfile.StorageAccountName}.blob.core.windows.net/{inputContainerName}";
            string outputUri = $"https://{loadedProfile.StorageAccountName}.blob.core.windows.net/{outputContainerName}";

            var inputParams  = new AssetConversionInputOptions(inputUri, null, folderName, modelFile);
            var outputParams = new AssetConversionOutputOptions(outputUri, null, folderName, outputFile);
            var options      = new AssetConversionOptions(null, inputParams, outputParams);

            // Azure authentication
            var client = await loadedProfile.GetClient(loadedProfile.PreferredDomain);

            msg = $"Starting conversion.";
            AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Info);
            Debug.Log(msg);

            // Start conversion
            var   conversion = client.StartAssetConversionAsync(options);
            await conversion;

            string conversionId;

            // Conversion result
            if (conversion.IsCompleted)
            {
                msg = $"Conversion started.";
                AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Info);
                Debug.Log(msg);
                conversionId = conversion.Result.ConversionUuid;
            }
            else
            {
                msg = $"Error starting conversion.";
                AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error);
                Debug.LogError(msg);
                return;
            }

            // Poll conversion process
            while (true)
            {
                // Wait 10 seconds
                await Task.Delay(10000);

                // Poll conversion status
                var task = await client.GetAssetConversionStatusAsync(conversionId);

                ConversionSessionStatus status = task.Result;
                if (status == ConversionSessionStatus.Created || status == ConversionSessionStatus.Running)
                {
                    // In progress
                    msg = $"Conversion Session In Progress...";
                    AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Info);
                    Debug.Log(msg);
                }
                else
                {
                    // Done, success/fail
                    switch (status)
                    {
                    case ConversionSessionStatus.Unknown:
                    case ConversionSessionStatus.Aborted:
                    case ConversionSessionStatus.Failure:
                        msg = $"Conversion Session Failed.";
                        AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error);
                        Debug.LogError(msg);
                        break;

                    case ConversionSessionStatus.Success:
                        msg = $"Conversion Session Completed Successfully.";
                        AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Info);
                        OnModelConversionSuccess?.Invoke();
                        Debug.Log(msg);
                        break;
                    }

                    break;
                }
            }
        }
        catch (Exception e)
        {
            var msg = $"Conversion Process Failed.\n{e}";
            AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error);
            Debug.LogError(msg);
            Debug.LogError(e.StackTrace);
        }
    }