/// <summary> /// Clear all text. If fReconstruct is true, also clears the display. /// </summary> public void Clear(bool fReconstruct) { CheckDisposed(); if (m_sda == null) { var cda = VwCacheDaClass.Create(); cda.TsStrFactory = TsStringUtils.TsStrFactory; m_sda = cda; if (WritingSystemFactory != null) { m_sda.WritingSystemFactory = WritingSystemFactory; } m_cd = cda; } else { m_hvoNextPara = khvoFirstPara; m_cd.CacheVecProp(m_hvoRoot, (int)SampleTags.ktagTextParas, new int[0], 0); if (fReconstruct) { RootBox.Reconstruct(); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds paragraphs to the database /// </summary> /// <param name="ws"></param> /// <param name="firstPara"></param> /// <param name="secondPara"></param> /// ------------------------------------------------------------------------------------ private void AddParagraphs(int ws, string firstPara, string secondPara) { int hvoPara1 = m_hvoPara++; int hvoPara2 = m_hvoPara++; int hvoText1 = m_hvoText++; int hvoText2 = m_hvoText++; ITsStrFactory tsf = TsStrFactoryClass.Create(); ITsString tsString = tsf.MakeString(firstPara, ws); IVwCacheDa cda = Cache.VwCacheDaAccessor; cda.CacheStringProp(hvoPara1, (int)StTxtPara.StTxtParaTags.kflidContents, tsString); tsString = tsf.MakeString(secondPara, ws); cda.CacheStringProp(hvoPara2, (int)StTxtPara.StTxtParaTags.kflidContents, tsString); // Now make each of them the paragraphs of an StText. int[] hvoParas = { hvoPara1 }; cda.CacheVecProp(hvoText1, (int)StText.StTextTags.kflidParagraphs, hvoParas, 1); hvoParas[0] = hvoPara2; cda.CacheVecProp(hvoText2, (int)StText.StTextTags.kflidParagraphs, hvoParas, 1); // And the StTexts to the contents of a dummy property. AddVecProp(new int[] { hvoText1, hvoText2 }); }
/// <summary> /// Set up the referring semantic domains for the domains found of an entry /// </summary> /// <param name="semanticDomainHvos">an array of semantic domain HVOs</param> void SetupDomainsForEntry(int[] semanticDomainHvos) { m_cdaTemp.CacheVecProp(m_hvoEntry, RelatedWordsVc.ktagDomains, semanticDomainHvos, semanticDomainHvos.Length); var entries = new List <int>(); var semanticDomainRepository = m_cache.ServiceLocator.GetInstance <ICmSemanticDomainRepository>(); foreach (var semanticDomainhvo in semanticDomainHvos) { var semanticDomain = semanticDomainRepository.GetObject(semanticDomainhvo); foreach (ICmObject obj in semanticDomain.ReferringObjects) { if (obj is ILexSense && (obj as ILexSense).SemanticDomainsRC.Contains(semanticDomain)) { var entry = obj.OwnerOfClass(LexEntryTags.kClassId) as ILexEntry; if (entry != null && entry.LexemeFormOA != null && entry.LexemeFormOA.Form != null) { entries.Add(entry.Hvo); m_cdaTemp.CacheStringProp(entry.Hvo, RelatedWordsVc.ktagName, entry.LexemeFormOA.Form.VernacularDefaultWritingSystem); } } } if (entries.Count > 0) { m_cdaTemp.CacheVecProp(semanticDomainhvo, RelatedWordsVc.ktagWords, entries.ToArray(), entries.Count); entries.Clear(); } } }
/// <summary> /// Store the given hvos in the cache as a fake vector property belonging to the /// language project. /// </summary> /// <param name="rghvo"></param> private void StoreData(List <int> rghvo) { IVwCacheDa cda = m_cache.MainCacheAccessor as IVwCacheDa; cda.CacheVecProp(m_cache.LangProject.Hvo, m_flidFake, rghvo.ToArray(), rghvo.Count); }
void SetSeqRef(XmlNode elt) { int src = GetSource(elt); int flid = GetProp(src, elt); List <int> dst = new List <int>(); foreach (XmlNode child in elt.ChildNodes) { if (child is XmlComment) { continue; } dst.Add(GetDst(child)); } m_cda.CacheVecProp(src, flid, dst.ToArray(), dst.Count); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } if (disposing) { if (components != null) { components.Dispose(); } } if (m_cache != null) { IVwCacheDa cda = m_cache.MainCacheAccessor as IVwCacheDa; cda.CacheVecProp(m_cache.LangProject.Hvo, m_fakeFlid, null, 0); cda = null; m_cache = null; } m_fwTextBoxBottomMsg = null; m_mediator = null; if (m_tsf != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(m_tsf); } m_tsf = null; base.Dispose(disposing); }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry">int ID of the lexical entry</param> /// <param name="hvoSemanticDomainsOut">A list of int IDs of the semantic domains of the lexical entry</param> /// <param name="cdaTemp"></param> /// <returns></returns> static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] hvoSemanticDomainsOut, out IVwCacheDa cdaTemp) { // REVIEW (SteveMiller): The LINQ below runs slow the first time its run. We should try to // optimize it if possible. var entryRepo = cache.ServiceLocator.GetInstance <ILexEntryRepository>(); var lexEntry = entryRepo.GetObject(hvoEntry); var domains = (from sense in lexEntry.AllSenses from sd in sense.SemanticDomainsRC where (from incoming in sd.ReferringObjects where incoming is ILexSense && incoming.OwnerOfClass <ILexEntry>() != lexEntry select incoming).FirstOrDefault() != null select sd).Distinct().ToArray(); hvoSemanticDomainsOut = ( from sd in domains select sd.Hvo).ToArray(); cdaTemp = VwCacheDaClass.Create(); foreach (var sd in domains) { cdaTemp.CacheStringProp(sd.Hvo, RelatedWordsVc.ktagName, sd.Name.BestVernacularAnalysisAlternative); } cdaTemp.CacheVecProp(hvoEntry, RelatedWordsVc.ktagDomains, hvoSemanticDomainsOut, hvoSemanticDomainsOut.Length); return(hvoSemanticDomainsOut.Length > 0); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } if (disposing) { if (m_helpProvider != null) { m_helpProvider.Dispose(); } } if (m_cache != null) { IVwCacheDa cda = m_cache.MainCacheAccessor as IVwCacheDa; cda.CacheVecProp(m_cache.LangProject.Hvo, m_fakeFlid, null, 0); cda = null; m_cache = null; } m_ctxt = null; m_mediator = null; m_bvList = null; m_valuesCombo = null; base.Dispose(disposing); }
private void BuildInitialBrowseView(XCore.Mediator mediator) { XmlNode configurationParameters = (XmlNode)mediator.PropertyTable.GetValue("WindowConfiguration"); XmlNode toolNode = configurationParameters.SelectSingleNode( "controls/parameters/guicontrol[@id='PhonologicalFeaturesFlatList']/parameters"); m_listPanel.SuspendLayout(); m_fakeFlid = FdoCache.DummyFlid; IVwCacheDa cda = m_cache.MainCacheAccessor as IVwCacheDa; int[] featureHvos = m_cache.LangProject.PhFeatureSystemOA.FeaturesOC.HvoArray; cda.CacheVecProp(m_cache.LangProject.Hvo, m_fakeFlid, featureHvos, featureHvos.Length); m_bvList = new BrowseViewer(toolNode, m_cache.LangProject.Hvo, m_fakeFlid, m_cache, mediator, null); m_bvList.SelectionChanged += new FwSelectionChangedEventHandler(m_bvList_SelectionChanged); m_bvList.ScrollBar.ValueChanged += new EventHandler(ScrollBar_ValueChanged); m_bvList.Scroller.Scroll += new ScrollEventHandler(ScrollBar_Scroll); m_bvList.ColumnsChanged += new EventHandler(BrowseViewer_ColumnsChanged); m_bvList.Resize += new EventHandler(m_bvList_Resize); m_bvList.TabStop = true; m_bvList.StyleSheet = FontHeightAdjuster.StyleSheetFromMediator(mediator); m_bvList.Dock = DockStyle.Fill; m_bvList.BackColor = SystemColors.Window; m_listPanel.Controls.Add(m_bvList); m_listPanel.ResumeLayout(false); }
/// <summary> /// Add the specified type of freeform annotation to the given segment. /// Undoable by default. /// </summary> /// <param name="hvoSeg"></param> /// <param name="hvoType">freeform annotation type</param> /// <returns></returns> public ICmIndirectAnnotation AddFreeformAnnotation(int hvoSeg, int hvoType) { using (SuppressSubTasks suppressor = new SuppressSubTasks(m_fdoCache, true)) { // convert any preceeding dummy segments, so paragraph parser does not push this to the first dummy sentence. (LT-7318) int hvoPara = m_fdoCache.GetObjProperty(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject); StTxtPara para = StTxtPara.CreateFromDBObject(m_fdoCache, hvoPara) as StTxtPara; para.EnsurePreceedingSegmentsAreReal(hvoSeg); string undoString = ""; string redoString = ""; if (hvoType == ktagSegFF_freeTranslation) { undoString = ITextStrings.ksUndoAddFreeformTranslation; redoString = ITextStrings.ksRedoAddFreeformTranslation; } else if (hvoType == ktagSegFF_literalTranslation) { undoString = ITextStrings.ksUndoAddLiteralTranslation; redoString = ITextStrings.ksRedoAddLiteralTranslation; } else if (hvoType == ktagSegFF_note) { undoString = ITextStrings.ksUndoAddNote; redoString = ITextStrings.ksRedoAddNote; } else { throw new ArgumentException(String.Format("segment freeform type {0} is not yet supported here.", hvoType)); } ICmIndirectAnnotation ann; m_fdoCache.BeginUndoTask(undoString, redoString); { ann = CmIndirectAnnotation.CreateUnownedIndirectAnnotation(m_fdoCache); ann.AppliesToRS.Append(hvoSeg); ann.AnnotationTypeRAHvo = hvoType; // Add it to the cached collection of freeform annotations. This is a bit clumsy because // it isn't a real property so we can't just use the normal methods for modifying a property. // Enhance JohnT: put it with the other ones of the same type. ISilDataAccess sda = m_fdoCache.MainCacheAccessor; IVwCacheDa cda = (IVwCacheDa)sda; int cFreeForm = sda.get_VecSize(hvoSeg, ktagSegFF); int[] freeForms = new int[cFreeForm + 1]; for (int i = 0; i < cFreeForm; i++) { freeForms[i] = sda.get_VecItem(hvoSeg, ktagSegFF, i); } freeForms[cFreeForm] = ann.Hvo; cda.CacheVecProp(hvoSeg, ktagSegFF, freeForms, cFreeForm + 1); sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoSeg, ktagSegFF, cFreeForm, 1, 0); } m_fdoCache.EndUndoTask(); return(ann); } }
/// <summary> /// Loads segments for a paragraph (and dependent dummy annotations such as ) /// </summary> /// <param name="hvoWfi"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvoPara, int ktagParaSegments, int ws, IVwCacheDa cda) { // The parser will create and cache our segments (and dependent dummy annotations). LoadParagraphInfoToCache(hvoPara); if (m_cache.VwCacheDaAccessor != cda) { int[] segments = m_cache.GetVectorProperty(hvoPara, ktagParaSegments, true); cda.CacheVecProp(hvoPara, ktagParaSegments, segments, segments.Length); } }
/// <summary> /// The value of this property is the hvo of the owning object that is of class m_clid (or is a subclass of that). /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { ISilDataAccess sda = cda as ISilDataAccess; // Do we want the subentries? string sql = string.Format("SELECT Id FROM dbo.fnGetOwnedIds({0},{1},{2})", hvo, (int)ReversalIndex.ReversalIndexTags.kflidEntries, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidSubentries); int[] vals = DbOps.ReadIntArrayFromCommand(m_cache, sql, null); cda.CacheVecProp(hvo, tag, vals, vals.Length); }
public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { ISilDataAccess sda = cda as ISilDataAccess; int cobj = sda.get_VecSize(hvo, m_tagReal); using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(cobj + 1, typeof(int))) // one longer to leave room for dummy { sda.VecProp(hvo, m_tagReal, cobj, out cobj, arrayPtr); int [] rgHvo = (int[])MarshalEx.NativeToArray(arrayPtr, cobj, typeof(int)); rgHvo[cobj] = TypeAheadSupportVc.kBaseFakeObj; cda.CacheVecProp(hvo, tag, rgHvo, cobj + 1); } }
public void InstallVirtualHandler() { CheckDisposed(); StTextParaCountVh vh = new StTextParaCountVh(); ISilDataAccess sda = m_fdoCache.MainCacheAccessor; IVwCacheDa cda = sda as IVwCacheDa; vh.ClassName = "StText"; vh.FieldName = "ParagraphCount"; vh.Type = (int)CellarModuleDefns.kcptInteger; cda.InstallVirtual(vh); // Rather than try to find a real StText, simulate one. cda.CacheVecProp(khvoTest, (int)StText.StTextTags.kflidParagraphs, new int[] { 10, 20, 30, 40 }, 4); Assert.AreEqual(4, sda.get_IntProp(khvoTest, vh.Tag)); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } if (m_cache != null) { IVwCacheDa cda = m_cache.MainCacheAccessor as IVwCacheDa; cda.CacheVecProp(m_cache.LangProject.Hvo, m_flidFake, null, 0); cda = null; m_cache = null; } if (m_mediator != null) { m_mediator = null; } base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clears the specified cda. /// </summary> /// <param name="cda">The cda.</param> /// <param name="hvo">The HVO.</param> /// <param name="ws">The writing system</param> /// ------------------------------------------------------------------------------------ protected internal virtual void Clear(IVwCacheDa cda, int hvo, int ws) { switch (this.Type) { case (int)CellarModuleDefns.kcptReferenceSequence: cda.CacheVecProp(hvo, Tag, new int[0], 0); break; case (int)CellarModuleDefns.kcptTime: cda.CacheInt64Prop(hvo, Tag, 0); break; case (int)CellarModuleDefns.kcptReferenceAtom: cda.CacheObjProp(hvo, Tag, 0); break; default: Debug.Assert(false); break; } }
private void InitBrowseView(string guiControl, List <DummyCmObject> mergeCandidates) { XmlNode configurationParameters = (XmlNode)m_mediator.PropertyTable.GetValue("WindowConfiguration"); XmlNode toolNode = configurationParameters.SelectSingleNode("controls/parameters/guicontrol[@id='" + guiControl + "']/parameters"); m_fakeFlid = FdoCache.DummyFlid; IVwCacheDa cda = m_cache.MainCacheAccessor as IVwCacheDa; int[] hvos = new int[mergeCandidates.Count]; for (int i = 0; i < mergeCandidates.Count; i++) { hvos[i] = mergeCandidates[i].Hvo; m_candidates[mergeCandidates[i].Hvo] = mergeCandidates[i]; } cda.CacheVecProp(m_cache.LangProject.Hvo, m_fakeFlid, hvos, hvos.Length); m_bvMergeOptions = new BrowseViewer(toolNode, m_cache.LangProject.Hvo, m_fakeFlid, m_cache, m_mediator, null); m_bvMergeOptions.StyleSheet = SIL.FieldWorks.Common.Widgets.FontHeightAdjuster.StyleSheetFromMediator(m_mediator); m_bvMergeOptions.SelectedIndexChanged += new System.EventHandler(this.m_bvMergeOptions_SelectedIndexChanged); m_bvMergeOptions.Dock = DockStyle.Fill; m_bvPanel.Controls.Add(m_bvMergeOptions); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load filtered/sorted reference sequence for the given object and tag. /// </summary> /// <param name="hvoPropOwner">HVO of object on which the virtual property is to be created /// (e.g., for Consultant Notes, this should be the HVO of a ScrBookAnnotations object) /// </param> /// <param name="tag">The virtual tag of the filtered/sorted sequence (not a real flid /// in the DB)</param> /// <param name="ws">Not used</param> /// <param name="vwCacheDa">Cache thingy (not an FDO cache, but it better be the same /// one our FDO cache refers to or we're in trouble)</param> /// ------------------------------------------------------------------------------------ public override void Load(int hvoPropOwner, int tag, int ws, IVwCacheDa vwCacheDa) { // Get the records FdoVector <ICmObject> collAllItems = GetCollectionOfRecordsToFilter(hvoPropOwner); // Evaluate each item in the collection, and build the new filteredList List <int> filteredList = new List <int>(); // List of included real indexes List <int> filteredHvos = new List <int>(); // List of included HVOs for (int i = 0; i < collAllItems.HvoArray.Length; i++) { int hvoObj = collAllItems.HvoArray[i]; if (m_filter == null || m_filter.MatchesCriteria(hvoObj)) { filteredList.Add(i); filteredHvos.Add(hvoObj); } } int[] hvos = filteredHvos.ToArray(); vwCacheDa.CacheVecProp(hvoPropOwner, tag, hvos, hvos.Length); // remember that we have loaded the virtual property for this object m_filteredObjectsInCache[hvoPropOwner] = filteredList; }
/// <summary> /// Load data into the VwCacheDa. /// </summary> public void LoadData(string filename) { ITsStrFactory tsf = (ITsStrFactory) new FwKernelLib.TsStrFactoryClass(); IVwCacheDa cda = (IVwCacheDa)m_sda; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filename); XmlNode book = xmlDoc.SelectSingleNode("book"); int wsAnalysis = m_wsf.get_Engine("en").get_WritingSystem(); // In real life try to get a meaningful one. int wsVern = m_wsf.get_Engine("de").get_WritingSystem(); // Vernacular ws. m_vc.SourceWs = wsAnalysis; m_vc.DestWs = wsVern; MakeStringProp(khvoBook, book, "name", ViewSampleVc.ktagBookName, wsAnalysis, tsf, cda); ITsPropsBldr tpb = (ITsPropsBldr) new FwKernelLib.TsPropsBldrClass(); tpb.SetIntPropValues((int)FwKernelLib.FwTextPropType.ktptWs, (int)FwKernelLib.FwTextPropVar.ktpvDefault, wsAnalysis); tpb.SetStrPropValue((int)FwKernelLib.FwTextPropType.ktptNamedStyle, "verseNumber"); ITsTextProps ttpVStyle = tpb.GetTextProps(); int [] sectionIds = new int[book.ChildNodes.Count]; int isection = 0; foreach (XmlNode section in book.ChildNodes) { int sectionId = m_hvoNextSection++; sectionIds[isection] = sectionId; isection++; MakeStringProp(sectionId, section, "refs", ViewSampleVc.ktagSectionRefs, wsAnalysis, tsf, cda); MakeStringProp(sectionId, section, "title", ViewSampleVc.ktagSectionTitle, wsAnalysis, tsf, cda); int[] paraIds = new int[section.ChildNodes.Count]; int ipara = 0; foreach (XmlNode para in section.ChildNodes) { int paraId = m_hvoNextPara++; paraIds[ipara] = paraId; ipara++; // Construct paragraph contents string ITsStrBldr tsb = (ITsStrBldr) new FwKernelLib.TsStrBldrClass(); foreach (XmlNode item in para.ChildNodes) { int ichLim = tsb.get_Length(); if (item.Name == "v") { string num = GetAttrVal(item, "n"); tsb.Replace(ichLim, ichLim, num, ttpVStyle); } else if (item.Name == "s") { string wsName = GetAttrVal(item, "ws"); int ws = wsName == null ? wsAnalysis : m_wsf.get_Engine(wsName).get_WritingSystem(); tsb.ReplaceTsString(ichLim, ichLim, tsf.MakeString(item.InnerText, ws)); } } // Review: should we assume the default ws analysis? Represent a multistring in the file? // Remember the last ws we encountered in the string? This is just a sample... cda.CacheStringAlt(paraId, ViewSampleVc.ktagParaContents, wsAnalysis, tsb.GetString()); } cda.CacheVecProp(sectionId, ViewSampleVc.ktagSectionParas, paraIds, paraIds.Length); } cda.CacheVecProp(khvoBook, ViewSampleVc.ktagBookSections, sectionIds, sectionIds.Length); }
/// <summary> /// Load the data. /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { int hvoTwficType = CmAnnotationDefn.Twfic(m_cache).Hvo; string sql = string.Format("select min(wa.id), pos.id from " +"(select wa.id, wa.Category from WfiWordform wf " +"join WfiAnalysis_ wa on wa.owner$ = wf.id " +"join WfiGloss_ wg on wg.owner$ = wa.id " +"join CmBaseAnnotation_ cba on cba.InstanceOf = wg.id and cba.AnnotationType = {0} " +"where wf.id = {1} " +"union " +"select wa.id, wa.Category from WfiWordform wf " +"join WfiAnalysis_ wa on wa.owner$ = wf.id " +"join CmBaseAnnotation_ cba on cba.InstanceOf = wa.id and cba.AnnotationType = {0} " +"where wf.id = {1}) wa " +"join PartOfSpeech pos on wa.Category = pos.id " +"group by pos.id", hvoTwficType, hvo); int[] vals = DbOps.ReadIntArrayFromCommand(m_cache, sql, null); cda.CacheVecProp(hvo, tag, vals, vals.Length); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load filtered books for scripture - load all books if no filter in place. /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="_cda"></param> /// ------------------------------------------------------------------------------------ public override void Load(int hvo, int tag, int ws, IVwCacheDa _cda) { CheckFilteredBooks(false); _cda.CacheVecProp(hvo, tag, m_filteredBooks.ToArray(), m_filteredBooks.Count); //Debug.WriteLine(string.Format("Load hvo={0}, filter count={1}", hvo, m_filteredBooks.Count)); }
/// <summary> /// Load the data. /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { ISilDataAccess sda = cda as ISilDataAccess; List<int> pictures = new List<int>(); GetPictures(sda, hvo, (int)LexEntry.LexEntryTags.kflidSenses, pictures); int[] result = DbOps.ListToIntArray(pictures); cda.CacheVecProp(hvo, tag, result, result.Length); }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry">int ID of the lexical entry</param> /// <param name="hvoSemanticDomainsOut">A list of int IDs of the semantic domains of the lexical entry</param> /// <param name="cdaTemp"></param> /// <returns></returns> static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] hvoSemanticDomainsOut, out IVwCacheDa cdaTemp) { // REVIEW (SteveMiller): The LINQ below runs slow the first time its run. We should try to // optimize it if possible. var entryRepo = cache.ServiceLocator.GetInstance<ILexEntryRepository>(); var lexEntry = entryRepo.GetObject(hvoEntry); var domains = (from sense in lexEntry.AllSenses from sd in sense.SemanticDomainsRC where (from incoming in sd.ReferringObjects where incoming is ILexSense && incoming.OwnerOfClass<ILexEntry>() != lexEntry select incoming).FirstOrDefault() != null select sd).Distinct().ToArray(); hvoSemanticDomainsOut = ( from sd in domains select sd.Hvo).ToArray(); cdaTemp = VwCacheDaClass.Create(); foreach (var sd in domains) { cdaTemp.CacheStringProp(sd.Hvo, RelatedWordsVc.ktagName, sd.Name.BestVernacularAnalysisAlternative); } cdaTemp.CacheVecProp(hvoEntry, RelatedWordsVc.ktagDomains, hvoSemanticDomainsOut, hvoSemanticDomainsOut.Length); return hvoSemanticDomainsOut.Length > 0; }
public void VecProp() { // test VecProp using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(10)) { int chvo = 99; m_ISilDataAccess.VecProp(1001, 2001, 10, out chvo, arrayPtr); Assert.AreEqual(0, chvo); chvo = m_ISilDataAccess.get_VecSize(1001, 2001); Assert.AreEqual(0, chvo); int[] rgHvo = new int[] { 33, 44, 55 }; m_IVwCacheDa.CacheVecProp(1001, 2001, rgHvo, rgHvo.Length); m_ISilDataAccess.VecProp(1001, 2001, 10, out chvo, arrayPtr); int[] rgHvoNew = MarshalEx.NativeToArray <int>(arrayPtr, chvo); Assert.AreEqual(rgHvo.Length, rgHvoNew.Length); for (int i = 0; i < rgHvoNew.Length; i++) { Assert.AreEqual(rgHvo[i], rgHvoNew[i]); } int[] rgHvo2 = new int[] { 66, 77, 88, 99 }; m_IVwCacheDa.CacheVecProp(1001, 2001, rgHvo2, rgHvo2.Length); m_ISilDataAccess.VecProp(1001, 2001, 10, out chvo, arrayPtr); rgHvoNew = MarshalEx.NativeToArray <int>(arrayPtr, chvo); Assert.AreEqual(rgHvo2.Length, rgHvoNew.Length); for (int i = 0; i < rgHvoNew.Length; i++) { Assert.AreEqual(rgHvo2[i], rgHvoNew[i]); } Exception ex = null; try { m_ISilDataAccess.VecProp(1001, 2001, 2, out chvo, arrayPtr); } catch (Exception e) { ex = e; } Assert.IsNotNull(ex); Assert.AreEqual(typeof(ArgumentException), ex.GetType()); // test VecItem int hvo = m_ISilDataAccess.get_VecItem(1001, 2001, 2); Assert.AreEqual(88, hvo); ex = null; try { hvo = m_ISilDataAccess.get_VecItem(1001, 2001, 10); } catch (Exception e) { ex = e; } Assert.IsNotNull(ex); Assert.AreEqual(typeof(ArgumentException), ex.GetType()); // test Vector size chvo = m_ISilDataAccess.get_VecSize(1001, 2001); Assert.AreEqual(rgHvo2.Length, chvo); } }
/// <summary> /// Load all wordforms from ConcordanceTexts into cache. /// </summary> /// <param name="hvoWfi"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvoWfi, int ktagConcordanceWordforms, int ws, IVwCacheDa cda) { Debug.Assert(hvoWfi == m_cache.LangProject.WordformInventoryOAHvo); List<int> concTexts = new List<int>(m_cache.GetVectorProperty(m_cache.LangProject.Hvo, LangProject.InterlinearTextsFlid(Cache), false)); // initialize our ConcordanceWords property. cda.CacheVecProp(hvoWfi, ktagConcordanceWordforms, new int[0], 0); // load all the text structure annotations. ParagraphParser.ConcordTexts(m_cache, concTexts.ToArray(), Progress); Set<int> wordformsFromSession = new Set<int>(ParagraphParser.WordformsFromLastParseSession(m_cache).ToArray()); // get all real wordforms and add the ones that have no occurrences in a text. Set<int> wfiWordforms = new Set<int>(m_cache.LangProject.WordformInventoryOA.WordformsOC.HvoArray); Set<int> fullConcordanceWordList = wordformsFromSession.Union(wfiWordforms); //UnionOfLists(wordformsFromSession, wfiWordforms); Debug.Assert(m_cache.MainCacheAccessor.get_VecSize(hvoWfi, ktagConcordanceWordforms) == 0, "The parse session should not have already added to our ConconcordanceWordforms"); // reload into our vector property cda.CacheVecProp(hvoWfi, ktagConcordanceWordforms, fullConcordanceWordList.ToArray(), fullConcordanceWordList.Count); }
/// <summary> /// Loads occurrences of this word into the cache. /// </summary> /// <param name="hvoWfi"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvoWfiWordform, int ktagOccurrences, int ws, IVwCacheDa cda) { // JohnT: this test is quite expensive and distorts optimization efforts. //Debug.Assert(m_cache.IsValidObject(hvoWfiWordform), "looks like our object (" + hvoWfiWordform + ") got vaporized."); // just to be safe initialize the property if it doesn't exist yet. if (!m_cache.MainCacheAccessor.get_IsPropInCache(hvoWfiWordform, ktagOccurrences, this.Type, ws)) cda.CacheVecProp(hvoWfiWordform, ktagOccurrences, new int[0], 0); }
/// <summary> /// /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { // Don't try to load anything real from a dummy object. if (m_cache.IsDummyObject(hvo)) { cda.CacheVecProp(hvo, tag, new int[0], 0); return; } ICmObject w = CmObject.CreateFromDBObject(m_cache, hvo); cda.CacheObjProp( hvo, tag, (int)m_propertyInfo.GetValue(w, null)); }
/// <summary> /// Load the back references (to LexReference) for a target into the given IVwCacheDa. /// </summary> /// <param name="hvo">id of the object for which we want to find backreferences</param> /// <param name="tag">virtual flid</param> /// <param name="ws">presently not used.</param> /// <param name="cda">the cache into which to load the backreferences</param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { if (BaseVirtualHandler.ForceBulkLoadIfPossible && m_bulkValues == null) { SetLoadForAllOfClass(true); BaseVirtualHandler.m_rgvhBulkForced.Add(this); } List<int> refs = null; if (m_bulkValues != null) { if (!m_fBulkLoaded) { this.LoadAllLexReferences(m_bulkValues); m_fBulkLoaded = true; } ValidateTargetClass(hvo); if (!m_bulkValues.TryGetValue(hvo, out refs)) refs = new List<int>(); } else { refs = this.LexReferences(hvo); } cda.CacheVecProp(hvo, tag, refs.ToArray(), refs.Count); }
void SetupDomainsForEntry(int[] domains) { m_cdaTemp.CacheVecProp(m_hvoEntry, RelatedWordsVc.ktagDomains, domains, domains.Length); // This produces first the Semantic domains of the senses of the entry, // then uses a backreference to find all senses linked to those domains. // Todo JohnT: this finds only entries that directly own senses linked to the relevant domains. // It will not find entries that only have senses with subsenses in the domain. // This is because we're specifically looking for MoForms with the same owner as the senses we found. // We'd have to do something tricky and recursive to get owning entry of a subsense. string sql2 = string.Format("select lscd.dst, cmls.owner$, mff.txt from LexSense ls" + " join CmObject cols on ls.id = cols.id and cols.owner$ = {0}" + " join LexSense_SemanticDomains lscd on lscd.src = ls.id" + " join LexSense_SemanticDomains lscd2 on lscd2.dst = lscd.dst and lscd2.src != ls.id" + " join CmObject cmls on lscd2.src = cmls.id and cmls.owner$ != {0}" + " join MoForm_ mf on mf.owner$ = cmls.owner$ and mf.OwnFlid$ = {1}" + " join MoForm_Form mff on mff.obj = mf.id and mff.ws = {2}" + " group by lscd.dst, cmls.owner$, mff.txt" + " order by lscd.dst, mff.txt", m_hvoEntry, (int)LexEntry.LexEntryTags.kflidLexemeForm, m_cache.DefaultVernWs); IOleDbCommand odc = DbOps.MakeRowSet(m_cache, sql2, null); try { bool fMoreRows; List <int> words = new List <int>(); int hvoOldDomain = 0; // to trigger change of domain on first iteration for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows)) { int hvoNewDomain = DbOps.ReadInt(odc, 0); if (hvoNewDomain != hvoOldDomain) { if (hvoOldDomain != 0) { m_cdaTemp.CacheVecProp(hvoOldDomain, RelatedWordsVc.ktagWords, DbOps.ListToIntArray(words), words.Count); words.Clear(); } hvoOldDomain = hvoNewDomain; } int hvoWord = DbOps.ReadInt(odc, 1); // JohnT: if I was better at sql, I could no doubt figure out how to prevent // duplicates in the query above, which are caused by having two or more senses of the // same entry in the same domain. But it's easier to just eliminate them here (and maybe // even faster). if (!words.Contains(hvoWord)) { m_cdaTemp.CacheStringProp(hvoWord, RelatedWordsVc.ktagName, DbOps.ReadTss(odc, 2, m_cache.DefaultVernWs)); words.Add(hvoWord); } } if (hvoOldDomain != 0) { // Cache words of last domain. m_cdaTemp.CacheVecProp(hvoOldDomain, RelatedWordsVc.ktagWords, DbOps.ListToIntArray(words), words.Count); } int hvoLf = m_cache.MainCacheAccessor.get_ObjectProp(m_hvoEntry, (int)LexEntry.LexEntryTags.kflidLexemeForm); if (hvoLf != 0) { ITsString tssCf = m_cache.MainCacheAccessor.get_MultiStringAlt(hvoLf, (int)MoForm.MoFormTags.kflidForm, m_cache.DefaultVernWs); m_cdaTemp.CacheStringProp(m_hvoEntry, RelatedWordsVc.ktagCf, tssCf); } } finally { DbOps.ShutdownODC(ref odc); } }
/// <summary> /// Load the data. /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { #if USEORIGINALCODE string sql = m_sql1 + hvo + m_sql2; IVwOleDbDa odd = cda as IVwOleDbDa; if (odd == null) return; // nothing we can do. IDbColSpec dcs = DbColSpecClass.Create(); dcs.Push((int)DbColType.koctObjVec, 0, tag, 0); odd.Load(sql, dcs, hvo, 0, null, false); #else string sql = m_sql1 + "? " + m_sql2; List<int> hvos = DbOps.ReadIntsFromCommand(m_cache, sql, hvo); cda.CacheVecProp( hvo, tag, hvos.ToArray(), hvos.Count); #endif }
/// <summary> /// Load the data. /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { if (m_cache.IsDummyObject(hvo)) // lots of dummy wordforms, don't want to go here. { cda.CacheVecProp(hvo, tag, null, 0); return; } int hvoTwficType = CmAnnotationDefn.Twfic(m_cache).Hvo; string sql = string.Format("select distinct wa.Category from WfiAnalysis_ wa " + "where wa.Category is not null and wa.Owner$ = {1} and " + "exists (select id from CmBaseAnnotation_ cba where cba.InstanceOf = wa.id and cba.AnnotationType = {0} " + "union " + "select cba.id from CmBaseAnnotation_ cba " + "join WfiGloss_ wg on cba.InstanceOf = wg.id and wg.owner$ = wa.id and cba.AnnotationType = {0} ) ", hvoTwficType, hvo); int[] vals = DbOps.ReadIntArrayFromCommand(m_cache, sql, null); cda.CacheVecProp(hvo, tag, vals, vals.Length); }
/// <summary> /// subclasses that override Load(hvo, tag, ws, cda) really need to override /// this one, if they want to take advantage of returning the list. /// </summary> /// <param name="hvo"></param> /// <param name="ws"></param> /// <param name="tag"></param> /// <param name="cda"></param> /// <param name="hvos"></param> protected virtual void Load(int hvo, int tag, int ws, IVwCacheDa cda, out List<int> hvos) { if (BaseVirtualHandler.ForceBulkLoadIfPossible && m_bulkValues == null) { SetLoadForAllOfClass(true); BaseVirtualHandler.m_rgvhBulkForced.Add(this); } // Don't try to load anything real from a dummy object. // However, if ComputeEveryTime is set for dummy object // we'll assume that it's possible to load its data // from it's CmObject property. if (!ComputeEveryTime && m_cache.IsDummyObject(hvo)) { cda.CacheVecProp(hvo, tag, new int[0], 0); hvos = new List<int>(); return; } if (m_bulkMethodInfo != null && m_bulkValues != null) { if (!m_fBulkLoaded) { m_bulkMethodInfo.Invoke(null, new object[] { m_cache, m_bulkValues }); m_fBulkLoaded = true; } if (!m_bulkValues.TryGetValue(hvo, out hvos)) hvos = new List<int>(); } else { hvos = GetVectorItemsToCache(hvo); } cda.CacheVecProp( hvo, tag, hvos.ToArray(), hvos.Count); }
protected override void Load(int hvo, int tag, int ws, IVwCacheDa cda, out List<int> ids) { ids = GetListForCache(); if (ids == null) ids = new List<int>(); cda.CacheVecProp(hvo, tag, ids.ToArray(), ids.Count); if (PropertyTableList().Count > 0) m_fListHasPropertyTableIds = true; else m_fListHasPropertyTableIds = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load filtered/sorted reference sequence for the given object and tag. /// </summary> /// <param name="hvoPropOwner">HVO of object on which the virtual property is to be created /// (e.g., for Consultant Notes, this should be the HVO of a ScrBookAnnotations object) /// </param> /// <param name="tag">The virtual tag of the filtered/sorted sequence (not a real flid /// in the DB)</param> /// <param name="ws">Not used</param> /// <param name="vwCacheDa">Cache thingy (not an FDO cache, but it better be the same /// one our FDO cache refers to or we're in trouble)</param> /// ------------------------------------------------------------------------------------ public override void Load(int hvoPropOwner, int tag, int ws, IVwCacheDa vwCacheDa) { // Get the records FdoVector<ICmObject> collAllItems = GetCollectionOfRecordsToFilter(hvoPropOwner); // Evaluate each item in the collection, and build the new filteredList List<int> filteredList = new List<int>(); // List of included real indexes List<int> filteredHvos = new List<int>(); // List of included HVOs for (int i = 0; i < collAllItems.HvoArray.Length; i++) { int hvoObj = collAllItems.HvoArray[i]; if (m_filter == null || m_filter.MatchesCriteria(hvoObj)) { filteredList.Add(i); filteredHvos.Add(hvoObj); } } int[] hvos = filteredHvos.ToArray(); vwCacheDa.CacheVecProp(hvoPropOwner, tag, hvos, hvos.Length); // remember that we have loaded the virtual property for this object m_filteredObjectsInCache[hvoPropOwner] = filteredList; }