Beispiel #1
0
        public virtual RecognizeReceiptsOperation StartRecognizeReceipts(Stream receiptFileStream, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(receiptFileStream, nameof(receiptFileStream));

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

            ResponseWithHeaders <ServiceAnalyzeReceiptAsyncHeaders> response = ServiceClient.AnalyzeReceiptAsync(contentType, receiptFileStream, includeTextDetails: recognizeOptions.IncludeTextContent, cancellationToken);

            return(new RecognizeReceiptsOperation(ServiceClient, response.Headers.OperationLocation));
        }
Beispiel #2
0
        public virtual RecognizeReceiptsOperation StartRecognizeReceipts(Stream receipt, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(receipt, nameof(receipt));

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

            Response response = ServiceClient.AnalyzeReceiptAsync(contentType, receipt, includeTextDetails: recognizeOptions.IncludeTextContent, cancellationToken);
            string   location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

            return(new RecognizeReceiptsOperation(ServiceClient, Diagnostics, location));
        }
        /// <summary>
        /// Recognizes values from one or more receipts.
        /// </summary>
        /// <param name="receipt">The stream containing the one or more receipts to recognize values from.</param>
        /// <param name="recognizeReceiptsOptions">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="RecognizeReceiptsOperation"/> to wait on this long-running operation.  Its <see cref="RecognizeReceiptsOperation.Value"/> upon successful
        /// completion will contain the extracted receipt.</returns>
        public virtual RecognizeReceiptsOperation StartRecognizeReceipts(Stream receipt, RecognizeReceiptsOptions recognizeReceiptsOptions = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(receipt, nameof(receipt));

            recognizeReceiptsOptions ??= new RecognizeReceiptsOptions();

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

            try
            {
                FormContentType contentType = recognizeReceiptsOptions.ContentType ?? DetectContentType(receipt, nameof(receipt));

                Response response = ServiceClient.AnalyzeReceiptAsync(contentType, receipt, includeTextDetails: recognizeReceiptsOptions.IncludeFieldElements, cancellationToken);
                string   location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

                return(new RecognizeReceiptsOperation(ServiceClient, Diagnostics, location));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }