/// <summary> /// Analyzes pages from one or more documents, using a model built with custom forms or one of the prebuilt /// models provided by the Form Recognizer service. /// </summary> /// <param name="modelId"> /// The ID of the model to use for analyzing the input documents. When using a custom built model /// for analysis, this parameter must be the ID attributed to the model during its creation. When /// using one of the service's prebuilt models, one of the supported prebuilt model IDs must be passed. /// Prebuilt model IDs can be found at <see href="https://aka.ms/azsdk/formrecognizer/models"/>. /// </param> /// <param name="documentUri">The absolute URI of the remote file to analyze documents from.</param> /// <param name="analyzeDocumentOptions"> /// A set of options available for configuring the analyze request. For example, specify the locale of the /// document, or which pages to analyze. /// </param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns> /// An <see cref="AnalyzeDocumentOperation"/> to wait on this long-running operation. Its <see cref="AnalyzeDocumentOperation.Value"/> upon successful /// completion will contain analyzed pages from the input document. /// </returns> public virtual AnalyzeDocumentOperation StartAnalyzeDocumentFromUri(string modelId, Uri documentUri, AnalyzeDocumentOptions analyzeDocumentOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(modelId, nameof(modelId)); Argument.AssertNotNull(documentUri, nameof(documentUri)); analyzeDocumentOptions ??= new AnalyzeDocumentOptions(); using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentAnalysisClient)}.{nameof(StartAnalyzeDocumentFromUri)}"); scope.Start(); try { var request = new AnalyzeDocumentRequest() { UrlSource = documentUri.AbsoluteUri }; var response = ServiceClient.AnalyzeDocument( modelId, analyzeDocumentOptions.Pages.Count == 0 ? null : string.Join(",", analyzeDocumentOptions.Pages), analyzeDocumentOptions.Locale, Constants.DefaultStringIndexType, request, cancellationToken); return(new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Analyzes pages from one or more documents, using a model built with custom forms or one of the prebuilt /// models provided by the Form Recognizer service. /// </summary> /// <param name="modelId"> /// The ID of the model to use for analyzing the input documents. When using a custom built model /// for analysis, this parameter must be the ID attributed to the model during its creation. When /// using one of the service's prebuilt models, one of the supported prebuilt model IDs must be passed. /// Prebuilt model IDs can be found at <see href="https://aka.ms/azsdk/formrecognizer/models"/>. /// </param> /// <param name="document">The stream containing one or more documents to analyze.</param> /// <param name="analyzeDocumentOptions"> /// A set of options available for configuring the analyze request. For example, specify the locale of the /// document, or which pages to analyze. /// </param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns> /// An <see cref="AnalyzeDocumentOperation"/> to wait on this long-running operation. Its <see cref="AnalyzeDocumentOperation.Value"/> upon successful /// completion will contain analyzed pages from the input document. /// </returns> public virtual async Task <AnalyzeDocumentOperation> StartAnalyzeDocumentAsync(string modelId, Stream document, AnalyzeDocumentOptions analyzeDocumentOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(modelId, nameof(modelId)); Argument.AssertNotNull(document, nameof(document)); analyzeDocumentOptions ??= new AnalyzeDocumentOptions(); using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentAnalysisClient)}.{nameof(StartAnalyzeDocument)}"); scope.Start(); try { var response = await ServiceClient.AnalyzeDocumentAsync( modelId, ContentType1.ApplicationOctetStream, analyzeDocumentOptions.Pages.Count == 0?null : string.Join(",", analyzeDocumentOptions.Pages), analyzeDocumentOptions.Locale, Constants.DefaultStringIndexType, document, cancellationToken).ConfigureAwait(false); return(new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }