/// <summary>
        /// Recognizes pages from one or more forms, using a model trained with custom forms.
        /// </summary>
        /// <param name="modelId">The ID of the model to use for recognizing form values.</param>
        /// <param name="form">The stream containing one or more forms to recognize elements from.</param>
        /// <param name="recognizeCustomFormsOptions">A set of options available for configuring the recognize request.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>A <see cref="RecognizeCustomFormsOperation"/> to wait on this long-running operation.  Its <see cref="RecognizeCustomFormsOperation.Value"/> upon successful
        /// completion will contain recognized pages from the input document.</returns>
        public virtual async Task <RecognizeCustomFormsOperation> StartRecognizeCustomFormsAsync(string modelId, Stream form, RecognizeCustomFormsOptions recognizeCustomFormsOptions = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(modelId, nameof(modelId));
            Argument.AssertNotNull(form, nameof(form));

            recognizeCustomFormsOptions ??= new RecognizeCustomFormsOptions();

            using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeCustomForms)}");
            scope.Start();

            try
            {
                Guid            guid        = ClientCommon.ValidateModelId(modelId, nameof(modelId));
                FormContentType contentType = recognizeCustomFormsOptions.ContentType ?? DetectContentType(form, nameof(form));

                Response response = await ServiceClient.AnalyzeWithCustomModelAsync(guid, contentType, form, includeTextDetails : recognizeCustomFormsOptions.IncludeFieldElements, cancellationToken).ConfigureAwait(false);

                string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

                return(new RecognizeCustomFormsOperation(ServiceClient, Diagnostics, location));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #2
0
        public virtual async Task <RecognizeCustomFormsOperation> StartRecognizeCustomFormsAsync(string modelId, Stream formFileStream, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(modelId, nameof(modelId));
            Argument.AssertNotNull(formFileStream, nameof(formFileStream));

            Guid guid = ClientCommon.ValidateModelId(modelId, nameof(modelId));

            recognizeOptions ??= new RecognizeOptions();
            FormContentType contentType = recognizeOptions.ContentType ?? DetectContentType(formFileStream, nameof(formFileStream));

            Response response = await ServiceClient.AnalyzeWithCustomModelAsync(guid, contentType, formFileStream, includeTextDetails : recognizeOptions.IncludeTextContent, cancellationToken).ConfigureAwait(false);

            string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

            return(new RecognizeCustomFormsOperation(ServiceClient, Diagnostics, location));
        }