/// <summary> /// Recognizes layout elements from one or more passed-in forms. /// </summary> /// <param name="form">The stream containing one or more forms to recognize elements from.</param> /// <param name="recognizeContentOptions">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="RecognizeContentOperation"/> to wait on this long-running operation. Its <see cref="RecognizeContentOperation.Value"/> upon successful /// completion will contain layout elements extracted from the form.</returns> public virtual RecognizeContentOperation StartRecognizeContent(Stream form, RecognizeContentOptions recognizeContentOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(form, nameof(form)); recognizeContentOptions ??= new RecognizeContentOptions(); using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeContent)}"); scope.Start(); try { FormContentType contentType = recognizeContentOptions.ContentType ?? DetectContentType(form, nameof(form)); Response response = ServiceClient.AnalyzeLayoutAsync(contentType, form, cancellationToken); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeContentOperation(ServiceClient, Diagnostics, location)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Recognizes layout elements from one or more passed-in forms. /// </summary> /// <param name="formUri">The absolute URI of the remote file to recognize elements from.</param> /// <param name="recognizeContentOptions">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="RecognizeContentOperation"/> to wait on this long-running operation. Its <see cref="RecognizeContentOperation.Value"/> upon successful /// completion will contain layout elements extracted from the form.</returns> public virtual async Task <RecognizeContentOperation> StartRecognizeContentFromUriAsync(Uri formUri, RecognizeContentOptions recognizeContentOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(formUri, nameof(formUri)); recognizeContentOptions ??= new RecognizeContentOptions(); using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeContentFromUri)}"); scope.Start(); try { SourcePath sourcePath = new SourcePath() { Source = formUri.AbsoluteUri }; Response response = await ServiceClient.AnalyzeLayoutAsyncAsync(sourcePath, cancellationToken).ConfigureAwait(false); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeContentOperation(ServiceClient, Diagnostics, location)); } catch (Exception e) { scope.Failed(e); throw; } }