コード例 #1
0
            private async Task <Tuple <Uri, Result> > OneCall(string apikey, Uri url)
            {
                Result res = null;

                try
                {
                    AddProgress(
                        pi.SetProgressInPercent(1).Progress
                        , url.ToString());
                    var fn = Lib.OCR.DocTools.GetFilename(url.LocalPath) + FixedOrigFileExtension;
                    logger.Debug($"starting OCR from {url.AbsoluteUri}");
                    res = await HlidacStatu.Lib.OCR.Api.Client.TextFromUrlAsync(apikey, url, this.Client,
                                                                                this.Priority, this.Intensity,
                                                                                fn, this.MaxWaitingTimeOfOneFile,
                                                                                this.RestartTaskIn);

                    logger.Debug($"DONE OCR from {url.AbsoluteUri}");
                    AddProgress(
                        pi.SetProgressInPercent(100).Progress
                        , url.ToString());
                    return(new Tuple <Uri, Result>(url, res));
                }
                catch (ApiException e)
                {
                    logger.Error($"TextFromURLAsync {url.AbsoluteUri} API error", e);
                    return(new Tuple <Uri, Result>(url, new Result()
                    {
                        Id = res?.Id, IsValid = Result.ResultStatus.Invalid, Error = e.ToString()
                    }));
                }
                catch (Exception e)
                {
                    logger.Error($"TextFromURLAsync {url.AbsoluteUri} error", e);
                    return(new Tuple <Uri, Result>(url, new Result()
                    {
                        Id = res?.Id, IsValid = Result.ResultStatus.Invalid, Error = e.ToString()
                    }));

                    //throw;
                }
            }
コード例 #2
0
            private async Task <Result> OneCall(string apikey, string fn)
            {
                Result res = null;

                try
                {
                    AddProgress(
                        pi.SetProgressInPercent(1).Progress
                        , fn);
                    logger.Debug($"Starting Api.Client.TextFromFileAsync for {fn}  parentTaskId:{this.ParentTaskId ?? ""}");
                    res = await HlidacStatu.Lib.OCR.Api.Client.TextFromFileAsync(apikey, fn, this.Client,
                                                                                 this.Priority, this.Intensity,
                                                                                 System.IO.Path.GetFileName(fn), this.MaxWaitingTimeOfOneFile,
                                                                                 this.RestartTaskIn);

                    logger.Debug($"Done Api.Client.TextFromFileAsync resultOK:{res.IsValid} fromOCR:{res.Server}  for {fn}  parentTaskId:{this.ParentTaskId ?? ""}");
                    AddProgress(
                        pi.SetProgressInPercent(100).Progress
                        , fn);
                    return(res);
                }
                catch (ApiException e)
                {
                    logger.Error($"TextFromFileAsync error for {fn}  parentTaskId:{this.ParentTaskId ?? ""}", e);
                    return(new Result()
                    {
                        Id = res?.Id, IsValid = Result.ResultStatus.Invalid, Error = e.ToString()
                    });
                }
                catch (Exception e)
                {
                    logger.Error($"TextFromFileAsync error for {fn}  parentTaskId:{this.ParentTaskId ?? ""}", e);
                    return(new Result()
                    {
                        Id = res?.Id, IsValid = Result.ResultStatus.Invalid, Error = e.ToString()
                    });

                    //throw;
                }
            }