public async Task SingleSourceMultipleTargetsTest() { Uri source = await CreateSourceContainerAsync(oneDocumentList); Uri targetFrench = await CreateTargetContainerAsync(); Uri targetSpanish = await CreateTargetContainerAsync(); Uri targetArabic = await CreateTargetContainerAsync(); var client = GetClient(); var input = new DocumentTranslationInput(source, targetFrench, "fr"); input.AddTarget(targetSpanish, "es"); input.AddTarget(targetArabic, "ar"); var operation = await client.StartTranslationAsync(input); await operation.WaitForCompletionAsync(PollingInterval); if (operation.DocumentsSucceeded < 3) { await PrintNotSucceededDocumentsAsync(operation); } Assert.IsTrue(operation.HasCompleted); Assert.IsTrue(operation.HasValue); Assert.AreEqual(3, operation.DocumentsTotal); Assert.AreEqual(3, operation.DocumentsSucceeded); Assert.AreEqual(0, operation.DocumentsFailed); Assert.AreEqual(0, operation.DocumentsCancelled); Assert.AreEqual(0, operation.DocumentsInProgress); Assert.AreEqual(0, operation.DocumentsNotStarted); }
public async Task MultipleInputsAsync() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); Uri source1SasUriUri = new Uri("<source1 SAS URI>"); Uri source2SasUri = new Uri("<source2 SAS URI>"); Uri frenchTargetSasUri = new Uri("<french target SAS URI>"); Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>"); Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>"); Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>"); #region Snippet:MultipleInputsAsync //@@ Uri source1SasUriUri = <source1 SAS URI>; //@@ Uri source2SasUri = <source2 SAS URI>; //@@ Uri frenchTargetSasUri = <french target SAS URI>; //@@ Uri arabicTargetSasUri = <arabic target SAS URI>; //@@ Uri spanishTargetSasUri = <spanish target SAS URI>; //@@ Uri frenchGlossarySasUri = <french glossary SAS URI>; var glossaryFormat = "TSV"; var input1 = new DocumentTranslationInput(source1SasUriUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); input1.AddTarget(spanishTargetSasUri, "es"); var input2 = new DocumentTranslationInput(source2SasUri, arabicTargetSasUri, "ar"); input2.AddTarget(frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); var inputs = new List <DocumentTranslationInput>() { input1, input2 }; DocumentTranslationOperation operation = await client.StartTranslationAsync(inputs); await operation.WaitForCompletionAsync(); await foreach (DocumentStatusResult document in operation.GetValuesAsync()) { Console.WriteLine($"Document with Id: {document.DocumentId}"); Console.WriteLine($" Status:{document.Status}"); if (document.Status == TranslationStatus.Succeeded) { Console.WriteLine($" Translated Document Uri: {document.TranslatedDocumentUri}"); Console.WriteLine($" Translated to language: {document.TranslateTo}."); Console.WriteLine($" Document source Uri: {document.SourceDocumentUri}"); } else { Console.WriteLine($" Document source Uri: {document.SourceDocumentUri}"); Console.WriteLine($" Error Code: {document.Error.ErrorCode}"); Console.WriteLine($" Message: {document.Error.Message}"); } } #endregion }
public void DocumentTranslationInput() { Uri sourceSasUri = new Uri("<source SAS URI>"); Uri frenchTargetSasUri = new Uri("<french target SAS URI>"); Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>"); Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>"); #region Snippet:DocumentTranslationSingleInput //@@ Uri sourceSasUri = <source SAS URI>; //@@ Uri frenchTargetSasUri = <french target SAS URI>; //@@ Uri arabicTargetSasUri = <arabic target SAS URI>; //@@ Uri spanishTargetSasUri = <spanish target SAS URI>; var input = new DocumentTranslationInput(sourceSasUri, frenchTargetSasUri, "fr"); input.AddTarget(arabicTargetSasUri, "ar"); input.AddTarget(spanishTargetSasUri, "es"); #endregion Uri source1SasUri = new Uri("<source1 SAS URI>"); Uri source2SasUri = new Uri("<source2 SAS URI>"); #region Snippet:DocumentTranslationMultipleInputs //@@ Uri source1SasUri = <source1 SAS URI>; //@@ Uri source2SasUri = <source2 SAS URI>; var inputs = new List <DocumentTranslationInput> { new DocumentTranslationInput(source1SasUri, spanishTargetSasUri, "es"), new DocumentTranslationInput( source: new TranslationSource(source2SasUri), targets: new List <TranslationTarget> { new TranslationTarget(frenchTargetSasUri, "fr"), new TranslationTarget(spanishTargetSasUri, "es") }), }; #endregion }
public async Task StartTranslationWithCategoryId() { var mockResponse = new MockResponse(202); mockResponse.AddHeader(new HttpHeader("Operation-Location", "something/batches/215c9633-fca1-4821-ab29-70e4e2fbacc7")); var mockTransport = new MockTransport(new[] { mockResponse, mockResponse }); var client = CreateTestClient(mockTransport); var input = new DocumentTranslationInput(new Uri("http://source"), new Uri("http://target"), "fr"); input.AddTarget(new Uri("http://target2"), "es", categoryId: "myCategoryId"); await client.StartTranslationAsync(input); var contentString = GetString(mockTransport.Requests.Single().Content); string category = contentString.Substring(contentString.IndexOf("category"), 23); var expectedContent = "category\":\"myCategoryId"; Assert.AreEqual(expectedContent, category); }
public void MultipleInputs() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); Uri source1SasUriUri = new Uri("<source1 SAS URI>"); Uri source2SasUri = new Uri("<source2 SAS URI>"); Uri frenchTargetSasUri = new Uri("<french target SAS URI>"); Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>"); Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>"); Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>"); #region Snippet:MultipleInputs //@@ Uri source1SasUriUri = <source1 SAS URI>; //@@ Uri source2SasUri = <source2 SAS URI>; //@@ Uri frenchTargetSasUri = <french target SAS URI>; //@@ Uri arabicTargetSasUri = <arabic target SAS URI>; //@@ Uri spanishTargetSasUri = <spanish target SAS URI>; //@@ Uri frenchGlossarySasUri = <french glossary SAS URI>; var glossaryFormat = "TSV"; var input1 = new DocumentTranslationInput(source1SasUriUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); input1.AddTarget(spanishTargetSasUri, "es"); var input2 = new DocumentTranslationInput(source2SasUri, arabicTargetSasUri, "ar"); input2.AddTarget(frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); var inputs = new List <DocumentTranslationInput>() { input1, input2 }; DocumentTranslationOperation operation = client.StartTranslation(inputs); TimeSpan pollingInterval = new TimeSpan(1000); while (!operation.HasCompleted) { Thread.Sleep(pollingInterval); 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}"); } foreach (DocumentStatusResult document in operation.GetValues()) { Console.WriteLine($"Document with Id: {document.DocumentId}"); Console.WriteLine($" Status:{document.Status}"); if (document.Status == TranslationStatus.Succeeded) { Console.WriteLine($" URI: {document.TranslatedDocumentUri}"); Console.WriteLine($" Translated to language: {document.TranslateTo}."); } else { Console.WriteLine($" Error Code: {document.Error.ErrorCode}"); Console.WriteLine($" Message: {document.Error.Message}"); } } #endregion }
public async Task MultipleInputsAsync() { #if SNIPPET string endpoint = "<Document Translator Resource Endpoint>"; string apiKey = "<Document Translator Resource API Key>"; #else string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; #endif var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); #region Snippet:MultipleInputsAsync #if SNIPPET Uri source1SasUri = new Uri("<source1 SAS URI>"); Uri source2SasUri = new Uri("<source2 SAS URI>"); Uri frenchTargetSasUri = new Uri("<french target SAS URI>"); Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>"); Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>"); Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>"); #else Uri source1SasUri = await CreateSourceContainerAsync(oneTestDocuments); Uri source2SasUri = await CreateSourceContainerAsync(new List <TestDocument> { new TestDocument("Document2.txt", "Second english test document") }); Uri frenchTargetSasUri = await CreateTargetContainerAsync(); Uri arabicTargetSasUri = await CreateTargetContainerAsync(); Uri spanishTargetSasUri = await CreateTargetContainerAsync(); var glossary = new TestDocument("glossary.tsv", "test\tglossarytest"); Uri frenchGlossarySasUri = await CreateGlossaryAsync(glossary); #endif var glossaryFormat = "TSV"; var input1 = new DocumentTranslationInput(source1SasUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); input1.AddTarget(spanishTargetSasUri, "es"); var input2 = new DocumentTranslationInput(source2SasUri, arabicTargetSasUri, "ar"); input2.AddTarget(frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); var inputs = new List <DocumentTranslationInput>() { input1, input2 }; DocumentTranslationOperation operation = await client.StartTranslationAsync(inputs); await operation.WaitForCompletionAsync(); await foreach (DocumentStatusResult document in operation.GetValuesAsync()) { 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.ErrorCode}"); Console.WriteLine($" Message: {document.Error.Message}"); } } #endregion }
public void MultipleInputs() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); Uri source1SasUriUri = new Uri("<source1 SAS URI>"); Uri source2SasUri = new Uri("<source2 SAS URI>"); Uri frenchTargetSasUri = new Uri("<french target SAS URI>"); Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>"); Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>"); Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>"); var glossaryFormat = "TSV"; var input1 = new DocumentTranslationInput(source1SasUriUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); input1.AddTarget(spanishTargetSasUri, "es"); var input2 = new DocumentTranslationInput(source2SasUri, arabicTargetSasUri, "ar"); input2.AddTarget(frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat)); var inputs = new List <DocumentTranslationInput>() { input1, input2 }; DocumentTranslationOperation operation = client.StartTranslation(inputs); 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 (DocumentStatus 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: {document.TranslatedTo}."); Console.WriteLine($" Document source Uri: {document.SourceDocumentUri}"); } else { Console.WriteLine($" Document source Uri: {document.SourceDocumentUri}"); Console.WriteLine($" Error Code: {document.Error.ErrorCode}"); Console.WriteLine($" Message: {document.Error.Message}"); } } }