/// ------------------------------------------------------------------------------------ /// <summary> /// Helper function. Creates a set of saved versions in the database for testing. /// </summary> /// ------------------------------------------------------------------------------------ private void CreateSavedVersions() { IScrRefSystem refSys = m_cache.ScriptureReferenceSystem; // delete all of the existing archives in the database, so we can start clean while (m_scr.ArchivedDraftsOC.Count > 0) { m_scr.ArchivedDraftsOC.Remove(m_scr.ArchivedDraftsOC.HvoArray[0]); } // create three archives for the tests from TestLangProj for (int i = 0; i < m_scr.ScriptureBooksOS.Count; i++) { // make an archive //ScrDraft archive = new ScrDraft(); //m_scr.ArchivedDraftsOC.Add(archive); //archive.Description = "My Archive " + i; List <int> booksToAdd = new List <int>(i); // put "i" books in this archive - one in the first, two in the second, etc for (int iBook = 0; iBook <= i; iBook++) { booksToAdd.Add(m_scr.ScriptureBooksOS[iBook].Hvo); } AddArchive("My Archive " + i, booksToAdd); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="BookPropertiesDialog"/> class. /// </summary> /// <param name="book">the current book</param> /// <param name="stylesheet">The stylesheet.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ public BookPropertiesDialog(IScrBook book, IVwStylesheet stylesheet, IHelpTopicProvider helpTopicProvider) { m_currentBook = book; m_helpTopicProvider = helpTopicProvider; // TE-5663: make sure the book's name and abbreviation are updated if some were added IScrRefSystem scrRefSystem = book.Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().AllInstances().FirstOrDefault(); book.Name.MergeAlternatives(scrRefSystem.BooksOS[book.CanonicalNum - 1].BookName); book.Abbrev.MergeAlternatives(scrRefSystem.BooksOS[book.CanonicalNum - 1].BookAbbrev); // // Required for Windows Form Designer support // InitializeComponent(); // Put the book name in the dialog caption Text = string.Format(Text, book.Name.UserDefaultWritingSystem.Text); m_listBookInfo.Cache = book.Cache; m_listBookInfo.FieldsToDisplay.Add(new FwMultilingualPropView.ColumnInfo( ScrBookTags.kflidName, TeResourceHelper.GetResourceString("kstidBookNameColHeader"), 60)); m_listBookInfo.FieldsToDisplay.Add(new FwMultilingualPropView.ColumnInfo( ScrBookTags.kflidAbbrev, TeResourceHelper.GetResourceString("kstidBookAbbrevColHeader"), 40)); m_listBookInfo.RootObject = book.Hvo; foreach (IWritingSystem ws in book.Cache.ServiceLocator.WritingSystems.AllWritingSystems) { m_listBookInfo.WritingSystemsToDisplay.Add(ws.Handle); } // Initialize the ID textbox. m_txtScrBookIdText.Text = m_currentBook.IdText; }
/// ------------------------------------------------------------------------------------- /// <summary> /// Create publications and header/footer sets (in the DB) from the given XML document. /// </summary> /// <remarks>tests are able to call this method</remarks> /// <param name="progressDlg">Progress dialog</param> /// <param name="rootNode">The XmlNode from which to read the publication info</param> /// ------------------------------------------------------------------------------------- protected void SetNamesAndAbbreviations(IProgress progressDlg, XmlNode rootNode) { IScrRefSystem srs = m_cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton; Debug.Assert(srs != null && srs.BooksOS.Count == BCVRef.LastBook); XmlNodeList tagList = rootNode.SelectNodes("/ScrBookRef/writingsystem"); progressDlg.Minimum = 0; progressDlg.Maximum = tagList.Count * BCVRef.LastBook; progressDlg.Position = 0; progressDlg.Title = TeResourceHelper.GetResourceString("kstidCreatingBookNames"); ITsStrFactory tsf = m_cache.TsStrFactory; IWritingSystem ws; foreach (XmlNode writingSystem in tagList) { XmlAttributeCollection attributes = writingSystem.Attributes; string sWsTag = attributes.GetNamedItem("xml:lang").Value; m_cache.ServiceLocator.WritingSystemManager.GetOrSet(sWsTag, out ws); XmlNodeList WSBooks = writingSystem.SelectNodes("book"); foreach (XmlNode book in WSBooks) { XmlAttributeCollection bookAttributes = book.Attributes; string sSilBookId = bookAttributes.GetNamedItem("SILBookId").Value; Debug.Assert(sSilBookId != null); int nCanonicalBookNum = BCVRef.BookToNumber(sSilBookId); string sName = bookAttributes.GetNamedItem("Name").Value; string sAbbrev = bookAttributes.GetNamedItem("Abbreviation").Value; string sAltName = bookAttributes.GetNamedItem("AlternateName").Value; progressDlg.Message = string.Format( TeResourceHelper.GetResourceString("kstidCreatingBookNamesStatusMsg"), sName); progressDlg.Step(0); // check for the book id IScrBookRef bookRef = srs.BooksOS[nCanonicalBookNum - 1]; int wsHandle = ws.Handle; if (sName != null) { bookRef.BookName.set_String(wsHandle, tsf.MakeString(sName, wsHandle)); } if (sAbbrev != null) { bookRef.BookAbbrev.set_String(wsHandle, tsf.MakeString(sAbbrev, wsHandle)); } if (sAltName != null) { bookRef.BookNameAlt.set_String(wsHandle, tsf.MakeString(sAltName, wsHandle)); } } } // Finally, update resource version in database. SetNewResourceVersion(GetVersion(rootNode)); }
public void Insert_UnownableObject() { IFdoServiceLocator servLoc = Cache.ServiceLocator; IScrBookFactory bookFact = servLoc.GetInstance <IScrBookFactory>(); // Setup the source sequence using the scripture books sequence. IStText text; IScrBook book0 = bookFact.Create(1, out text); IStTxtPara para = text.AddNewTextPara(ScrStyleNames.MainBookTitle); IScrRefSystem systemToAdd = servLoc.GetInstance <IScrRefSystemRepository>().Singleton; para.AnalyzedTextObjectsOS.Insert(0, systemToAdd); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the book properties on the current ScrBook and ScrBookRef. /// </summary> /// ------------------------------------------------------------------------------------ protected void UpdateBookProperties() { // Save book names and abbreviations to the current ScrBook m_listBookInfo.SaveMultiLingualStrings(); // All new settings in the book should now be written to the ScrBookRef m_currentBook.BookIdRA.BookName.CopyAlternatives(m_currentBook.Name); m_currentBook.BookIdRA.BookAbbrev.CopyAlternatives(m_currentBook.Abbrev); IScrRefSystem scrRefSystem = m_currentBook.Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().AllInstances().FirstOrDefault(); IScrBookRef scrBookRef = scrRefSystem.BooksOS[m_currentBook.CanonicalNum - 1]; scrBookRef.BookName.CopyAlternatives(m_currentBook.Name); scrBookRef.BookAbbrev.CopyAlternatives(m_currentBook.Abbrev); }
public void Insert_UnownableObject() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBookFactory bookFact = servLoc.GetInstance <IScrBookFactory>(); // Setup the source sequence using the scripture books sequence. IStText text; bookFact.Create(1, out text); IStTxtPara para = text.AddNewTextPara(ScrStyleNames.MainBookTitle); IScrRefSystem systemToAdd = servLoc.GetInstance <IScrRefSystemRepository>().Singleton; Assert.That(() => para.AnalyzedTextObjectsOS.Insert(0, systemToAdd), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("ScrRefSystem can not be owned!")); }
public void SetBookNameAbbrev() { m_phm = m_scr.ScriptureBooksOS[0]; IScrRefSystem scrRefSystem = Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().AllInstances().FirstOrDefault(); m_phmBkRef = scrRefSystem.BooksOS[m_phm.CanonicalNum - 1]; // Set up the analysis writing system in ScrBook and the analysis writing system in ScrBookRef. m_phm.Name.set_String(Cache.DefaultVernWs, string.Empty); m_phm.Name.set_String(Cache.DefaultAnalWs, "Foilemon"); m_phm.Abbrev.set_String(Cache.DefaultAnalWs, "Foil"); m_phmBkRef.BookName.set_String(Cache.DefaultVernWs, "Filemon"); m_phmBkRef.BookAbbrev.set_String(Cache.DefaultVernWs, "Fil"); // Updating the name and abbreviation with the Book Properties dialog should set the // information from the ScrRefSystem in both ScrBook and ScrBookRef. using (DummyBookPropertiesDlg dlg = new DummyBookPropertiesDlg(m_phm, m_stylesheet)) { dlg.Show(); dlg.CallUpdateBookProperties(); // We expect that the ScrBook and ScrBookRef will be set to the same values. // The BookPropertiesDialog should get the settings from the ScrBook, and if they are // not set there (as is the case with the vernacular), look in ScrBookRef. Assert.AreEqual("Filemon", m_phm.Name.VernacularDefaultWritingSystem.Text); Assert.AreEqual("Filemon", m_phmBkRef.BookName.VernacularDefaultWritingSystem.Text); Assert.AreEqual("Fil", m_phm.Abbrev.VernacularDefaultWritingSystem.Text); Assert.AreEqual("Fil", m_phmBkRef.BookAbbrev.VernacularDefaultWritingSystem.Text); Assert.AreEqual("Foilemon", m_phm.Name.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("Foilemon", m_phmBkRef.BookName.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("Foil", m_phm.Abbrev.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("Foil", m_phmBkRef.BookAbbrev.AnalysisDefaultWritingSystem.Text); dlg.Close(); } //dlg.Dispose(); }
public void CreateScrBookRefs() { CheckDisposed(); IScrRefSystem scr = Cache.ScriptureReferenceSystem; m_scrInitializer.CallCreateScrBookRefs(Cache); FdoOwningSequence <IScrBookRef> books = scr.BooksOS; // Make sure the right number of books was generated. Assert.AreEqual(66, books.Count); ILgWritingSystemFactory wsf = Cache.LanguageWritingSystemFactoryAccessor; int wsEnglish = wsf.GetWsFromStr("en"); int wsSpanish = wsf.GetWsFromStr("es"); // Check English Genesis IScrBookRef genesis = books[0]; Assert.AreEqual("Genesis", genesis.BookName.GetAlternative(wsEnglish)); Assert.AreEqual("Gen", genesis.BookAbbrev.GetAlternative(wsEnglish)); Assert.IsNull(genesis.BookNameAlt.GetAlternative(wsEnglish)); // Check Spanish Matthew IScrBookRef mateo = books[39]; Assert.AreEqual("Mateo", mateo.BookName.GetAlternative(wsSpanish)); Assert.AreEqual("Mt", mateo.BookAbbrev.GetAlternative(wsSpanish)); Assert.IsNull(mateo.BookNameAlt.GetAlternative(wsSpanish)); // Check English 2 Corinthians IScrBookRef iiCor = books[46]; Assert.AreEqual("2 Corinthians", iiCor.BookName.GetAlternative(wsEnglish)); Assert.AreEqual("2Cor", iiCor.BookAbbrev.GetAlternative(wsEnglish)); Assert.AreEqual("II Corinthians", iiCor.BookNameAlt.GetAlternative(wsEnglish)); // Check Spanish Revelation IScrBookRef apocalipsis = books[65]; Assert.AreEqual("Apocalipsis", apocalipsis.BookName.GetAlternative(wsSpanish)); Assert.AreEqual("Ap", apocalipsis.BookAbbrev.GetAlternative(wsSpanish)); Assert.IsNull(apocalipsis.BookNameAlt.GetAlternative(wsSpanish)); MultilingScrBooks mlsb = new MultilingScrBooks(m_scr); mlsb.InitializeWritingSystems(Cache.LanguageWritingSystemFactoryAccessor); foreach (IScrBookRef brf in books) { string sBookName = brf.BookName.GetAlternative(wsEnglish); Assert.IsTrue(sBookName != null && sBookName != string.Empty); string sBookAbbrev = brf.BookAbbrev.GetAlternative(wsEnglish); Assert.IsTrue(sBookAbbrev != null && sBookAbbrev != string.Empty); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the scripture reference system /// </summary> /// <param name="srs"></param> /// ------------------------------------------------------------------------------------ public void SetScriptureReferenceSystem(IScrRefSystem srs) { CheckDisposed(); m_srs = srs; }
/// ------------------------------------------------------------------------------------- /// <summary> /// Create all of the ScrBookRef objects for each book of Scripture /// </summary> /// <param name="progressDlg">Progress dialog so the user can cancel</param> /// ------------------------------------------------------------------------------------- protected void CreateScrBookRefs(IAdvInd4 progressDlg) { IScrRefSystem scr = m_cache.ScriptureReferenceSystem; // If there are books existing, then delete them first. for (int i = scr.BooksOS.Count - 1; i >= 0; i--) { scr.BooksOS.RemoveAt(i); } XmlDocument doc = new XmlDocument(); doc.Load(DirectoryFinder.FWCodeDirectory + @"\Translation Editor\ScrBookRef.xml"); ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor; //Select and display the value of all the ISBN attributes. XmlNodeList tagList = doc.SelectNodes("/ScrBookRef/writingsystem"); progressDlg.SetRange(0, tagList.Count * ScrReference.LastBook); progressDlg.Position = 0; progressDlg.Title = TeResourceHelper.GetResourceString("kstidCreatingBookNames"); foreach (XmlNode writingSystem in tagList) { XmlAttributeCollection attributes = writingSystem.Attributes; string sLocale = attributes.GetNamedItem("iculocale").Value; int ws = m_cache.LanguageEncodings.GetWsFromIcuLocale(sLocale); if (ws == 0) { // It is possible that the XML file contains more languages than the // database. If so, just ignore this writing system. continue; } short iBook = 0; XmlNodeList WSBooks = writingSystem.SelectNodes("book"); foreach (XmlNode book in WSBooks) { XmlAttributeCollection bookAttributes = book.Attributes; string sSilBookId = bookAttributes.GetNamedItem("SILBookId").Value; Debug.Assert(sSilBookId != null); // Make sure books are coming in canonical order. Debug.Assert(ScrReference.BookToNumber(sSilBookId) == iBook + 1); string sName = bookAttributes.GetNamedItem("Name").Value; string sAbbrev = bookAttributes.GetNamedItem("Abbreviation").Value; string sAltName = bookAttributes.GetNamedItem("AlternateName").Value; progressDlg.Message = string.Format( TeResourceHelper.GetResourceString("kstidCreatingBookNamesStatusMsg"), sName); progressDlg.Step(0); // check for the book id ScrBookRef bookRef = null; if (scr.BooksOS.Count > iBook) { bookRef = (ScrBookRef)scr.BooksOS[iBook]; Debug.Assert(bookRef != null); } else { // add this book to the list bookRef = new ScrBookRef(); scr.BooksOS.Append(bookRef); } if (sName != null) { bookRef.BookName.SetAlternative(sName, ws); } if (sAbbrev != null) { bookRef.BookAbbrev.SetAlternative(sAbbrev, ws); } if (sAltName != null) { bookRef.BookNameAlt.SetAlternative(sAltName, ws); } iBook++; } } }