/// -------------------------------------------------------------------------------- /// <summary> /// Reloads the specified Paratext project with the latest data. /// </summary> /// -------------------------------------------------------------------------------- public void ReloadProject(IScrText project) { if (project != null) { project.Reload(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the Paratext project and enumerator, preparing us to read the data files. /// </summary> /// <param name="paratextProjectId">3-letter Paratext project ID</param> /// <returns>true if the project was loaded, else false</returns> /// ------------------------------------------------------------------------------------ protected virtual void LoadParatextProject(string paratextProjectId) { try { m_ptProjectText = ScriptureProvider.MakeScrText(paratextProjectId); } catch (Exception e) { // Can't load Paratext project if Paratext is not installed. throw new ParatextLoadException( TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e); } try { // create ref objs of the Paratext lib Logger.WriteEvent("Loading Paratext project " + paratextProjectId + " to import from " + m_settings.StartRef.AsString + " to " + m_settings.EndRef.AsString); // Now initialize the TextEnum with the range of Scripture text we want m_ptParser = m_ptProjectText.Parser; m_ptCurrBook = ScriptureProvider.MakeVerseRef(m_settings.StartRef.Book, 0, 0); ResetParatextState(); } catch (Exception e) { string msg = string.Format( TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"), paratextProjectId); throw new ParatextLoadException(msg, e); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads the texts for each Scripture book title, section, footnote, etc. /// </summary> /// ------------------------------------------------------------------------------------ public void LoadScriptureTexts(FdoCache cache, IBookImporter bookImporter) { m_bookImporter = bookImporter; m_associatedPtText = bookImporter != null?ParatextHelper.GetAssociatedProject(cache.ProjectId) : null; m_scr = cache.LanguageProject.TranslatedScriptureOA; if (m_scr == null) { return; } List <TreeNode> otBooks = new List <TreeNode>(); List <TreeNode> ntBooks = new List <TreeNode>(); for (int bookNum = 1; bookNum <= BCVRef.LastBook; bookNum++) { var bookName = cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton.BooksOS[bookNum - 1].UIBookName; object book = m_scr.FindBook(bookNum); if (book == null) { if (m_associatedPtText != null && m_associatedPtText.BookPresent(bookNum)) { book = bookNum; } else { continue; } } TreeNode node = new TreeNode(bookName); node.Tag = book; node.Name = "Book"; // help us query for books. if (bookNum < ScriptureTags.kiNtMin) { otBooks.Add(node); } else { ntBooks.Add(node); } } TreeNode bibleNode = new TreeNode(FwControls.kstidBibleNode); bibleNode.Name = "Bible"; if (otBooks.Count > 0) { TreeNode testamentNode = new TreeNode(FwControls.kstidOtNode, otBooks.ToArray()); testamentNode.Name = "Testament"; // help us query for Testaments bibleNode.Nodes.Add(testamentNode); } if (ntBooks.Count > 0) { TreeNode testamentNode = new TreeNode(FwControls.kstidNtNode, ntBooks.ToArray()); testamentNode.Name = "Testament"; // help us query for Testaments bibleNode.Nodes.Add(testamentNode); } Nodes.Add(bibleNode); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets any back translations of the specified base project. /// </summary> /// ------------------------------------------------------------------------------------ public static IEnumerable <IScrText> GetBtsForProject(IScrText baseProj) { // We're looking for projects that are back translations of baseProj. That means they have type // back translation, and their base project is the one we want. // Seems that baseProj.Equals(proj.BaseScrText) should work, but it doesn't, at least in one unit test, // possibly just because the mock is not simulating the real helper well enough. return(s_ptHelper.GetProjects().Where(proj => baseProj.Name.Equals(proj.TranslationInfo.BaseProjectName) && proj.TranslationInfo.Type == ProjectType.BackTranslation)); }
public void GetAssociatedProject() { m_ptHelper.AddProject("MNKY", "Soup"); m_ptHelper.AddProject("SOUP", "Monkey Soup"); m_ptHelper.AddProject("GRK", "Levington"); m_ptHelper.AddProject("Mony", "Money"); IScrText found = ParatextHelper.GetAssociatedProject(new TestProjectId(BackendProviderType.kXML, "Monkey Soup")); Assert.AreEqual("SOUP", found.Name); }
/// <summary/> protected virtual void Dispose(bool fDisposing) { System.Diagnostics.Debug.WriteLineIf(!fDisposing, "****** Missing Dispose() call for " + GetType() + ". *******"); if (fDisposing && !IsDisposed) { // dispose managed and unmanaged objects Cleanup(); } m_ptProjectText = null; IsDisposed = true; }
/// <summary> /// This class creates text, it must delete it here when UNDO is commanded /// so it can update InterestingTexts. /// </summary> /* public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel) * { * if (cvDel != 1) * return; * SaveOnChangeRecord(); * SuppressSaveOnChangeRecord = true; * try * { * m_list.DeleteCurrentObject(); * } * finally * { * SuppressSaveOnChangeRecord = false; * } * GetInterestingTextList().UpdateInterestingTexts(); * } */ #region IBookImporter Members /// ------------------------------------------------------------------------------------ /// <summary> /// Imports the specified book. /// </summary> /// <param name="bookNum">The canonical book number.</param> /// <param name="owningForm">Form that can be used as the owner of progress dialogs and /// message boxes.</param> /// <param name="importBt">True to import only the back translation, false to import /// only the main translation</param> /// <returns> /// The ScrBook created to hold the imported data /// </returns> /// ------------------------------------------------------------------------------------ public IScrBook Import(int bookNum, Form owningForm, bool importBt) { IScripture scr = Cache.LangProject.TranslatedScriptureOA; bool haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => { IScrImportSet importSettings = scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6); importSettings.StyleSheet = ScriptureStylesheet; IScrText paratextProj = ParatextHelper.GetAssociatedProject(Cache.ProjectId); importSettings.ParatextScrProj = paratextProj.Name; importSettings.StartRef = new BCVRef(bookNum, 0, 0); int chapter = paratextProj.Versification.LastChapter(bookNum); importSettings.EndRef = new BCVRef(bookNum, chapter, paratextProj.Versification.LastVerse(bookNum, chapter)); if (!importBt) { importSettings.ImportTranslation = true; importSettings.ImportBackTranslation = false; } else { List <IScrText> btProjects = ParatextHelper.GetBtsForProject(paratextProj).ToList(); if (btProjects.Count > 0 && (string.IsNullOrEmpty(importSettings.ParatextBTProj) || !btProjects.Any(st => st.Name == importSettings.ParatextBTProj))) { importSettings.ParatextBTProj = btProjects[0].Name; } if (string.IsNullOrEmpty(importSettings.ParatextBTProj)) { return(false); } importSettings.ImportTranslation = false; importSettings.ImportBackTranslation = true; } ParatextHelper.LoadProjectMappings(importSettings); ScrMappingList importMap = importSettings.GetMappingListForDomain(ImportDomain.Main); ImportMappingInfo figureInfo = importMap[@"\fig"]; if (figureInfo != null) { figureInfo.IsExcluded = true; } importSettings.SaveSettings(); return(true); }); if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("TeImportExport.dll", "SIL.FieldWorks.TE.TeImportManager"), "ImportParatext", owningForm, ScriptureStylesheet, (FwApp)m_mediator.PropertyTable.GetValue("App"))) { return(scr.FindBook(bookNum)); } return(null); }
/// <summary> /// Imports the specified book's back translation. /// </summary> /// <param name="owningForm">Form that can be used as the owner of progress dialogs and /// message boxes.</param> /// <param name="bookNum">The canonical book number.</param> /// <param name="btProject">The BT project to import</param> private void ImportBackTranslation(Form owningForm, int bookNum, IScrText btProject) { if (string.IsNullOrEmpty(btProject.Name)) { return; } IScrImportSet importSettings = null; NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => { importSettings = m_scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6, m_scriptureStylesheet, FwDirectoryFinder.FlexStylesPath); importSettings.ParatextScrProj = m_associatedPtText.Name; importSettings.StartRef = new BCVRef(bookNum, 0, 0); importSettings.EndRef = new BCVRef(bookNum, 0, 0); importSettings.ParatextBTProj = btProject.Name; importSettings.ImportTranslation = false; importSettings.ImportBackTranslation = true; ParatextHelper.LoadProjectMappings(importSettings); var importMap = importSettings.GetMappingListForDomain(ImportDomain.Main); // Check for corrupted import settings, clear them out if they are bad. if (importMap == null) { m_scr.DefaultImportSettings = null; m_scr.ImportSettingsOC.Clear(); importSettings = null; } else { var figureInfo = importMap[@"\fig"]; if (figureInfo != null) { figureInfo.IsExcluded = true; } importSettings.SaveSettings(); } }); if (importSettings != null) { ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("ParatextImport.dll", "ParatextImport.ParatextImportManager"), "ImportParatext", owningForm, m_cache, importSettings, m_scriptureStylesheet, App); } }
/// <summary/> public ScriptureProvider.IScriptureProviderParserState GetParserState(IScrText ptProjectText, IVerseRef ptCurrBook) { return(new PT8ParserStateWrapper(new ScrParserState((ScrText)ptProjectText.CoreScrText, (VerseRef)ptCurrBook.CoreVerseRef))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reloads the specified Paratext project with the latest data. (no-op) /// </summary> /// ------------------------------------------------------------------------------------ public void ReloadProject(IScrText project) { // Nothing to do }
public ScriptureProvider.IScriptureProviderParserState GetParserState(IScrText ptProjectText, IVerseRef ptCurrBook) { throw new NotImplementedException(); }
/// <summary/> public static IScriptureProviderParserState GetParserState(IScrText ptProjectText, IVerseRef ptCurrBook) { return(_scriptureProvider.GetParserState(ptProjectText, ptCurrBook)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Fill in the children for a particular book. This is typically done when it gets /// expanded or when we need a list including the children. Separating it from the /// initial load saves a lot of time when we have a long list of books. /// </summary> /// <param name="bookNode">The book node.</param> /// <returns><c>true</c> if the dummy node was replaced by real child node(s)</returns> /// <remarks>protected virtual for unit tests</remarks> /// ------------------------------------------------------------------------------------ protected virtual bool FillInBookChildren(TreeNode bookNode) { var book = bookNode.Tag as IScrBook; var bookNum = book?.CanonicalNum ?? (int)bookNode.Tag; var owningForm = FindForm(); while (owningForm != null && !owningForm.Visible) { owningForm = owningForm.Owner; } if (owningForm == null) { owningForm = Form.ActiveForm ?? Application.OpenForms[0]; } if (m_associatedPtText != null) { // Update main text, if possible/needed. if (m_associatedPtText.BookPresent(bookNum)) { // PT has it. // If we don't have it, OR if our copy is stale, then get updated copy. if (book == null || !m_associatedPtText.IsCheckSumCurrent(bookNum, book.ImportedCheckSum)) { // Get new/fresh version from PT. var importedBook = ImportBook(owningForm, bookNum); if (importedBook != null) { book = importedBook; bookNode.Tag = importedBook; } } } if (book == null) { // No book, so don't fret about a back translation return(false); } // Update back translation IScrText btProject = ParatextHelper.GetBtsForProject(m_associatedPtText).FirstOrDefault(); if (btProject != null && btProject.BookPresent(book.CanonicalNum) && !btProject.IsCheckSumCurrent(book.CanonicalNum, book.ImportedBtCheckSum.get_String(book.Cache.DefaultAnalWs).Text)) { // The BT for this book node is out-of-date with the Paratext BT data ImportBackTranslation(owningForm, bookNum, btProject); } } bookNode.Nodes.Clear(); // Gets rid of dummy. // Add Title node. if (book.TitleOA != null) { var titleNode = new TreeNode(ResourceHelper.GetResourceString("kstidScriptureTitle")) { Name = book.TitleOA.ToString(), Tag = book.TitleOA }; bookNode.Nodes.Add(titleNode); } // Add Sections. foreach (var section in book.SectionsOS) { var chapterVerseBridge = m_scr.ChapterVerseBridgeAsString(section); // Include the heading text if it's not empty. See LT-8764. var cTotal = section.HeadingOA?.ParagraphsOS.Cast <IScrTxtPara>().Sum(para => para.Contents.Length); if (cTotal > 0) { var sFmt = ResourceHelper.GetResourceString("kstidSectionHeading"); var node = new TreeNode(string.Format(sFmt, chapterVerseBridge)) { Name = string.Format(sFmt, section), Tag = section.HeadingOA // expect an StText }; bookNode.Nodes.Add(node); } var sectionNode = new TreeNode(chapterVerseBridge) { Name = section.ToString(), Tag = section.ContentOA // expect an StText }; bookNode.Nodes.Add(sectionNode); } // Add Footnotes in reverse order, so we can insert them in the proper order. var footnotes = new List <IScrFootnote>(book.FootnotesOS); footnotes.Reverse(); foreach (var scrFootnote in footnotes) { // insert under the relevant section, if any (LTB-408) IScrSection containingSection; IStText containingTitle = null; if (!scrFootnote.TryGetContainingSection(out containingSection) && !scrFootnote.TryGetContainingTitle(out containingTitle)) { continue; } var nodeName = m_scr.ContainingRefAsString(scrFootnote); var footnoteNode = new TreeNode(nodeName) { Tag = scrFootnote, Name = "Footnote" }; // see if we can lookup the node of this section. var nodeIndex = bookNode.Nodes.IndexOfKey(containingSection?.ToString() ?? containingTitle.ToString()); if (nodeIndex >= 0) { bookNode.Nodes.Insert(nodeIndex + 1, footnoteNode); } else { bookNode.Nodes.Add(footnoteNode); // insert at end. } } return(true); }
protected virtual bool FillInBookChildren(TreeNode bookNode) { IScrBook book = bookNode.Tag as IScrBook; int bookNum = (book == null) ? (int)bookNode.Tag : book.CanonicalNum; Form owner = FindForm(); while (owner != null && !owner.Visible) { owner = owner.Owner; } if (owner == null) { owner = Form.ActiveForm ?? Application.OpenForms[0]; } if (book == null || (m_associatedPtText != null && m_associatedPtText.BookPresent(book.CanonicalNum) && !m_associatedPtText.IsCheckSumCurrent(book.CanonicalNum, book.ImportedCheckSum))) { // The book for this node is out-of-date with the Paratext book data IScrBook importedBook = m_bookImporter.Import(bookNum, owner, false); if (importedBook != null) { bookNode.Tag = book = importedBook; } if (book == null) { return(false); } } if (m_associatedPtText != null) { IScrText btProject = ParatextHelper.GetBtsForProject(m_associatedPtText).FirstOrDefault(); if (btProject != null && btProject.BookPresent(book.CanonicalNum) && !btProject.IsCheckSumCurrent(book.CanonicalNum, book.ImportedBtCheckSum.get_String(book.Cache.DefaultAnalWs).Text)) { // The BT for this book node is out-of-date with the Paratext BT data m_bookImporter.Import(bookNum, owner, true); } } bookNode.Nodes.Clear(); // Gets rid of dummy. //IScrBook book = (IScrBook)bookNode.Tag; // Add Title node. if (book.TitleOA != null) { TreeNode titleNode = new TreeNode(ResourceHelper.GetResourceString("kstidScriptureTitle")); titleNode.Name = book.TitleOA.ToString(); titleNode.Tag = book.TitleOA; bookNode.Nodes.Add(titleNode); } // Add Sections. foreach (IScrSection section in book.SectionsOS) { string chapterVerseBridge = m_scr.ChapterVerseBridgeAsString(section); if (section.HeadingOA != null) { // Include the heading text if it's not empty. See LT-8764. int cTotal = 0; foreach (IScrTxtPara para in section.HeadingOA.ParagraphsOS) { cTotal += para.Contents.Length; } if (cTotal > 0) { string sFmt = ResourceHelper.GetResourceString("kstidSectionHeading"); TreeNode node = new TreeNode(String.Format(sFmt, chapterVerseBridge)); node.Name = String.Format(sFmt, section); node.Tag = section.HeadingOA; // expect an StText bookNode.Nodes.Add(node); } } TreeNode sectionNode = new TreeNode(chapterVerseBridge); sectionNode.Name = section.ToString(); sectionNode.Tag = section.ContentOA; // expect an StText bookNode.Nodes.Add(sectionNode); } // Add Footnotes in reverse order, so we can insert them in the proper order. List <IScrFootnote> footnotes = new List <IScrFootnote>(book.FootnotesOS); footnotes.Reverse(); foreach (IScrFootnote scrFootnote in footnotes) { // insert under the relevant section, if any (LTB-408) IScrSection containingSection; IStText containingTitle = null; if (scrFootnote.TryGetContainingSection(out containingSection) || scrFootnote.TryGetContainingTitle(out containingTitle)) { string nodeName = m_scr.ContainingRefAsString(scrFootnote); TreeNode footnoteNode = new TreeNode(nodeName); footnoteNode.Tag = scrFootnote; footnoteNode.Name = "Footnote"; // see if we can lookup the node of this section. int nodeIndex = bookNode.Nodes.IndexOfKey( containingSection != null ? containingSection.ToString() : containingTitle.ToString()); //TreeNode[] sectionNodes = bookNode.Nodes.Find(hvoSection.ToString(), false); //if (sectionNodes != null && sectionNodes.Length > 0) if (nodeIndex >= 0) { bookNode.Nodes.Insert(nodeIndex + 1, footnoteNode); } else { bookNode.Nodes.Add(footnoteNode); // insert at end. } } } return(true); }