Beispiel #1
0
        private void SaveDocument()
        {
            DocumentSaver.Save(Document, Filename);
            Document.Manipulator.ResetUndoStack();

            MessageBus.Publish(new DocumentSavedEvent());
        }
Beispiel #2
0
        /// <summary>
        /// Creates an epub from the given urls.
        /// </summary>
        /// <remarks>
        /// This method makes use of a record created for each html that is given by a url.
        /// The records contain information from the html needed to create the various files which
        /// constitute the epub format. An immutable record is created initially so the data collected can be used
        /// accross various parts of the program. For example, the record contains a mapping (src map) for each image.
        /// This maps the current src of the image to a new local one - this is then used to change the sources of the
        /// html images to a local directory and also to download the images to the relevant local directory.
        /// </remarks>
        /// <param name="urls"></param>
        /// <param name="rootDirectory">Path in which the book will be created</param>
        /// <param name="bookTitle">Name of the book</param>
        /// <param name="guid">Unique identifier for the folder</param>
        /// <returns></returns>
        public async Task FromAsync(IEnumerable <string> urls, string rootDirectory, string bookTitle, Guid guid)
        {
            var htmlDocs = _htmlInput.GetHtmlDocumentsFromAsync(urls, new HtmlWeb());

            var directoryPaths    = GetDirectoryContext(rootDirectory, guid);
            var createDirectories = _epubOutput.CreateDirectoriesAsync(directoryPaths);

            var wikiPageRecords =
                (await htmlDocs).Select(doc => _getRecords.From(doc, "image_repo")).ToList();
            var downloadImages =
                Task.WhenAll(wikiPageRecords.SelectMany(record => _epubOutput.DownloadImages(record, directoryPaths)));

            var createEpubDocuments = Task.WhenAll(_getEpubDocs.From(wikiPageRecords, bookTitle, directoryPaths));

            // Save the produced files to relevant directory and compress them
            await createDirectories;
            var   saveDocuments  = DocumentSaver.Save(await createEpubDocuments);
            var   createMimeType = _epubOutput.CreateMimeFile(directoryPaths);

            Task.WaitAll(saveDocuments, createMimeType, downloadImages);
            await _epubOutput.ZipFiles(directoryPaths, guid);
        }