Unverified Commit 3f68e963 authored by Marius Göcke's avatar Marius Göcke
Browse files

added download-operation

parent 9cc890da
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ namespace SimpleOCR.CLI.Core.Helper
                }
                else
                {
                    ParserResult<RunCLI> parserResult = Parser.Default.ParseArguments<RunCLI>(arguments);
                    ParserResult<OCRAnalysisVerb> parserResult = Parser.Default.ParseArguments<OCRAnalysisVerb>(arguments);
                    return parserResult.MapResult(
                        parsedArgument =>
                        {
@@ -70,7 +70,7 @@ namespace SimpleOCR.CLI.Core.Helper
            }
        }

        private int HandleErrors(IEnumerable<Error> errors, ParserResult<RunCLI> parserResult)
        private int HandleErrors(IEnumerable<Error> errors, ParserResult<OCRAnalysisVerb> parserResult)
        {
            if(errors.IsHelp())
            {
+6 −1
Original line number Diff line number Diff line
@@ -10,10 +10,15 @@ namespace SimpleOCR.CLI.Core.Helper
        {
        }

        public int Handle(RunCLI runWithOptionsFromCLI)
        public int Handle(OCRAnalysisVerb runWithOptionsFromCLI)
        {
            this.RunBase = new RunWithArgumentsFromCLI(runWithOptionsFromCLI);
            return this.RunBase.Run();
        }

        public int Handle(DownloadOCRDataVerb downloadOCRData)
        {
            throw new System.NotImplementedException();
        }
    }
}
+28 −0
Original line number Diff line number Diff line
using GRYLibrary.Core.Logging.GeneralPurposeLogger;
using SimpleOCR.CLI.Core.Verbs;
using SimpleOCR.Library.Core.FileTypes;
using SimpleOCR.Library.Core.Visitors;
using SimpleOCR.Library.Core.VIsitors;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace SimpleOCR.CLI.Core.Runner
{
    internal class RunDownloader :RunBase
    {
        private readonly DownloadOCRDataVerb _Options;
        public RunDownloader(DownloadOCRDataVerb options) : base()
        {
            this._Options = options;
        }

        protected override string RunImplementation()
        {
            SimpleOCR.Library.Core.IOCRService ocrService = new SimpleOCR.Library.Core.OCRService(new SimpleOCR.Library.Core.OCRServiceConfiguration() { DataFolder = this._Options.TargetFolder}, GeneralLogger.CreateUsingConsole());
            ocrService.Download();
            return string.Empty;
        }
    }
}
+39 −39
Original line number Diff line number Diff line
using GRYLibrary.Core.Logging.GeneralPurposeLogger;
using SimpleOCR.CLI.Core.Verbs;
using SimpleOCR.Library.Core.FileTypes;
using SimpleOCR.Library.Core.Visitors;
using SimpleOCR.Library.Core.VIsitors;
using System;
using System.Collections.Generic;
using System.IO;
@@ -9,10 +9,10 @@ using System.Text;

namespace SimpleOCR.CLI.Core.Runner
{
    internal class RunWithArgumentsFromCLI :RunBase
    internal class RunOCRAnalysis :RunBase
    {
        private readonly RunCLI _Options;
        public RunWithArgumentsFromCLI(RunCLI options) : base()
        private readonly OCRAnalysisVerb _Options;
        public RunOCRAnalysis(OCRAnalysisVerb options) : base()
        {
            this._Options = options;
        }
@@ -23,7 +23,7 @@ namespace SimpleOCR.CLI.Core.Runner
            ocrService.Initialize();
            (FileType fileType, byte[] content, string mimeType) = SimpleOCR.Library.Core.Misc.Utilities.LoadFile(_Options.File);
            content = fileType.Accept(new ToPictureVisitor(content, mimeType));
            string result = ocrService.GetOCRContent(content, "image/jpeg", new HashSet<string>(this._Options.Languages));
            string result = ocrService.GetOCRContent(content, new HashSet<string>(this._Options.Languages));
            if(this._Options.Outputfile == null)
            {
                Console.WriteLine(result);
+23 −0
Original line number Diff line number Diff line
using CommandLine;
using System.Collections.Generic;

namespace SimpleOCR.CLI.Core.Verbs
{
    [Verb(nameof(DownloadOCRDataVerb), isDefault: true, HelpText = "Downloads OCR-data.")]
    public class DownloadOCRDataVerb :VerbBase
    {

        [Option('f', nameof(TargetFolder), Required = true)]
        public string TargetFolder { get; set; }

          public override void Accept(IVerbBaseVisitor visitor)
        {
            visitor.Handle(this);
        }

        public override T Accept<T>(IVerbBaseVisitor<T> visitor)
        {
            return visitor.Handle(this);
        }
    }
}
Loading