public Book.Book LoadBookIfNeeded() { if (_currentlyLoadedBook != BookSelection.CurrentSelection) { _currentlyLoadedBook = BookSelection.CurrentSelection; // In case we have any new settings since the last time we were in the Edit tab (BL-3881) _currentlyLoadedBook.BringBookUpToDate(new NullProgress()); } return(_currentlyLoadedBook); }
public static int Handle(HydrateParameters options) { if (!Directory.Exists(options.Path)) { if (options.Path.Contains(".htm")) { Debug.WriteLine("Supply only the directory, not the path to the file."); Console.Error.WriteLine("Supply only the directory, not the path to the file."); } else { Debug.WriteLine("Could not find " + options.Path); Console.Error.WriteLine("Could not find " + options.Path); } return(1); } Console.WriteLine("Starting Hydrating."); var layout = new Layout { SizeAndOrientation = SizeAndOrientation.FromString(options.SizeAndOrientation) }; var collectionSettings = new CollectionSettings { XMatterPackName = options.XMatter, Language1Iso639Code = options.VernacularIsoCode, Language2Iso639Code = string.IsNullOrWhiteSpace(options.NationalLanguage1IsoCode) ? options.VernacularIsoCode : options.NationalLanguage1IsoCode, Language3Iso639Code = options.NationalLanguage2IsoCode }; XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetInstalledXMatterDirectory() }); var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(), ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations()); var bookInfo = new BookInfo(options.Path, true); var book = new Book.Book(bookInfo, new BookStorage(options.Path, locator, new BookRenamedEvent(), collectionSettings), null, collectionSettings, null, null, new BookRefreshEvent(), new BookSavedEvent()); //we might change this later, or make it optional, but for now, this will prevent surprises to processes //running this CLI... the folder name won't change out from under it. book.LockDownTheFileAndFolderName = true; book.SetLayout(layout); book.BringBookUpToDate(new NullProgress()); Console.WriteLine("Finished Hydrating."); Debug.WriteLine("Finished Hydrating."); return(0); }
public void UpdateModelUponActivation() { if (BookSelection.CurrentSelection == null) { return; } _currentlyLoadedBook = BookSelection.CurrentSelection; PageLayout = _currentlyLoadedBook.GetLayout(); // BL-8648: In case we have an older version of a book (downloaded, e.g.) and the user went // straight to the Publish tab avoiding the Edit tab, we could arrive here needing to update // things. We choose to do the original book update here (when the user clicks on the Publish tab), // instead of the various places that we publish the book. // Note that the BringBookUpToDate() called by PublishHelper.MakeDeviceXmatterTempBook() and // called by BloomReaderFileMaker.PrepareBookForBloomReader() applies to a copy of the book // and is done in a way that explicitly avoids updating images. This call updates the images, // if needed, as a permanent fix. using (var dlg = new ProgressDialogForeground()) { dlg.ShowAndDoWork(progress => _currentlyLoadedBook.BringBookUpToDate(progress)); } }
public void LoadBook(BackgroundWorker worker, DoWorkEventArgs doWorkEventArgs) { _currentlyLoadedBook = BookSelection.CurrentSelection; try { // In case we have any new settings since the last time we were in the Edit tab (BL-3881) _currentlyLoadedBook.BringBookUpToDate(new NullProgress()); using(var tempHtml = MakeFinalHtmlForPdfMaker()) { if (doWorkEventArgs.Cancel) return; BookletLayoutMethod layoutMethod; if (this.BookletPortion == BookletPortions.AllPagesNoBooklet) layoutMethod = BookletLayoutMethod.NoBooklet; else layoutMethod = BookSelection.CurrentSelection.GetDefaultBookletLayout(); // Check memory for the benefit of developers. The user won't see anything. SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "about to create PDF file", false); _pdfMaker.MakePdf(tempHtml.Key, PdfFilePath, PageLayout.SizeAndOrientation.PageSizeName, PageLayout.SizeAndOrientation.IsLandScape, _currentlyLoadedBook.UserPrefs.ReducePdfMemoryUse, LayoutPagesForRightToLeft, layoutMethod, BookletPortion, worker, doWorkEventArgs, View); // Warn the user if we're starting to use too much memory. SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(false, "finished creating PDF file", true); } } catch (Exception e) { //we can't safely do any ui-related work from this thread, like putting up a dialog doWorkEventArgs.Result = e; // SIL.Reporting.ErrorReport.NotifyUserOfProblem(e, "There was a problem creating a PDF from this book."); // SetDisplayMode(DisplayModes.WaitForUserToChooseSomething); // return; } }
public static int Handle(HydrateParameters options) { if (!Directory.Exists(options.Path)) { if (options.Path.Contains(".htm")) { Debug.WriteLine("Supply only the directory, not the path to the file."); Console.Error.WriteLine("Supply only the directory, not the path to the file."); } else { Debug.WriteLine("Could not find " + options.Path); Console.Error.WriteLine("Could not find " + options.Path); } return(1); } Console.WriteLine("Starting Hydrating."); var layout = new Layout { SizeAndOrientation = SizeAndOrientation.FromString(options.SizeAndOrientation) }; var collectionSettings = new CollectionSettings { XMatterPackName = options.XMatter, Language1Iso639Code = options.VernacularIsoCode, Language2Iso639Code = options.NationalLanguage1IsoCode, Language3Iso639Code = options.NationalLanguage2IsoCode }; XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetInstalledXMatterDirectory() }); var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(), ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations()); var bookInfo = new BookInfo(options.Path, true); var book = new Book.Book(bookInfo, new BookStorage(options.Path, locator, new BookRenamedEvent(), collectionSettings), null, collectionSettings, null, null, new BookRefreshEvent()); if (collectionSettings.XMatterPackName == "Video") { if (null == book.OurHtmlDom.SelectSingleNodeHonoringDefaultNS("//script[contains(text(),'bloomPlayer.js')]")) { var element = book.OurHtmlDom.Head.AppendChild(book.OurHtmlDom.RawDom.CreateElement("script")) as XmlElement; element.IsEmpty = false; element.SetAttribute("type", "text/javascript"); element.SetAttribute("src", "bloomPlayer.js"); } AddRequisiteJsFiles(options.Path); } //we might change this later, or make it optional, but for now, this will prevent surprises to processes //running this CLI... the folder name won't change out from under it. book.LockDownTheFileAndFolderName = true; book.SetLayout(layout); book.BringBookUpToDate(new NullProgress()); Console.WriteLine("Finished Hydrating."); Debug.WriteLine("Finished Hydrating."); return(0); }
/// <summary> /// Import the spreadsheet into the dom /// </summary> /// <returns>a list of warnings</returns> public List <string> Import(InternalSpreadsheet sheet, IWebSocketProgress progress = null) { _sheet = sheet; _progress = progress ?? new NullWebSocketProgress(); Progress("Importing spreadsheet..."); _warnings = new List <string>(); _inputRows = _sheet.ContentRows.ToList(); _pages = _destinationDom.GetPageElements().ToList(); _bookIsLandscape = _pages[0]?.Attributes["class"]?.Value?.Contains("Landscape") ?? false; _currentRowIndex = 0; _currentPageIndex = -1; _groupsOnPage = new List <XmlElement>(); _imageContainersOnPage = new List <XmlElement>(); _destLayout = Layout.FromDom(_destinationDom, Layout.A5Portrait); while (_currentRowIndex < _inputRows.Count) { var currentRow = _inputRows[_currentRowIndex]; string rowTypeLabel = currentRow.MetadataKey; if (rowTypeLabel == InternalSpreadsheet.PageContentRowLabel) { bool rowHasImage = !string.IsNullOrWhiteSpace(currentRow.GetCell(InternalSpreadsheet.ImageSourceColumnLabel).Text); bool rowHasText = RowHasText(currentRow); if (rowHasImage && rowHasText) { AdvanceToNextGroupAndImageContainer(); } else if (rowHasImage) { AdvanceToNextImageContainer(); } else if (rowHasText) { AdvanceToNextGroup(); } if (rowHasImage) { PutRowInImage(currentRow); } if (rowHasText) { PutRowInGroup(currentRow, _currentGroup); } } else if (rowTypeLabel.StartsWith("[") && rowTypeLabel.EndsWith("]")) //This row is xmatter { string dataBookLabel = rowTypeLabel.Substring(1, rowTypeLabel.Length - 2); //remove brackets UpdateDataDivFromRow(currentRow, dataBookLabel); } _currentRowIndex++; } // This section is necessary to make sure changes to the dom are recorded. // If we run SS Importer from the CLI (without CollectionSettings), BringBookUpToDate() // will happen when we eventually open the book, but the user gets an updated thumbail and preview // if we do it here for the main production case where we DO have both the CollectionSettings // and the Book itself. Testing is the other situation (mostly) that doesn't use CollectionSettings. if (_collectionSettings != null && _book != null) { _book.BringBookUpToDate(new NullProgress()); } Progress("Done"); return(_warnings); }
public static int Handle(HydrateParameters options) { if (!Directory.Exists(options.Path)) { if (options.Path.Contains(".htm")) { Debug.WriteLine("Supply only the directory, not the path to the file."); Console.Error.WriteLine("Supply only the directory, not the path to the file."); } else { Debug.WriteLine("Could not find " + options.Path); Console.Error.WriteLine("Could not find " + options.Path); } return(1); } Console.WriteLine("Starting Hydrating."); var layout = new Layout { SizeAndOrientation = SizeAndOrientation.FromString(options.SizeAndOrientation) }; if (File.Exists(TeamCollectionManager.GetTcLinkPathFromLcPath(Path.GetDirectoryName(options.Path)))) { throw new ApplicationException("Hydrate command cannot currently be used in Team Collections"); // To make this possible, we'd need to spin up a TeamCollectionManager and TeamCollection and pass the latter // to the Book as its SaveContext and still changes would be forbidden unless the book was checked out. } var collectionSettings = new CollectionSettings { XMatterPackName = options.XMatter, Language1Iso639Code = options.VernacularIsoCode, Language2Iso639Code = string.IsNullOrWhiteSpace(options.NationalLanguage1IsoCode) ? options.VernacularIsoCode : options.NationalLanguage1IsoCode, Language3Iso639Code = options.NationalLanguage2IsoCode }; XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetFactoryXMatterDirectory(), }); var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(), ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations()); // alwaysSaveable is fine here, as we already checked it's not a TC. var bookInfo = new BookInfo(options.Path, true, new AlwaysEditSaveContext()); var book = new Book.Book(bookInfo, new BookStorage(options.Path, locator, new BookRenamedEvent(), collectionSettings), null, collectionSettings, null, null, new BookRefreshEvent(), new BookSavedEvent()); // This was added as part of the phase 1 changes towards the new language system, where book languages // are more clearly distinct from collection languages, and there's no sense (except underlying storage) in which // a book has languages that are not selected for display. This made it necessary to decide explicitly // whether passing the national language options implies that a book is bi- or tri-lingual. Andrew and I (JohnT) // could not think of any reason to pass the arguments at all except to achieve that, so I made it so. var langs = new List <string>(); langs.Add(options.VernacularIsoCode); if (!string.IsNullOrEmpty(options.NationalLanguage1IsoCode) && options.NationalLanguage1IsoCode != options.VernacularIsoCode) { langs.Add(options.NationalLanguage1IsoCode); } if (!string.IsNullOrEmpty(options.NationalLanguage2IsoCode)) { langs.Add(options.NationalLanguage2IsoCode); } book.SetMultilingualContentLanguages(langs.ToArray()); //we might change this later, or make it optional, but for now, this will prevent surprises to processes //running this CLI... the folder name won't change out from under it. book.LockDownTheFileAndFolderName = true; book.SetLayout(layout); book.BringBookUpToDate(new NullProgress()); Console.WriteLine("Finished Hydrating."); Debug.WriteLine("Finished Hydrating."); return(0); }
public static int Handle(HydrateParameters options) { if (!Directory.Exists(options.Path)) { if (options.Path.Contains(".htm")) { Debug.WriteLine("Supply only the directory, not the path to the file."); Console.Error.WriteLine("Supply only the directory, not the path to the file."); } else { Debug.WriteLine("Could not find " + options.Path); Console.Error.WriteLine("Could not find " + options.Path); } return 1; } Console.WriteLine("Starting Hydrating."); var layout = new Layout { SizeAndOrientation = SizeAndOrientation.FromString(options.SizeAndOrientation) }; var collectionSettings = new CollectionSettings { XMatterPackName = "Video", Language1Iso639Code = options.VernacularIsoCode, Language2Iso639Code = options.NationalLanguage1IsoCode, Language3Iso639Code = options.NationalLanguage2IsoCode }; XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetInstalledXMatterDirectory() }); var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(), ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations()); var bookInfo = new BookInfo(options.Path, true); var book = new Book.Book(bookInfo, new BookStorage(options.Path, locator, new BookRenamedEvent(), collectionSettings), null, collectionSettings, null, null, new BookRefreshEvent()); if (null == book.OurHtmlDom.SelectSingleNodeHonoringDefaultNS("//script[contains(text(),'bloomPlayer.js')]")) { var element = book.OurHtmlDom.Head.AppendChild(book.OurHtmlDom.RawDom.CreateElement("script")) as XmlElement; element.IsEmpty = false; element.SetAttribute("type", "text/javascript"); element.SetAttribute("src", "bloomPlayer.js"); } AddRequisiteJsFiles(options.Path); //we might change this later, or make it optional, but for now, this will prevent surprises to processes //running this CLI... the folder name won't change out from under it. book.LockDownTheFileAndFolderName = true; book.SetLayout(layout); book.BringBookUpToDate(new NullProgress()); Console.WriteLine("Finished Hydrating."); Debug.WriteLine("Finished Hydrating."); return 0; }