Exemplo n.º 1
0
        public async Task <HttpResponseMessage> ExtractCheck([FromUri] LeadWebRequest request)
        {
            try
            {
                AuthenticateRequest();

                if (!VerifyCommonParameters(request))
                {
                    throw new MalformedRequestException();
                }

                using (var stream = await GetImageStream(request.fileUrl))
                {
                    int lastPage = request.LastPage;
                    ValidateFile(stream, ref lastPage);

                    LoadDocumentOptions options = new LoadDocumentOptions()
                    {
                        FirstPageNumber = request.FirstPage,
                        LastPageNumber  = lastPage
                    };
                    RecognitionEngine recognitionEngine = new RecognitionEngine();
                    recognitionEngine.OcrEngine = ocrEngine;
                    var micrResults = recognitionEngine.ExtractMicr(stream, options, Leadtools.Forms.Commands.BankCheckMicrFontType.Unknown);
                    return(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(micrResults))
                    });
                }
            }
            catch (Exception e)
            {
                return(GenerateExceptionMessage(e));
            }
        }
Exemplo n.º 2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "Recognition/ExtractCheck")] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            try
            {
                if (!DemoConfiguration.UnlockSupport(log))
                {
                    return(GenerateErrorMessage(ApiError.LicenseNotSet, req));
                }

                var leadParameterObject = ParseLeadWebRequestParameters(req);
                if (!leadParameterObject.Successful)
                {
                    return(GenerateErrorMessage(ApiError.InvalidRequest, req));
                }

                var imageReturn = await GetImageStreamAsync(leadParameterObject.LeadWebRequest.fileUrl, req, DemoConfiguration.MaxUrlMbs);

                if (!imageReturn.Successful)
                {
                    return(GenerateErrorMessage(imageReturn.ErrorType.Value, req));
                }

                using (imageReturn.Stream)
                {
                    LoadDocumentOptions options = new LoadDocumentOptions()
                    {
                        FirstPageNumber = leadParameterObject.LeadWebRequest.FirstPage,
                        LastPageNumber  = leadParameterObject.LeadWebRequest.LastPage
                    };

                    RecognitionEngine recognitionEngine = new RecognitionEngine
                    {
                        WorkingDirectory = Path.GetTempPath(),
                        OcrEngine        = GetOcrEngine()
                    };

                    var micrResults   = recognitionEngine.ExtractMicr(imageReturn.Stream, options, BankCheckMicrFontType.Unknown);
                    var returnRequest = req.CreateResponse(HttpStatusCode.OK);
                    returnRequest.Content = new StringContent(JsonConvert.SerializeObject(micrResults));
                    return(returnRequest);
                }
            }
            catch (Exception ex)
            {
                log.Error($"API Error occurred for request: {context.InvocationId} \n Details: {JsonConvert.SerializeObject(ex)}");
                return(GenerateErrorMessage(ApiError.InternalServerError, req));
            }
        }