public async Task AnalyzeReceiptOCRAsync()
        {
            try
            {
                if (this.ImageUrl != null)
                {
                    this.ReceiptOcrResult = await ReceiptOCRHelper.GetReceiptOCRResult(this.ImageUrl);
                }
                else if (this.GetImageStreamCallback != null)
                {
                    this.ReceiptOcrResult = await ReceiptOCRHelper.GetReceiptOCRResult(await this.GetImageStreamCallback());
                }

                ResolveWordsInReceiptFields();
            }
            catch (Exception)
            {
                this.ReceiptOcrResult = new AnalyzeResultResponse();
            }
        }
コード例 #2
0
        private async Task <AnalyzeFormResult> GetResultFromResponse(HttpResponseMessage response)
        {
            // Process operation
            if (response.Headers.Contains(this.HEADER_OPERATION_LOCATION_KEY) == false)
            {
                throw new InvalidOperationException("No operation-location value returned from initial request.");
            }

            Uri locationUri = new Uri(response.Headers.GetValues(this.HEADER_OPERATION_LOCATION_KEY).First());

            var opResult = new AnalyzeResultResponse();

            int i = 0;

            while (i++ < RETRY_COUNT)
            {
                // Get the operation result
                opResult = await HttpClientUtility.GetAsync <AnalyzeResultResponse>(locationUri, this.RequestHeaders);

                // Wait if operation is running or has not started
                if (opResult.Status == "notStarted" || opResult.Status == "running")
                {
                    await Task.Delay(RETRY_DELAY);
                }
                else
                {
                    break;
                }
            }

            if (opResult.Status != "succeeded")
            {
                throw new Exception($"Form recognition operation was not successful with status: {opResult.Status}");
            }

            return(opResult.AnalyzeResult);
        }