diff --git a/sdk/translation/Azure.AI.Translation.Document/CHANGELOG.md b/sdk/translation/Azure.AI.Translation.Document/CHANGELOG.md index db37d2a15af2e..631b58dada978 100644 --- a/sdk/translation/Azure.AI.Translation.Document/CHANGELOG.md +++ b/sdk/translation/Azure.AI.Translation.Document/CHANGELOG.md @@ -1,14 +1,12 @@ # Release History -## 2.0.0-beta.2 (Unreleased) +## 2.0.0-beta.2 (2024-07-05) ### Features Added - -### Breaking Changes +- Single document translation client can be created using endpoint alone, mainly for SDK to work against containers. ### Bugs Fixed - -### Other Changes +- SourceInput options which is a part of TranslationInput is now public. This allows users to enter source language, source storage, and document filter prefix and suffix. ## 2.0.0-beta.1 (2024-05-07) diff --git a/sdk/translation/Azure.AI.Translation.Document/README.md b/sdk/translation/Azure.AI.Translation.Document/README.md index a0b325fa90893..12214b3bc7b79 100644 --- a/sdk/translation/Azure.AI.Translation.Document/README.md +++ b/sdk/translation/Azure.AI.Translation.Document/README.md @@ -469,6 +469,7 @@ Samples showing how to use the Cognitive Services Document Translation library a - [Operations History][operations_history_sample] ### Advanced samples +- [Start Translation with SourceInput][start_translation_with_sourceInput_sample] - [Multiple Inputs][multiple_Inputs_sample] - [Create Storage Containers and start translation][using_storage_sample] @@ -517,6 +518,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [operations_history_sample]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/translation/Azure.AI.Translation.Document/samples/Sample3_OperationsHistory.md [multiple_inputs_sample]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/translation/Azure.AI.Translation.Document/samples/Sample4_MultipleInputs.md [using_storage_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/translation/Azure.AI.Translation.Document/tests/samples/Sample_StartTranslationWithAzureBlob.cs +[start_translation_with_sourceInput_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/translation/Azure.AI.Translation.Document/tests/samples/Sample_StartTranslationWithSourceInput.cs [azure_cli]: https://docs.microsoft.com/cli/azure [azure_sub]: https://azure.microsoft.com/free/dotnet/ diff --git a/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs b/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs index ba8906075dd28..8e96f5884eed3 100644 --- a/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs +++ b/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs @@ -254,6 +254,8 @@ public MultipartFormFileData(string name, System.IO.Stream content, string conte public partial class SingleDocumentTranslationClient { protected SingleDocumentTranslationClient() { } + public SingleDocumentTranslationClient(System.Uri endpoint) { } + public SingleDocumentTranslationClient(System.Uri endpoint, Azure.AI.Translation.Document.DocumentTranslationClientOptions options) { } public SingleDocumentTranslationClient(System.Uri endpoint, Azure.AzureKeyCredential credential) { } public SingleDocumentTranslationClient(System.Uri endpoint, Azure.AzureKeyCredential credential, Azure.AI.Translation.Document.DocumentTranslationClientOptions options) { } public SingleDocumentTranslationClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } @@ -314,6 +316,7 @@ public TranslationGlossary(System.Uri glossaryUri, string format) { } public partial class TranslationSource : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public TranslationSource(System.Uri sourceUri) { } + public TranslationSource(System.Uri sourceUri, string languageCode = null, string storageSource = null, string prefix = null, string suffix = null) { } public string LanguageCode { get { throw null; } set { } } public string Prefix { get { throw null; } set { } } public System.Uri SourceUri { get { throw null; } } diff --git a/sdk/translation/Azure.AI.Translation.Document/assets.json b/sdk/translation/Azure.AI.Translation.Document/assets.json index 5b3ce33ea9209..6c855fbfb81f1 100644 --- a/sdk/translation/Azure.AI.Translation.Document/assets.json +++ b/sdk/translation/Azure.AI.Translation.Document/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/translation/Azure.AI.Translation.Document", - "Tag": "net/translation/Azure.AI.Translation.Document_d9bcf85e69" + "Tag": "net/translation/Azure.AI.Translation.Document_4ee1e847a5" } diff --git a/sdk/translation/Azure.AI.Translation.Document/samples/README.md b/sdk/translation/Azure.AI.Translation.Document/samples/README.md index a88b3722fb793..4b71e68842df6 100644 --- a/sdk/translation/Azure.AI.Translation.Document/samples/README.md +++ b/sdk/translation/Azure.AI.Translation.Document/samples/README.md @@ -24,6 +24,7 @@ Azure Cognitive Services Document Translation is a cloud service that translates - [Synchronous Document Translation](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/translation/Azure.AI.Translation.Document/samples/Sample5_SynchronousTranslation.md) ## Advanced samples +- [Start Translation with SourceInput](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/translation/Azure.AI.Translation.Document/tests/samples/Sample_StartTranslationWithSourceInput.cs) - [Multiple Inputs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/translation/Azure.AI.Translation.Document/samples/Sample4_MultipleInputs.md) - [Create Storage Containers And Submit Operation (code sample)](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/translation/Azure.AI.Translation.Document/tests/samples/Sample_StartTranslationWithAzureBlob.cs) diff --git a/sdk/translation/Azure.AI.Translation.Document/src/SingleDocumentTranslationClient.cs b/sdk/translation/Azure.AI.Translation.Document/src/SingleDocumentTranslationClient.cs new file mode 100644 index 0000000000000..1fb29c39668aa --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Document/src/SingleDocumentTranslationClient.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.AI.Translation.Document +{ + // Data plane generated client. + /// The SingleDocumentTranslation service client. + public partial class SingleDocumentTranslationClient + { + /// Initializes a new instance of SingleDocumentTranslationClient. + /// + /// Supported document Translation endpoint, protocol and hostname, for example: + /// https://{TranslatorResourceName}-doctranslation.cognitiveservices.azure.com + /// + /// is null. + public SingleDocumentTranslationClient(Uri endpoint) : this(endpoint, new DocumentTranslationClientOptions()) + { + } + + /// Initializes a new instance of SingleDocumentTranslationClient. + /// + /// Supported document Translation endpoint, protocol and hostname, for example: + /// https://{TranslatorResourceName}-doctranslation.cognitiveservices.azure.com + /// + /// The options for configuring the client. + /// is null. + public SingleDocumentTranslationClient(Uri endpoint, DocumentTranslationClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + options ??= new DocumentTranslationClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), Array.Empty(), new ResponseClassifier()); + _endpoint = endpoint; + _apiVersion = options.Version; + } + } +} diff --git a/sdk/translation/Azure.AI.Translation.Document/src/TranslationSource.cs b/sdk/translation/Azure.AI.Translation.Document/src/TranslationSource.cs index 347ae196cbfc5..9555bdb4af967 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/TranslationSource.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/TranslationSource.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.Translation.Document @@ -63,5 +64,35 @@ public string Suffix /// [CodeGenMember("Filter")] internal DocumentFilter Filter { get; set; } + + /// Initializes a new instance of . + /// Location of the folder / container or single file with your documents. + /// + /// Language code + /// If none is specified, we will perform auto detect on the document + /// + /// Storage Source. + /// Document prefix filter. + /// Document suffix filter. + public TranslationSource(Uri sourceUri, string languageCode = default, string storageSource = default, string prefix = default, string suffix = default) + { + SourceUri = sourceUri; + if (languageCode != null) + { + LanguageCode = languageCode; + } + if (storageSource != null) + { + StorageSource = storageSource; + } + if (prefix != null) + { + Prefix = prefix; + } + if (suffix != null) + { + Suffix = suffix; + } + } } } diff --git a/sdk/translation/Azure.AI.Translation.Document/tests/ContainerDocumentTranslationClientTests.cs b/sdk/translation/Azure.AI.Translation.Document/tests/ContainerDocumentTranslationClientTests.cs new file mode 100644 index 0000000000000..d35c199d031f1 --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Document/tests/ContainerDocumentTranslationClientTests.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.AI.Translation.Document.Tests +{ + public partial class ContainerDocumentTranslationClientTests : DocumentTranslationLiveTestBase + { + /// + /// Initializes a new instance of the class. + /// + /// A flag used by the Azure Core Test Framework to differentiate between tests for asynchronous and synchronous methods. + public ContainerDocumentTranslationClientTests(bool isAsync) + : base(isAsync) + { + } + + // Before running this test make sure you have docker application running and then run the Translator container + [Test] + [Ignore("Container Test only")] + public async Task StartSynchronousDocumentTranslation() + { + //Once the container is running, note the endpoint it is listening on and update accordingly + var endpoint = new Uri("http://localhost:5000"); + + SingleDocumentTranslationClient client = new SingleDocumentTranslationClient(endpoint); + + string filePath = Path.Combine("TestData", "test-input.txt"); + using Stream fileStream = File.OpenRead(filePath); + + var sourceDocument = new MultipartFormFileData(Path.GetFileName(filePath), fileStream, "text/html"); + DocumentTranslateContent content = new DocumentTranslateContent(sourceDocument); + + //make sure this language model "hi" is downloaded + var response = await client.DocumentTranslateAsync("hi", content, "en").ConfigureAwait(false); + var requestString = File.ReadAllText(filePath); + var responseString = Encoding.UTF8.GetString(response.Value.ToArray()); + Assert.IsNotEmpty(responseString); + Assert.IsNotNull(responseString); + Assert.AreNotEqual(requestString, responseString); + } + } +} diff --git a/sdk/translation/Azure.AI.Translation.Document/tests/DocumentTranslationClientLiveTests.cs b/sdk/translation/Azure.AI.Translation.Document/tests/DocumentTranslationClientLiveTests.cs index 6e7c0db462739..26236c2c85df6 100644 --- a/sdk/translation/Azure.AI.Translation.Document/tests/DocumentTranslationClientLiveTests.cs +++ b/sdk/translation/Azure.AI.Translation.Document/tests/DocumentTranslationClientLiveTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Azure.Core.TestFramework; using NUnit.Framework; @@ -21,6 +22,52 @@ public DocumentTranslationClientLiveTests(bool isAsync) { } + [RecordedTest] + [TestCase(true)] + [TestCase(false)] + public async Task GetTranslationStatusesTestWithSourceInputOptions(bool usetokenCredential) + { + Uri sourceUri = await CreateSourceContainerAsync(oneTestDocuments); + Uri targetUri = await CreateTargetContainerAsync(); + + DocumentTranslationClient client = GetClient(useTokenCredential: usetokenCredential); + + TranslationSource translationSource = new TranslationSource(sourceUri, "en"); + TranslationTarget translationTarget = new TranslationTarget(targetUri, "fr"); + List targets = new List { translationTarget }; + var input = new DocumentTranslationInput(translationSource, targets); + var translationOp = await client.StartTranslationAsync(input); + await translationOp.WaitForCompletionAsync(); + + // list translations with ID filter + var options = new GetTranslationStatusesOptions + { + Ids = { translationOp.Id } + }; + var translations = await client.GetTranslationStatusesAsync(options: options).ToEnumerableAsync(); + + // assert + Assert.GreaterOrEqual(translations.Count, 1); + TranslationStatusResult oneTranslation = translations[0]; + Assert.AreNotEqual(new DateTimeOffset(), oneTranslation.CreatedOn); + Assert.AreNotEqual(new DateTimeOffset(), oneTranslation.LastModified); + Assert.GreaterOrEqual(oneTranslation.DocumentsCanceled, 0); + Assert.GreaterOrEqual(oneTranslation.DocumentsFailed, 0); + Assert.GreaterOrEqual(oneTranslation.DocumentsInProgress, 0); + Assert.GreaterOrEqual(oneTranslation.DocumentsNotStarted, 0); + Assert.GreaterOrEqual(oneTranslation.DocumentsSucceeded, 0); + Assert.GreaterOrEqual(oneTranslation.DocumentsTotal, 0); + + if (oneTranslation.Status == DocumentTranslationStatus.Succeeded) + { + Assert.Greater(oneTranslation.TotalCharactersCharged, 0); + } + else + { + Assert.AreEqual(0, oneTranslation.TotalCharactersCharged); + } + } + [RecordedTest] public void ClientCannotAuthenticateWithFakeApiKey() { diff --git a/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationLiveTestBase.cs b/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationLiveTestBase.cs index 6ff57a8788d38..a205839901230 100644 --- a/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationLiveTestBase.cs +++ b/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationLiveTestBase.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Azure.Core.TestFramework; +using Azure.Identity; using Azure.Storage.Blobs; using Azure.Storage.Blobs.Models; using Azure.Storage.Sas; @@ -79,68 +80,62 @@ public DocumentTranslationClient GetClient( public BlobContainerClient GetBlobContainerClient(string containerName) { - return InstrumentClient(new BlobContainerClient( - TestEnvironment.StorageConnectionString, - containerName, - InstrumentClientOptions(new BlobClientOptions(BlobClientOptions.ServiceVersion.V2020_04_08)))); + string accountUrl = String.Format("https://{0}.blob.core.windows.net/", TestEnvironment.StorageAccountName); + BlobServiceClient blobServiceClient = new BlobServiceClient( + new Uri(accountUrl), + TestEnvironment.Credential, + InstrumentClientOptions(new BlobClientOptions(BlobClientOptions.ServiceVersion.V2020_04_08))); + BlobContainerClient blobContainerClient = blobServiceClient.CreateBlobContainer(containerName, PublicAccessType.None); + return InstrumentClient(blobContainerClient); } public Uri CreateSourceContainer(List documents) { var containerClient = CreateContainer("source", documents); - var expiresOn = DateTimeOffset.UtcNow.AddHours(1); - return containerClient.GenerateSasUri(BlobContainerSasPermissions.List | BlobContainerSasPermissions.Read, expiresOn); + return containerClient.Uri; } public async Task CreateSourceContainerAsync(List documents) { var containerClient = await CreateContainerAsync("source", documents); - var expiresOn = DateTimeOffset.UtcNow.AddHours(1); - return containerClient.GenerateSasUri(BlobContainerSasPermissions.List | BlobContainerSasPermissions.Read, expiresOn); + return containerClient.Uri; } public Uri CreateTargetContainer(List documents = default) { var containerClient = CreateContainer("target", documents); - var expiresOn = DateTimeOffset.UtcNow.AddHours(1); - return containerClient.GenerateSasUri(BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write, expiresOn); + return containerClient.Uri; } public async Task CreateTargetContainerAsync(List documents = default) { var containerClient = await CreateContainerAsync("target", documents); - var expiresOn = DateTimeOffset.UtcNow.AddHours(1); - return containerClient.GenerateSasUri(BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write, expiresOn); + return containerClient.Uri; } public async Task CreateGlossaryAsync(TestDocument document = default) { var containerClient = await CreateContainerAsync("glossary", new List { document }); - var expiresOn = DateTimeOffset.UtcNow.AddHours(1); - var glossaryContainerSasUri = containerClient.GenerateSasUri(BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List, expiresOn); - return new Uri(String.Format("{0}{1}{2}{3}/{4}{5}", glossaryContainerSasUri.Scheme, Uri.SchemeDelimiter, glossaryContainerSasUri.Authority, glossaryContainerSasUri.AbsolutePath, document.Name, glossaryContainerSasUri.Query)); + var containerUri = containerClient.Uri; + return new Uri(String.Format("{0}/{1}", containerUri, document.Name)); } public Uri CreateGlossary(TestDocument document = default) { var containerClient = CreateContainer("glossary", new List { document }); - var expiresOn = DateTimeOffset.UtcNow.AddHours(1); - var glossaryContainerSasUri = containerClient.GenerateSasUri(BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List, expiresOn); - return new Uri(String.Format("{0}{1}{2}{3}/{4}{5}", glossaryContainerSasUri.Scheme, Uri.SchemeDelimiter, glossaryContainerSasUri.Authority, glossaryContainerSasUri.AbsolutePath, document.Name, glossaryContainerSasUri.Query)); + var containerUri = containerClient.Uri; + return new Uri(String.Format("{0}/{1}", containerUri, document.Name)); } public async Task> CreateTargetContainerWithClientAsync(List documents = default) { var containerClient = await CreateContainerAsync("target", documents); - var expiresOn = DateTimeOffset.UtcNow.AddHours(1); - var containerSasUri = containerClient.GenerateSasUri(BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write, expiresOn); - return Tuple.Create(containerSasUri, containerClient); + return Tuple.Create(containerClient.Uri, containerClient); } private BlobContainerClient CreateContainer(string name, List documents) { var containerName = name + Recording.GenerateId(); - var containerClient = GetBlobContainerClient(containerName); - containerClient.Create(); + BlobContainerClient containerClient = GetBlobContainerClient(containerName); if (documents != default) { @@ -153,8 +148,7 @@ private BlobContainerClient CreateContainer(string name, List docu private async Task CreateContainerAsync(string name, List documents) { string containerName = name + Recording.GenerateId(); - var containerClient = GetBlobContainerClient(containerName); - await containerClient.CreateAsync().ConfigureAwait(false); + BlobContainerClient containerClient = GetBlobContainerClient(containerName); if (documents != default) { diff --git a/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationTestEnvironment.cs b/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationTestEnvironment.cs index 1ee3b83b259ee..25f4f023c93fa 100644 --- a/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationTestEnvironment.cs +++ b/sdk/translation/Azure.AI.Translation.Document/tests/Infrastructure/DocumentTranslationTestEnvironment.cs @@ -23,12 +23,8 @@ public DocumentTranslationTestEnvironment() /// The name of the environment variable from which the Document Translator Storage Account Name will be extracted for the live tests. private const string StorageAccountNameEnvironmentVariableName = "DOCUMENT_TRANSLATION_STORAGE_NAME"; - /// The name of the environment variable from which the Document Translator Storage Primary key will be extracted for the live tests. - private const string StorageConnectionStringEnvironmentVariableName = "DOCUMENT_TRANSLATION_CONNECTION_STRING"; - public string ApiKey => GetRecordedVariable(ApiKeyEnvironmentVariableName, options => options.IsSecret()); public string Endpoint => GetRecordedVariable(EndpointEnvironmentVariableName); - public string StorageConnectionString => GetRecordedVariable(StorageConnectionStringEnvironmentVariableName, options => options.HasSecretConnectionStringParameter("AccountKey", SanitizedValue.Base64)); public string StorageAccountName => GetRecordedVariable(StorageAccountNameEnvironmentVariableName); protected override async ValueTask IsEnvironmentReadyAsync() diff --git a/sdk/translation/Azure.AI.Translation.Document/tests/samples/Sample_StartTranslationWithSourceInput.cs b/sdk/translation/Azure.AI.Translation.Document/tests/samples/Sample_StartTranslationWithSourceInput.cs new file mode 100644 index 0000000000000..1ba84bbdf4410 --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Document/tests/samples/Sample_StartTranslationWithSourceInput.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Threading; +using Azure.AI.Translation.Document.Tests; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.AI.Translation.Document.Samples +{ + public partial class DocumentTranslationSamples : DocumentTranslationLiveTestBase + { + [Test] + [SyncOnly] + public void StartTranslationwithSourceInput() + { + /** + FILE: SampleTranslationWithAzureBlob.cs + DESCRIPTION: + This sample demonstrates how to start batch document translation by specifying some of the sourceInput options like + source language, storage source and DocumentFilter prefix and suffix + **/ +#if SNIPPET + string endpoint = ""; + string apiKey = ""; +#else + string endpoint = TestEnvironment.Endpoint; + string apiKey = TestEnvironment.ApiKey; +#endif + + var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); +#if SNIPPET + Uri sourceUri = new Uri(""); + Uri targetUri = new Uri(""); +#else + Uri sourceUri = CreateSourceContainer(oneTestDocuments); + Uri targetUri = CreateTargetContainer(); +#endif + //Creating a TranslationSource object with sourceURI, sourceLanguage, storageSource, DocumentFilterPrefix and DocumentFilterSuffix + TranslationSource translationSource = new TranslationSource(sourceUri, "en", "AzureBlob", "File", "txt"); + TranslationTarget translationTarget = new TranslationTarget(targetUri, "fr"); + List targets = new List { translationTarget }; + var input = new DocumentTranslationInput(translationSource, targets); + DocumentTranslationOperation operation = client.StartTranslation(input); + + TimeSpan pollingInterval = new(1000); + + while (true) + { + operation.UpdateStatus(); + + Console.WriteLine($"Status: {operation.Status}"); + Console.WriteLine($"Created on: {operation.CreatedOn}"); + Console.WriteLine($"Last modified: {operation.LastModified}"); + Console.WriteLine($"Total documents: {operation.DocumentsTotal}"); + Console.WriteLine($"Succeeded: {operation.DocumentsSucceeded}"); + Console.WriteLine($"Failed: {operation.DocumentsFailed}"); + Console.WriteLine($"In Progress: {operation.DocumentsInProgress}"); + Console.WriteLine($"Not started: {operation.DocumentsNotStarted}"); + + if (operation.HasCompleted) + { + break; + } + else + { + if (operation.GetRawResponse().Headers.TryGetValue("Retry-After", out string value)) + { + pollingInterval = TimeSpan.FromSeconds(Convert.ToInt32(value)); + } + Thread.Sleep(pollingInterval); + } + } + + foreach (DocumentStatusResult document in operation.GetValues()) + { + Console.WriteLine($"Document with Id: {document.Id}"); + Console.WriteLine($"Status:{document.Status}"); + if (document.Status == DocumentTranslationStatus.Succeeded) + { + Console.WriteLine($"Translated Document Uri: {document.TranslatedDocumentUri}"); + Console.WriteLine($"Translated to language code: {document.TranslatedToLanguageCode}."); + Console.WriteLine($"Document source Uri: {document.SourceDocumentUri}"); + } + else + { + Console.WriteLine($"Document source Uri: {document.SourceDocumentUri}"); + Console.WriteLine($"Error Code: {document.Error.Code}"); + Console.WriteLine($"Message: {document.Error.Message}"); + } + } + } + } +} diff --git a/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml b/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml index 6c7026aad1825..63f2b5f3b0150 100644 --- a/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml +++ b/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml @@ -1,5 +1,5 @@ directory: specification/translation/Azure.AI.DocumentTranslation -commit: c27f2af6b7ffa0e2d966fc0926b9d19242f9f774 +commit: db63bea839f5648462c94e685d5cc96f8e8b38ba repo: Azure/azure-rest-api-specs diff --git a/sdk/translation/test-resources.json b/sdk/translation/test-resources.json index 3589993d78d6b..ffa2b9fd41c5c 100644 --- a/sdk/translation/test-resources.json +++ b/sdk/translation/test-resources.json @@ -134,10 +134,6 @@ "type": "string", "value": "[variables('storageAccountName')]" }, - "DOCUMENT_TRANSLATION_CONNECTION_STRING": { - "type": "string", - "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-04-01').keys[0].value,';EndpointSuffix=core.windows.net')]" - }, "TEXT_TRANSLATION_API_KEY": { "type": "string", "value": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('txtUniqueSubDomainName')), '2017-04-18').key1]" diff --git a/sdk/translation/tests.yml b/sdk/translation/tests.yml index bf596ea3b4d54..89441c3cce7f1 100644 --- a/sdk/translation/tests.yml +++ b/sdk/translation/tests.yml @@ -7,3 +7,4 @@ extends: SupportedClouds: 'Public' TimeoutInMinutes: 90 Location: 'westus3' + UseFederatedAuth: true