/// <summary> /// Try the number of times given to make the ePUB before letting an ApplicationException be thrown. /// </summary> /// <remarks> /// The ExportEpubTests (including ExportEpubWithVideoTests and EpubValidAndAccessible) fail rather /// consistently (but not always) on Linux even though they always succeed on Windows. The failure /// mode is always having an ApplicationException thrown from inside PublishHelper.IsDisplayed /// while making the ePUB with the message "Failure to completely load visibility document in /// RemoveUnwantedContent". Converting all three subclasses to single class removed this failure /// mode on Linux, but introduced a failure mode on Windows where every test run reported two /// failures in this set of tests. Various attempts with lock on Mutex on the MakeEpub method /// had little to no effect. Implementing this retry method is the only solution that I've come /// up with that appears to work on both platforms. A test run of 20 times through all the export /// ePUB tests showed that no more than two tries were ever needed to succeed, but two tries were /// needed at least once per run on average. /// </remarks> protected ZipFile MakeEpubWithRetries(int maxRetry, string mainFileName, string folderName, Bloom.Book.Book book, BookInfo.HowToPublishImageDescriptions howToPublishImageDescriptions = BookInfo.HowToPublishImageDescriptions.None, string branding = "Default", Action <EpubMaker> extraInit = null) { ZipFile zipFile = null; for (int i = 1; i <= maxRetry; ++i) { try { zipFile = MakeEpub(mainFileName, folderName, book, howToPublishImageDescriptions, branding, extraInit); if (i > 1) { Console.WriteLine($"MakeEpub(\"{mainFileName}\",\"{folderName}\",...) succeeded on try number {i} to load the visibility document."); } break; } catch (ApplicationException e) { if (e.Message == "Failure to completely load visibility document in RemoveUnwantedContent") { if (i < maxRetry) { continue; } Console.WriteLine($"MakeEpub(\"{mainFileName}\",\"{folderName}\",...) failed {maxRetry} times to complete loading the visibility document."); } throw; } } return(zipFile); }
private void HandleImageDescriptions(HtmlDom htmlDom, BookInfo.HowToPublishImageDescriptions howTo = BookInfo.HowToPublishImageDescriptions.None) { var obj = new PrivateObject(new Bloom.Publish.Epub.EpubMaker(null, null)); obj.SetFieldOrProperty("PublishImageDescriptions", howTo); obj.Invoke("HandleImageDescriptions", htmlDom); }
/// <summary> /// Make an ePUB out of the specified book. Sets up several instance variables with commonly useful parts of the results. /// </summary> /// <returns></returns> protected virtual ZipFile MakeEpub(string mainFileName, string folderName, Bloom.Book.Book book, BookInfo.HowToPublishImageDescriptions howToPublishImageDescriptions = BookInfo.HowToPublishImageDescriptions.None, string branding = "Default", Action <EpubMaker> extraInit = null) { book.CollectionSettings.BrandingProjectKey = branding; // BringBookUpToDate is done on entering the Publish tab, outside the scope of these tests. // But note that it must be done AFTER setting the branding (which in Bloom will happen well before // entering the Publish tab). book.BringBookUpToDate(new NullProgress()); var epubFolder = new TemporaryFolder(folderName); var epubName = mainFileName + ".epub"; var epubPath = Path.Combine(epubFolder.FolderPath, epubName); using (var maker = CreateEpubMaker(book)) { maker.Unpaginated = true; // Currently we always make unpaginated epubs. maker.PublishImageDescriptions = howToPublishImageDescriptions; extraInit?.Invoke(maker); maker.SaveEpub(epubPath, new NullWebSocketProgress()); } Assert.That(File.Exists(epubPath)); _epub = new ZipFile(epubPath); _manifestFile = ExportEpubTestsBaseClass.GetManifestFile(_epub); _manifestContent = StripXmlHeader(GetZipContent(_epub, _manifestFile)); _manifestDoc = XDocument.Parse(_manifestContent); _defaultSourceValue = $"created from Bloom book on {DateTime.Now:yyyy-MM-dd} with page size A5 Portrait"; return(_epub); }