/// <summary> /// Add the item to the language database /// </summary> /// <param name="cache">FDO cache to use</param> public void AddToDataBase(FdoCache cache) { ILangProject lp = cache.LangProject; IMoMorphData md = lp.MorphologicalDataOA; IMoGlossSystem gs = md.GlossSystemOA; XmlNode parent = m_xmlNode.ParentNode; if (parent.Name != "item") { // is a top level item; find it or add it IMoGlossItem giFound = gs.FindEmbeddedItem(Term, Abbrev, false); if (giFound == null) { // not found, so add it gs.GlossesOC.Add(m_glossItem); } } else { // not at top level; get parent and add it to parent; // also create any missing items between this node and the top IMoGlossItem giParent = GetMyParentGlossItem(cache, parent); giParent.GlossItemsOS.Append(m_glossItem); } FillInGlossItemBasedOnXmlNode(m_glossItem, m_xmlNode, this); CreateFeatStructFrag(); }
/// <summary> /// Get parent MoGlossItem and fill in any missing items between the parent and the top level. /// </summary> /// <param name="cache"></param> /// <param name="node"></param> /// <returns>The MoGlossItem object which is or is to be the parent of this item.</returns> private IMoGlossItem GetMyParentGlossItem(FdoCache cache, XmlNode node) { ILangProject lp = cache.LangProject; IMoMorphData md = lp.MorphologicalDataOA; IMoGlossSystem gs = md.GlossSystemOA; System.Xml.XmlNode parent = node.ParentNode; #if NUnitDebug Console.WriteLine("gmpgi: working on " + XmlUtils.GetAttributeValue(node, "id")); #endif if (parent.Name != "item") { // is a top level item; find it or add it #if NUnitDebug Console.WriteLine("gmpgi: found top"); #endif MIoGlossItem giFound = gs.FindEmbeddedItem(XmlUtils.GetAttributeValue(node, "term"), XmlUtils.GetAttributeValue(node, "abbrev"), false); if (giFound == null) { // not found; so add it IMoGlossItem gi = new MoGlossItem(); gs.GlossesOC.Add(gi); FillInGlossItemBasedOnXmlNode(gi, node, this); #if NUnitDebug Console.WriteLine("gmpgi, found top, made new, returning ", gi.Name.AnalysisDefaultWritingSystem); #endif return(gi); } else { //found, so return it #if NUnitDebug Console.WriteLine("gmpgi, found top, exists, returning ", giFound.Name.AnalysisDefaultWritingSystem); #endif return(giFound); } } else { // not a top level item; get its parent and add it, if need be #if NUnitDebug Console.WriteLine("gmpgi: calling parent of " + XmlUtils.GetAttributeValue(node, "id")); #endif IMoGlossItem giParent = GetMyParentGlossItem(cache, parent); IMoGlossItem giFound = giParent.FindEmbeddedItem(XmlUtils.GetAttributeValue(node, "term"), XmlUtils.GetAttributeValue(node, "abbrev"), false); if (giFound == null) { // not there, add it #if NUnitDebug Console.WriteLine("gmpgi: adding a node"); #endif giFound = new MoGlossItem(); giParent.GlossItemsOS.Append(giFound); FillInGlossItemBasedOnXmlNode(giFound, node, this); } #if NUnitDebug Console.WriteLine("gmpgi, in middle, returning " + giFound.Name.AnalysisDefaultWritingSystem + " for node " + XmlUtils.GetAttributeValue(node, "id")); #endif return(giFound); } }