Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the key terms.
        /// </summary>
        /// <returns>Always <c>null</c>.</returns>
        /// ------------------------------------------------------------------------------------
        private object LoadKeyTerms()
        {
            // Pre-load all of the stuff we are going to display from the DB.
            //m_cache.LoadAllOfAnOwningVectorProp(
            //	(int)CmPossibility.CmPossibilityTags.kflidSubPossibilities, "ChkTerm");
            //m_cache.LoadAllOfMultiUnicode((int)CmPossibility.CmPossibilityTags.kflidName,
            //	"ChkTerm");
            //m_cache.LoadAllOfMultiUnicode((int)ChkTerm.ChkTermTags.kflidSeeAlso,
            //	"ChkTerm");
            //m_cache.LoadAllOfAnIntProp((int)ChkTerm.ChkTermTags.kflidTermId);
            // see if we have a book filter enabled
            //if (HasBookFilter())
            //{
            //m_cache.LoadAllOfAnOwningVectorProp(
            //	(int)ChkTerm.ChkTermTags.kflidOccurrences, "ChkRef");
            //m_cache.LoadAllOfAnIntProp((int)ChkRef.ChkRefTags.kflidRef);

            // Alternatively, we could use the sql query below to get all the
            // the relevant key term ids, but that makes it harder for unit testing.
            // /*
            //	select distinct (occ.Src) from ChkTerm_Occurrences occ
            //	join ChkRef cr on cr.id = occ.Dst
            //	where (cr.ref >= 41000000 and cr.ref < 42000000 or -- book filters
            //	cr.ref >= 39000000 and cr.ref < 40000000)
            // */
            //}
            try
            {
                // preload whatever we need, whenever we need to.
                // clear our chkTermsWithRefs list
                m_chkTermsWithRefs.Clear();
                m_cache.EnableBulkLoadingIfPossible(true);
                foreach (int hvo in m_keyTermsList.PossibilitiesOS.HvoArray)
                {
                    PopulateTreeNode(Nodes, hvo);
                }

                this.Sort();
            }
            finally
            {
                EndUpdate();
                m_cache.EnableBulkLoadingIfPossible(false);
            }


            if (Nodes.Count > 0)
            {
                SelectedNode = Nodes[0];
            }

            return(null);
        }
        /// <summary>
        /// Load ScrBooks into the scripture tree view.
        /// </summary>
        /// <param name="cache"></param>
        public void LoadBooks(FdoCache cache)
        {
            if (cache.LangProject.TranslatedScriptureOA == null)
            {
                return;
            }
            try
            {
                cache.EnableBulkLoadingIfPossible(true);
                List <TreeNode> otBooks = new List <TreeNode>();
                List <TreeNode> ntBooks = new List <TreeNode>();
                foreach (IScrBook book in cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS)
                {
                    TreeNode node = new TreeNode((book.BookIdRA as ScrBookRef).UIBookName);
                    node.Tag  = book.Hvo;
                    node.Name = "Book";                         // help us query for books.
                    if (book.CanonicalNum < Scripture.kiNtMin)
                    {
                        otBooks.Add(node);
                    }
                    else
                    {
                        ntBooks.Add(node);
                    }
                }

                TreeNode bibleNode = new TreeNode(ScrControls.kstidBibleNode);
                if (otBooks.Count > 0)
                {
                    TreeNode testamentNode = new TreeNode(ScrControls.kstidOtNode,
                                                          otBooks.ToArray());
                    testamentNode.Name = "Testament";                     // help us query for Testaments
                    bibleNode.Nodes.Add(testamentNode);
                }

                if (ntBooks.Count > 0)
                {
                    TreeNode testamentNode = new TreeNode(ScrControls.kstidNtNode,
                                                          ntBooks.ToArray());
                    testamentNode.Name = "Testament";                     // help us query for Testaments
                    bibleNode.Nodes.Add(testamentNode);
                }

                this.Nodes.Add(bibleNode);
            }
            finally
            {
                cache.EnableBulkLoadingIfPossible(false);
            }
        }
Example #3
0
        public void TestFlexChorusMethods()
        {
            int    cOrigEntries = m_cache.LangProject.LexDbOA.EntriesOC.Count;
            string sLiftFile    = Path.GetTempFileName();

            m_cache.EnableBulkLoadingIfPossible(true);
            TestFlexChorusDlg dlg        = new TestFlexChorusDlg(m_cache);
            TestProgress      prog       = new TestProgress();
            string            sLiftFile2 = dlg.Export(sLiftFile, prog);

            Assert.AreEqual(sLiftFile2, sLiftFile);
            string sLiftFile3 = dlg.Merge(sLiftFile2, prog);

            Assert.IsNotNull(sLiftFile3);
            Assert.AreNotEqual(sLiftFile3, sLiftFile);
            string sLogFile = dlg.Import(sLiftFile3, prog);

            Assert.AreEqual(m_cache.LangProject.LexDbOA.EntriesOC.Count, cOrigEntries - 1);
            CheckDeletedEntries();
            CheckModifiedEntry();
            CheckCreatedEntry();
            Assert.IsNotNull(sLogFile);

            // Clean up the temp directory and other debris.
            File.Delete(sLiftFile);
            File.Delete(Path.ChangeExtension(sLiftFile, ".lift-ranges"));               // if it exists...
            File.Delete(sLiftFile3);
            File.Delete(sLogFile);
        }
