/// <summary> /// Starts a translation operation which translates the document(s) in your source container /// to your <see cref="TranslationTarget"/>(s) in the given language. /// <para>For document length limits, maximum batch size, and supported document formats, see /// <a href="https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview"/>.</para> /// </summary> /// <param name="inputs">Sets the inputs for the translation operation /// including source and target containers for documents to be translated. </param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <exception cref="RequestFailedException">Service returned a non-success status code. </exception> public virtual async Task<DocumentTranslationOperation> StartTranslationAsync(IEnumerable<DocumentTranslationInput> inputs, CancellationToken cancellationToken = default) { var request = new StartTranslationDetails(inputs); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(StartTranslation)}"); scope.Start(); try { ResponseWithHeaders<DocumentTranslationStartTranslationHeaders> job = await _serviceRestClient.StartTranslationAsync(request, cancellationToken).ConfigureAwait(false); return new DocumentTranslationOperation(_serviceRestClient, _clientDiagnostics, job.Headers.OperationLocation); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Starts a translation operation which translates the document(s) in your source container /// to your <see cref="TranslationTarget"/>(s) in the given language. /// <para>For document length limits, maximum batch size, and supported document formats, see /// <a href="https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview"/>.</para> /// </summary> /// <param name="input">Sets the input for the translation operation /// including source and target containers for documents to be translated. </param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <exception cref="RequestFailedException">Service returned a non-success status code. </exception> public virtual DocumentTranslationOperation StartTranslation(DocumentTranslationInput input, CancellationToken cancellationToken = default) { Argument.AssertNotNull(input, nameof(input)); var request = new StartTranslationDetails(new List<DocumentTranslationInput> { input }); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DocumentTranslationClient)}.{nameof(StartTranslation)}"); scope.Start(); try { ResponseWithHeaders<DocumentTranslationStartTranslationHeaders> job = _serviceRestClient.StartTranslation(request, cancellationToken); return new DocumentTranslationOperation(_serviceRestClient, _clientDiagnostics, job.Headers.OperationLocation); } catch (Exception e) { scope.Failed(e); throw; } }