Example #1
0
        /// <summary>
        /// Run conversion tasks of source files
        /// </summary>
        /// <param name="inFiles">Array of source files</param>
        /// <param name="outDir">Destination directory</param>
        public void Convert(string[] inFiles, string outDir)
        {
            Parallel.ForEach(inFiles, item =>
            {
                ItemConverter convertItem = CreateItemComverter(item, outDir);
                StartConvertTask(item, convertItem);
            });

            WaitTillTasksEnd();
        }
Example #2
0
        /// <summary>
        /// Start conversion task, place it to tasks container and raise event
        /// </summary>
        /// <param name="inFile">Source file name</param>
        /// <param name="convertItem">Conversion object which is used for task</param>
        private void StartConvertTask(string inFile, ItemConverter convertItem)
        {
            if (convertItem != null)
            {
                if (ConvertStartEvent != null)
                {
                    ConvertStartEvent(inFile);
                }

                _convertTasks.Add(Task.Run(() => convertItem.Convert()));
            }
        }
Example #3
0
        /// <summary>
        /// Check source file for e-book and create conversion object
        /// </summary>
        /// <param name="inFile">Source file name</param>
        /// <param name="outDir">Destination directory</param>
        /// <returns>Conversion object or null if source file is not e-book</returns>
        private ItemConverter CreateItemComverter(string inFile, string outDir)
        {
            ItemConverter convertItem = null;

            if (Path.GetExtension(inFile).Equals(".epub", StringComparison.OrdinalIgnoreCase) == true)
            {
                // .epub e-book file is discovered
                var outFile = Path.Combine(outDir, Path.GetFileNameWithoutExtension(inFile) + ".mobi");

                convertItem =
                    new EpubItemConverter(inFile, outFile, _deleteInputFile, _rewriteOutputFile, _compressionLevel, _verbose);
            }
            else if ((string.Equals(Path.GetExtension(inFile), ".zip", StringComparison.OrdinalIgnoreCase) == true) &&
                     (string.Equals(Path.GetExtension(
                                        Path.GetFileNameWithoutExtension(inFile)), ".epub", StringComparison.OrdinalIgnoreCase) == true))
            {
                // .epub e-book file in zip archive is discovered
                var outFileName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(inFile)) + ".mobi";
                var outFile     = Path.Combine(outDir, outFileName);

                convertItem =
                    new EpubItemConverter(inFile, outFile, _deleteInputFile, _rewriteOutputFile, _compressionLevel, _verbose);
            }
            else if (string.Equals(Path.GetExtension(inFile), ".fb2", StringComparison.OrdinalIgnoreCase) == true)
            {
                // .fb2 e-book file is discovered
                var outFile = Path.Combine(outDir, Path.GetFileNameWithoutExtension(inFile) + ".mobi");

                convertItem =
                    new Fb2ItemConverter(inFile, outFile, _deleteInputFile, _rewriteOutputFile, _compressionLevel, _verbose);
            }
            else if ((string.Equals(Path.GetExtension(inFile), ".zip", StringComparison.OrdinalIgnoreCase) == true) &&
                     (string.Equals(Path.GetExtension
                                        (Path.GetFileNameWithoutExtension(inFile)), ".fb2", StringComparison.OrdinalIgnoreCase) == true))
            {
                // .fb2 e-book file in zip archive is discovered
                var outFileName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(inFile)) + ".mobi";
                var outFile     = Path.Combine(outDir, outFileName);

                convertItem =
                    new Fb2ItemConverter(inFile, outFile, _deleteInputFile, _rewriteOutputFile, _compressionLevel, _verbose);
            }

            return(convertItem);
        }