Example #4
0
        public void Setup()
        {
            string sBackupFile = UnzipBackup();

            RestoreDbBackup(sBackupFile, "FlexChorusTest");
            // now, create the data cache for the test project.
            Dictionary <string, string> cacheOptions = new Dictionary <string, string>();

            cacheOptions.Add("c", MiscUtils.LocalServerName);
            cacheOptions.Add("db", "FlexChorusTest");
            m_cache = FdoCache.Create(cacheOptions);
            Debug.Assert(m_cache != null);
            m_cache.EnableBulkLoadingIfPossible(true);
            InstallVirtuals(@"Language Explorer\Configuration\Main.xml",
                            new string[] { "SIL.FieldWorks.FDO.", "SIL.FieldWorks.IText." });
        }
        /// <summary>
        /// Load sections into the books of a scripture tree view optionally including the
        /// heading as well as the content of each section.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="fIncludeHeadings"></param>
        public void LoadSections(FdoCache cache, bool fIncludeHeadings)
        {
            try
            {
                cache.EnableBulkLoadingIfPossible(true);
                // first load the book ids.
                this.Nodes.Clear();
                this.LoadBooks(cache);

                TreeNode bibleNode;
                if (this.Nodes.Count == 1)
                {
                    bibleNode = this.Nodes[0];
                }
                else if (this.Nodes.Count > 0)
                {
                    throw new ArgumentException("We should only have 1 Bible node, not " + this.Nodes.Count);
                }
                else
                {
                    return;
                }
                if (cache.LangProject.TranslatedScriptureOA == null)
                {
                    return;
                }

                Scripture scripture = cache.LangProject.TranslatedScriptureOA as Scripture;
                foreach (TreeNode testament in bibleNode.Nodes)
                {
                    foreach (TreeNode bookNode in testament.Nodes)
                    {
                        IScrBook book = ScrBook.CreateFromDBObject(cache, (int)bookNode.Tag) as IScrBook;
                        // Add Title node.
                        if (book.TitleOAHvo != 0)
                        {
                            TreeNode titleNode =
                                new TreeNode(ResourceHelper.GetResourceString("kstidScriptureTitle"));
                            titleNode.Name = book.TitleOAHvo.ToString();
                            titleNode.Tag  = book.TitleOAHvo;
                            bookNode.Nodes.Add(titleNode);
                        }

                        // Add Sections.
                        foreach (IScrSection section in book.SectionsOS)
                        {
                            string chapterVerseBridge = scripture.ChapterVerseBridgeAsString(section);
                            if (fIncludeHeadings && section.HeadingOAHvo != 0)
                            {
                                // Include the heading text if it's not empty.  See LT-8764.
                                int cTotal = 0;
                                foreach (IStTxtPara 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.Hvo.ToString());
                                    node.Tag  = section.HeadingOAHvo;                                           // expect an StText
                                    bookNode.Nodes.Add(node);
                                }
                            }
                            TreeNode sectionNode =
                                new TreeNode(chapterVerseBridge);
                            sectionNode.Name = section.Hvo.ToString();
                            sectionNode.Tag  = section.ContentOAHvo;                            // expect an StText
                            bookNode.Nodes.Add(sectionNode);
                        }

                        // Add Footnotes in reverse order, so we can insert them in the proper order.
                        List <IStFootnote> footnotes = new List <IStFootnote>(book.FootnotesOS);
                        footnotes.Reverse();
                        foreach (IStFootnote footnote in footnotes)
                        {
                            ScrFootnote scrFootnote = footnote as ScrFootnote;
                            if (scrFootnote == null)
                            {
                                scrFootnote = new ScrFootnote(cache, footnote.Hvo);
                            }
                            //  insert under the relevant section, if any (LTB-408)
                            int hvoContainingObj;
                            if (scrFootnote.TryGetContainingSectionHvo(out hvoContainingObj) ||
                                scrFootnote.TryGetContainingTitle(out hvoContainingObj))
                            {
                                string   nodeName     = scripture.ContainingRefAsString(scrFootnote);
                                TreeNode footnoteNode = new TreeNode(nodeName);
                                footnoteNode.Tag  = footnote.Hvo;
                                footnoteNode.Name = "Footnote";

                                // see if we can lookup the node of this section.
                                int nodeIndex = bookNode.Nodes.IndexOfKey(hvoContainingObj.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.
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                cache.EnableBulkLoadingIfPossible(false);
            }
        }