Esempio n. 1
0
        public static void Main(string[] args)
        {
            var resourceLocator = new ConsoleAppResourceLocator();
            var log             = new LoggingConfig(resourceLocator).CreateRootLogWriter();

            log.Debug("start");

            var options = new Options(args);

            var _htmlToEpub = new HtmlToEpubConverter(
                new Counter(log),
                log,
                options,
                new MecabParser(),
                new MecabReader(),
                new MecabBackend(),
                new XHtmlMaker(),
                new JmdicFastReader(
                    log,
                    resourceLocator,
                    new Jmdictionary()
                    ),
                new ContentsBreaker(new ChapterMarkersProvider(options, new ContentsDetector())),
                new EpubMaker(log, options, resourceLocator),
                new SentenceBreaker()
                );

            options.Print(Console.Out);

            _htmlToEpub.Convert().ContinueWith(_ =>
            {
                log.Debug("end");
            }).Wait();
        }
Esempio n. 2
0
        async void ConvertButtonClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_model.SourceFile))
            {
                _dialog.Info("Source file wasn't chosen", "Conversion is cancelled because the source file wasn't chosen");
                return;
            }

            if (!File.Exists(_model.SourceFile))
            {
                _dialog.Info("Source file doesn't exist", "Conversion is cancelled because the source file doesn't exist");
                return;
            }

            string targetFile;
            string filename = string.IsNullOrWhiteSpace(_model.SourceFile) ? string.Empty : Path.GetFileNameWithoutExtension(_model.SourceFile);

            if (!_dialog.SaveFile("Save epub as file", "Epub files|*.epub", filename, out targetFile))
            {
                _dialog.Info("Target file wasn't chosen", "Conversion is cancelled because the target file wasn't chosen");
                return;
            }

            _model.TargetFile = targetFile;

            var options = new Options(new string[] {
                "--inputFile", _model.SourceFile,
                "--outputFile", _model.TargetFile
            });

            // lock ui

            try
            {
                var htmlToEpub = new HtmlToEpubConverter(
                    new Counter(_log),
                    _log,
                    options,
                    new MecabParser(),
                    new MecabReader(),
                    new MecabBackend(),
                    new XHtmlMaker(),
                    await _jmdicReaderTask,
                    new ContentsBreaker(new ChapterMarkersProvider(options, new ContentsDetector())),
                    new EpubMaker(_log, options, _resourceLocator),
                    new SentenceBreaker()
                    );

                options.Print(Console.Out);

                await htmlToEpub.Convert();
            }
            catch (Exception ex)
            {
                _dialog.UnexpectedError(ex);
                throw;
            }
            finally
            {
                // unlock ui
                _fileManager.OpenFileManagerAndShowFile(Path.GetDirectoryName(targetFile));
            }
            _log.Debug("end");
        }
Esempio n. 3
0
        async partial void ConvertButtonClicked(NSObject sender)
        {
            _log.Debug($"Convert {FileToConvert.StringValue}");

            if (string.IsNullOrWhiteSpace(FileToConvert.StringValue))
            {
                _dialog.Info("Source file wasn't chosen", "Conversion is cancelled because the source file wasn't chosen");
                return;
            }

            if (!File.Exists(FileToConvert.StringValue))
            {
                _dialog.Info("Source file doesn't exist", "Conversion is cancelled because the source file doesn't exist");
                return;
            }

            string outputFile;
            string filename = string.IsNullOrWhiteSpace(FileToConvert.StringValue) ? string.Empty : Path.GetFileNameWithoutExtension(FileToConvert.StringValue);

            if (!_dialog.SaveFile("Save epub as file", "epub", filename, out outputFile))
            {
                _dialog.Info("Target file wasn't chosen", "Conversion is cancelled because the target file wasn't chosen");
                return;
            }

            var options = new Options(new string[]
            {
                "--inputFile", FileToConvert.StringValue,
                "--outputFile", outputFile,
            });

            OpenButton.Enabled           = false;
            ConvertButton.Enabled        = false;
            FileToConvert.Enabled        = false;
            ConversionStatus.StringValue = "Conversion started...";
            ConversionProgress.StartAnimation(null);

            try
            {
                var htmlToEpub = new HtmlToEpubConverter(
                    new Counter(_log),
                    _log,
                    options,
                    new MecabParser(),
                    new MecabReader(),
                    new MecabBackend(),
                    new XHtmlMaker(),
                    await _jmdicReaderTask,
                    new ContentsBreaker(new ChapterMarkersProvider(options, new ContentsDetector())),
                    new EpubMaker(_log, options, _resourceLocator),
                    new SentenceBreaker()
                    );

                options.Print(Console.Out);

                await htmlToEpub.Convert();
            }
            catch (Exception ex)
            {
                _dialog.UnexpectedError(ex);
            }
            finally
            {
                OpenButton.Enabled           = true;
                ConvertButton.Enabled        = true;
                FileToConvert.Enabled        = true;
                ConversionStatus.StringValue = "Conversion done";
                ConversionProgress.StopAnimation(null);

                _fileManager.OpenFileManagerAndShowFile(outputFile);
            }

            _log.Debug("end");
        }