/// <summary>Snippet for ProcessDocumentAsync</summary> public async Task ProcessDocumentRequestObjectAsync() { // Snippet: ProcessDocumentAsync(ProcessDocumentRequest, CallSettings) // Additional: ProcessDocumentAsync(ProcessDocumentRequest, CancellationToken) // Create client DocumentUnderstandingServiceClient documentUnderstandingServiceClient = await DocumentUnderstandingServiceClient.CreateAsync(); // Initialize request argument(s) ProcessDocumentRequest request = new ProcessDocumentRequest { InputConfig = new InputConfig(), OutputConfig = new OutputConfig(), DocumentType = "", TableExtractionParams = new TableExtractionParams(), FormExtractionParams = new FormExtractionParams(), EntityExtractionParams = new EntityExtractionParams(), OcrParams = new OcrParams(), AutomlParams = new AutoMlParams(), Parent = "", }; // Make the request Document response = await documentUnderstandingServiceClient.ProcessDocumentAsync(request); // End snippet }
/// <summary>Snippet for BatchProcessDocumentsAsync</summary> public async Task BatchProcessDocumentsAsync() { // Snippet: BatchProcessDocumentsAsync(IEnumerable<ProcessDocumentRequest>, CallSettings) // Additional: BatchProcessDocumentsAsync(IEnumerable<ProcessDocumentRequest>, CancellationToken) // Create client DocumentUnderstandingServiceClient documentUnderstandingServiceClient = await DocumentUnderstandingServiceClient.CreateAsync(); // Initialize request argument(s) IEnumerable <ProcessDocumentRequest> requests = new ProcessDocumentRequest[] { new ProcessDocumentRequest(), }; // Make the request Operation <BatchProcessDocumentsResponse, OperationMetadata> response = await documentUnderstandingServiceClient.BatchProcessDocumentsAsync(requests); // Poll until the returned long-running operation is complete Operation <BatchProcessDocumentsResponse, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result BatchProcessDocumentsResponse result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <BatchProcessDocumentsResponse, OperationMetadata> retrievedResponse = await documentUnderstandingServiceClient.PollOnceBatchProcessDocumentsAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result BatchProcessDocumentsResponse retrievedResult = retrievedResponse.Result; } // End snippet }
public async stt::Task ProcessDocumentRequestObjectAsync() { moq::Mock <DocumentUnderstandingService.DocumentUnderstandingServiceClient> mockGrpcClient = new moq::Mock <DocumentUnderstandingService.DocumentUnderstandingServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); ProcessDocumentRequest request = new ProcessDocumentRequest { InputConfig = new InputConfig(), OutputConfig = new OutputConfig(), DocumentType = "document_typeba9d5586", TableExtractionParams = new TableExtractionParams(), FormExtractionParams = new FormExtractionParams(), EntityExtractionParams = new EntityExtractionParams(), OcrParams = new OcrParams(), AutomlParams = new AutoMlParams(), Parent = "parent7858e4d0", }; Document expectedResponse = new Document { Uri = "uri3db70593", Content = proto::ByteString.CopyFromUtf8("contentb964039a"), MimeType = "mime_type606a0ffc", Text = "textec51b21c", TextStyles = { new Document.Types.Style(), }, Pages = { new Document.Types.Page(), }, Entities = { new Document.Types.Entity(), }, EntityRelations = { new Document.Types.EntityRelation(), }, ShardInfo = new Document.Types.ShardInfo(), Error = new gr::Status(), Labels = { new Document.Types.Label(), }, }; mockGrpcClient.Setup(x => x.ProcessDocumentAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Document>(stt::Task.FromResult(expectedResponse), null, null, null, null)); DocumentUnderstandingServiceClient client = new DocumentUnderstandingServiceClientImpl(mockGrpcClient.Object, null); Document responseCallSettings = await client.ProcessDocumentAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Document responseCancellationToken = await client.ProcessDocumentAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task <bool> ProcessDocumentAsync(ProcessDocumentRequest request, bool isLargeFile, IAsyncCollector <Message> messages) { try { ProcessDocumentMessage processDocumentMessage; if (isLargeFile) { var documentId = $"{request.Id}-{Guid.NewGuid():N}"; await _blobService.UploadBlobAsync(documentId, JsonConvert.SerializeObject(request)); processDocumentMessage = new ProcessDocumentMessage { RequestReferenceId = documentId }; } else { processDocumentMessage = new ProcessDocumentMessage { Request = request }; } var message = new Message(Encoding.Default.GetBytes(JsonConvert.SerializeObject(processDocumentMessage))); message.UserProperties.Add("DocumentType", request.DocumentType.ToString()); await messages.AddAsync(message); return(true); } catch (Exception exception) { _logger.LogError(exception, "Error when processing the document."); } return(false); }
/// <summary>Snippet for ProcessDocument</summary> public void ProcessDocumentRequestObject() { // Snippet: ProcessDocument(ProcessDocumentRequest, CallSettings) // Create client DocumentUnderstandingServiceClient documentUnderstandingServiceClient = DocumentUnderstandingServiceClient.Create(); // Initialize request argument(s) ProcessDocumentRequest request = new ProcessDocumentRequest { InputConfig = new InputConfig(), OutputConfig = new OutputConfig(), DocumentType = "", TableExtractionParams = new TableExtractionParams(), FormExtractionParams = new FormExtractionParams(), EntityExtractionParams = new EntityExtractionParams(), OcrParams = new OcrParams(), AutomlParams = new AutoMlParams(), Parent = "", }; // Make the request Document response = documentUnderstandingServiceClient.ProcessDocument(request); // End snippet }
/// <summary> /// Processes a single document. /// </summary> /// <param name="request">The request object containing all of the parameters for the API call.</param> /// <param name="callSettings">If not null, applies overrides to this RPC call.</param> /// <returns>A Task containing the RPC response.</returns> public override stt::Task <Document> ProcessDocumentAsync(ProcessDocumentRequest request, gaxgrpc::CallSettings callSettings = null) { Modify_ProcessDocumentRequest(ref request, ref callSettings); return(_callProcessDocument.Async(request, callSettings)); }
/// <summary> /// Processes a single document. /// </summary> /// <param name="request">The request object containing all of the parameters for the API call.</param> /// <param name="callSettings">If not null, applies overrides to this RPC call.</param> /// <returns>The RPC response.</returns> public override Document ProcessDocument(ProcessDocumentRequest request, gaxgrpc::CallSettings callSettings = null) { Modify_ProcessDocumentRequest(ref request, ref callSettings); return(_callProcessDocument.Sync(request, callSettings)); }
partial void Modify_ProcessDocumentRequest(ref ProcessDocumentRequest request, ref gaxgrpc::CallSettings settings);
/// <summary> /// Processes a single document. /// </summary> /// <param name="request">The request object containing all of the parameters for the API call.</param> /// <param name="cancellationToken">A <see cref="st::CancellationToken"/> to use for this RPC.</param> /// <returns>A Task containing the RPC response.</returns> public virtual stt::Task <Document> ProcessDocumentAsync(ProcessDocumentRequest request, st::CancellationToken cancellationToken) => ProcessDocumentAsync(request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));
/// <summary> /// Processes a single document. /// </summary> /// <param name="request">The request object containing all of the parameters for the API call.</param> /// <param name="callSettings">If not null, applies overrides to this RPC call.</param> /// <returns>A Task containing the RPC response.</returns> public virtual stt::Task <Document> ProcessDocumentAsync(ProcessDocumentRequest request, gaxgrpc::CallSettings callSettings = null) => throw new sys::NotImplementedException();
/// <summary> /// Processes a single document. /// </summary> /// <param name="request">The request object containing all of the parameters for the API call.</param> /// <param name="callSettings">If not null, applies overrides to this RPC call.</param> /// <returns>The RPC response.</returns> public virtual Document ProcessDocument(ProcessDocumentRequest request, gaxgrpc::CallSettings callSettings = null) => throw new sys::NotImplementedException();
public async Task <ProcessDocumentResponse> ProcessDocumentAsync(ProcessDocumentRequest request) { var response = new ProcessDocumentResponse(); try { var sdkConfig = _cache.Get <EncompassSdkConfig>(ConstantString.EncompassSdkCacheKey); var tokenResponse = await RequestAccessToken(sdkConfig).ConfigureAwait(false); // get access token if (!tokenResponse.StatusCode.IsSuccessStatusCode()) { response.SuccessBit = false; response.EventStatus = EventStatusEnum.Error; response.ErrorMsgTxt = JsonConvert.SerializeObject(new { errorCode = tokenResponse.StatusCode, errorMsgTxt = JsonConvert.SerializeObject(tokenResponse.Body.FailureResponse) }); } var accessToken = tokenResponse.Body.SuccessResponse.AccessToken; // get list of latest documents via api var getAttachmentApis = await _encompassClient.QueryDocumentAsync(new GetAttachmentRequest { AccessToken = accessToken, LoanGuid = request.LoanGuid }).ConfigureAwait(false); if (getAttachmentApis.Body?.FailureResponse != null) { response.SuccessBit = false; response.EventStatus = EventStatusEnum.Error; response.ErrorMsgTxt = JsonConvert.SerializeObject(new { errorCode = getAttachmentApis.StatusCode, errorMsgTxt = string.Format(ConstantString.ErrorWhileGettingAttachments, JsonConvert.SerializeObject(getAttachmentApis.Body?.FailureResponse)) }); } var cachedDocuments = await GetDocumentCacheAsync(request.LoanGuid).ConfigureAwait(false); var apiDocuments = ParseDoucmentApiResponse(getAttachmentApis.Body); var apiDocumentIds = apiDocuments.Select(x => x.Key).ToHashSet(); var apiNotCacheDocumentIds = GetDocumentIdToDownload(cachedDocuments, apiDocumentIds); // latest documents from api the same as cache if (apiNotCacheDocumentIds.Count == 0) { response.SuccessBit = true; response.EventStatus = EventStatusEnum.Done; response.EventReason = string.Format(ConstantString.AllDocumentDowloaded); return(response); } // here means there are mismatch between documents in cache and in api var latestPersistedDocuments = await GetPersistedDocumentAsync(request.LoanGuid).ConfigureAwait(false); var apiNotDbDocumentIds = GetDocumentIdToDownload(latestPersistedDocuments, apiNotCacheDocumentIds); // there is no new documents if (apiNotDbDocumentIds.Count == 0) { response = await TryUpdateDocumentCache(request.LoanGuid, latestPersistedDocuments, response).ConfigureAwait(false); return(response); } // in db, we do not even have documents so we need to perform download. var addingDbResults = await AddNewDocument(apiNotDbDocumentIds, apiDocuments, request.LoanGuid).ConfigureAwait(false); var successAddingDbResults = ExtractSuccessDbResult(addingDbResults, response.DocErrors, false); var downloadDocumentResponses = await PerformDownloadDocument(successAddingDbResults, request.LoanGuid, accessToken).ConfigureAwait(false); var downloadSuccessResponses = ExtractSuccessApiResult(downloadDocumentResponses, response.DocErrors, false); var updatingDbResults = await UpdateNewDocument(downloadSuccessResponses, request.LoanGuid); var updatedSuccessDbResults = ExtractSuccessDbResult(updatingDbResults, response.DocErrors, true); var updatededDocumentGuids = GetUpdatedDocumentGuid(updatedSuccessDbResults); if (cachedDocuments != null) { updatededDocumentGuids.UnionWith(cachedDocuments); } response = await TryUpdateDocumentCache(request.LoanGuid, updatededDocumentGuids, response).ConfigureAwait(false); } catch (Exception ex) { response.SuccessBit = false; response.EventStatus = EventStatusEnum.Error; response.EventReason = ex.Message; response.ErrorMsgTxt = JsonConvert.SerializeObject(new { message = JsonConvert.SerializeObject(ex.Message), stackTrace = ex.StackTrace }); } return(response); }