public void MultiStringAlt() { ITsString tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7); Assert.IsNotNull(tsStringNew); Assert.AreEqual(0, tsStringNew.Length); ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr(); ITsStrBldr strBldr = TsStringUtils.MakeStrBldr(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse"); strBldr.Replace(0, 0, "Test", propsBldr.GetTextProps()); ITsString tsString = strBldr.GetString(); m_IVwCacheDa.CacheStringAlt(1117, 2227, 7, tsString); tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7); Assert.AreEqual(tsString, tsStringNew); strBldr.Replace(0, 0, "SecondTest", propsBldr.GetTextProps()); tsString = strBldr.GetString(); m_IVwCacheDa.CacheStringAlt(1117, 2227, 7, tsString); tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7); Assert.AreEqual(tsString, tsStringNew); tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 8); Assert.IsNotNull(tsStringNew); Assert.AreEqual(0, tsStringNew.Length); }
public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { // Value is always an empty string in the specified writing system. ITsStrFactory tsf = TsStrFactoryClass.Create(); ITsString tssEmpty = tsf.MakeString("", m_ws); if (ws == 0) { cda.CacheStringProp(hvo, tag, tssEmpty); } else { cda.CacheStringAlt(hvo, tag, ws, tssEmpty); } }
public void MultiStringVirtualHandler() { CheckDisposed(); MultiStringVirtualHandler msvh = new MultiStringVirtualHandler("LexDb", "NewString"); m_fdoCache.InstallVirtualProperty(msvh); Assert.IsTrue(msvh.Writeable); Assert.AreEqual((int)CellarModuleDefns.kcptMultiString, msvh.Type); Assert.IsFalse(msvh.ComputeEveryTime); int hvoLexDb = 0; if (m_fdoCache.LangProject != null && m_fdoCache.LangProject.LexDbOA != null) { hvoLexDb = m_fdoCache.LangProject.LexDbOA.Hvo; } if (hvoLexDb == 0) { // Rather than try to create a real LexDb, simulate one. hvoLexDb = khvoTest; } ISilDataAccess sda = m_fdoCache.MainCacheAccessor; IVwCacheDa cda = sda as IVwCacheDa; int wsVern = m_fdoCache.LangProject.DefaultVernacularWritingSystem; msvh.Load(hvoLexDb, msvh.Tag, wsVern, cda); ITsStrFactory tsf = TsStrFactoryClass.Create(); ITsString tss = tsf.MakeString("", wsVern); ITsString tss1 = sda.get_MultiStringAlt(hvoLexDb, msvh.Tag, wsVern); Assert.IsTrue(tss.Equals(tss1)); Assert.IsTrue(msvh.Writeable); tss = tsf.MakeString("This is a test", wsVern); msvh.WriteObj(hvoLexDb, msvh.Tag, wsVern, tss, sda); cda.CacheStringAlt(hvoLexDb, msvh.Tag, wsVern, tss); tss1 = sda.get_MultiStringAlt(hvoLexDb, msvh.Tag, wsVern); Assert.IsTrue(tss.Equals(tss1)); }
public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { // Value is always an empty string in the specified writing system. ITsStrFactory tsf = TsStrFactoryClass.Create(); ITsString tssEmpty = tsf.MakeString("", m_ws); if (ws == 0) cda.CacheStringProp(hvo, tag, tssEmpty); else cda.CacheStringAlt(hvo, tag, ws, tssEmpty); }
private void LoadSecDataForEntry(ILexEntry entryReal, ILexSense senseReal, int hvoSbWord, IVwCacheDa cda, int wsVern, int hvoMbSec, int fGuessing, ISilDataAccess sdaMain, ITsStrFactory tsf) { int hvoEntry = m_caches.FindOrCreateSec(entryReal.Hvo, kclsidSbNamedObj, hvoSbWord, ktagSbWordDummy); // try to determine if the given entry is a variant of the sense we passed in (ie. not an owner) ILexEntryRef ler = null; int hvoEntryToDisplay = entryReal.Hvo; if (senseReal != null) { if ((entryReal as ILexEntry).IsVariantOfSenseOrOwnerEntry(senseReal, out ler)) hvoEntryToDisplay = senseReal.EntryID; } ITsString tssLexEntry = LexEntryVc.GetLexEntryTss(Cache, hvoEntryToDisplay, wsVern, ler); cda.CacheStringAlt(hvoEntry, ktagSbNamedObjName, wsVern, tssLexEntry); cda.CacheObjProp(hvoMbSec, ktagSbMorphEntry, hvoEntry); cda.CacheIntProp(hvoEntry, ktagSbNamedObjGuess, fGuessing); List<int> writingSystems = m_choices.OtherWritingSystemsForFlid(InterlinLineChoices.kflidLexEntries, 0); if (writingSystems.Count > 0) { // Sigh. We're trying for some reason to display other alternatives of the entry. int hvoLf = sdaMain.get_ObjectProp(hvoEntryToDisplay, LexEntryTags.kflidLexemeForm); if (hvoLf != 0) CopyStringsToSecondary(writingSystems, sdaMain, hvoLf, MoFormTags.kflidForm, cda, hvoEntry, ktagSbNamedObjName, tsf); else CopyStringsToSecondary(writingSystems, sdaMain, hvoEntryToDisplay, LexEntryTags.kflidCitationForm, cda, hvoEntry, ktagSbNamedObjName, tsf); } }
private static void CacheStringAltForAllCurrentWs(IEnumerable<int> currentWsList, IVwCacheDa cda, int hvoSec, int flidSec, Func<int, ITsString> createStringAlt) { foreach (int ws1 in currentWsList) { ITsString tssMain = null; if (createStringAlt != null) tssMain = createStringAlt(ws1); if (tssMain == null) tssMain = TsStringUtils.MakeTss("", ws1); cda.CacheStringAlt(hvoSec, flidSec, ws1, tssMain); } }
private void CopyStringsToSecondary(IList<int> writingSystems, ISilDataAccess sdaMain, int hvoMain, int flidMain, IVwCacheDa cda, int hvoSec, int flidSec, ITsStrFactory tsf) { CheckDisposed(); foreach (int ws in writingSystems) { int wsActual = 0; ITsString tss; if (ws > 0) { wsActual = ws; } else if (ws == WritingSystemServices.kwsFirstAnal) { IList<int> currentAnalysisWsList = m_caches.MainCache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Select(wsObj => wsObj.Handle).ToArray(); CacheStringAltForAllCurrentWs(currentAnalysisWsList, cda, hvoSec, flidSec, sdaMain, hvoMain, flidMain); continue; } else if (ws == WritingSystemServices.kwsFirstVern) { IList<int> currentVernWsList = m_caches.MainCache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Select(wsObj => wsObj.Handle).ToArray(); CacheStringAltForAllCurrentWs(currentVernWsList, cda, hvoSec, flidSec, sdaMain, hvoMain, flidMain); continue; } else if (ws == WritingSystemServices.kwsVernInParagraph) { wsActual = RawWordformWs; } if (wsActual <= 0) throw new ArgumentException(String.Format("magic ws {0} not yet supported.", ws)); if (hvoMain == 0) { tss = MakeTss("", wsActual, tsf); } else { tss = sdaMain.get_MultiStringAlt(hvoMain, flidMain, wsActual); } cda.CacheStringAlt(hvoSec, flidSec, wsActual, tss); } }
void AddMultiStringProp(int hvo, XmlNode elt) { int ws = GetWritingSystem(elt); m_cda.CacheStringAlt(hvo, GetProp(hvo, elt), ws, MakeString(ws, elt)); }
/// <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">a Wfic.</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; int hvoPara = sda.get_ObjectProp(hvo, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject); int hvoStText = 0; if (hvoPara != 0) hvoStText = sda.get_ObjectProp(hvoPara, (int)CmObjectFields.kflidCmObject_Owner); if (hvoStText == 0) { // Unusual case, possibly hvoPara is not actually a para at all, for example, it may // be a picture caption. For now we make an empty reference so at least it won't crash. ITsStrFactory tsf = TsStrFactoryClass.Create(); ITsString dummy = tsf.MakeString("", ws); cda.CacheStringAlt(hvo, tag, ws, dummy); cda.CacheStringProp(hvo, tag, dummy); return; } ITsString tssName = null; StText stText = new StText(Cache, hvoStText); int wsActual = 0; bool fUsingAbbreviation = false; if (stText.OwningFlid == (int)Text.TextTags.kflidContents) { // see if we can find an abbreviation. Text text = stText.Owner as Text; tssName = text.Abbreviation.GetAlternativeOrBestTss(ws, out wsActual); if (wsActual > 0) fUsingAbbreviation = true; } else if (stText.OwningFlid == (int)ScrSection.ScrSectionTags.kflidContent) { // Body of Scripture. Figure a book/chapter/verse ScrTxtPara scrPara = new ScrTxtPara(m_cache, hvoPara, false, false); ScrBook book = new ScrBook(m_cache, Cache.GetOwnerOfObject(Cache.GetOwnerOfObject(stText.Hvo))); string mainRef = FullScrRef(scrPara, hvo, book.BestUIAbbrev).Trim(); int ktagParaSegments = StTxtPara.SegmentsFlid(Cache); int beginOffset = Cache.GetIntProperty(hvo, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset); int chvo = sda.get_VecSize(hvoPara, ktagParaSegments); int idxSeg = 0; while (idxSeg < chvo - 1) { // Stop if the FOLLOWING segment has a larger beginOffset than the target one. int hvoSeg = sda.get_VecItem(hvoPara, ktagParaSegments, idxSeg + 1); int segBeginOffset = sda.get_IntProp(hvoSeg, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset); if (segBeginOffset > beginOffset) break; idxSeg++; } ITsString tssRef1 = Cache.MakeUserTss(mainRef + VerseSegLabel(scrPara, idxSeg, ktagParaSegments)); cda.CacheStringProp(hvo, tag, tssRef1); cda.CacheStringAlt(hvo, tag, m_cache.DefaultUserWs, tssRef1); return; } else if (stText.OwningFlid == (int)ScrSection.ScrSectionTags.kflidHeading) { // use the section title without qualifiers. ITsString tssRef2 = stText.Title.GetAlternativeOrBestTss(ws, out wsActual); cda.CacheStringProp(hvo, tag, tssRef2); cda.CacheStringAlt(hvo, tag, wsActual, tssRef2); return; } if (wsActual == 0) { tssName = stText.Title.GetAlternativeOrBestTss(ws, out wsActual); } // if we didn't find an alternative, we'll just revert to using the 'ws' we're loading for. string sNotFound = null; if (wsActual == 0) { wsActual = ws; sNotFound = tssName.Text; } ITsStrBldr bldr = tssName.GetBldr(); // If we didn't find a "best", reset to an empty string. if (bldr.Length > 0 && bldr.Text == sNotFound) bldr.ReplaceTsString(0, bldr.Length, null); // Truncate to 8 chars, if the user hasn't specified an abbreviation. // Enhance JohnT: Eventually Text will have an abbreviation property, and we will do the // truncate title thing only if abbreviation is empty. if (!fUsingAbbreviation && bldr.Length > 8) bldr.ReplaceTsString(8, bldr.Length, null); // Make a TsTextProps specifying just the writing system. ITsPropsBldr propBldr = TsPropsBldrClass.Create(); propBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsActual); ITsTextProps props = propBldr.GetTextProps(); // Insert a space (if there was any title) if (bldr.Length > 0) bldr.Replace(bldr.Length, bldr.Length, " ", props); // if Scripture.IsResponsibleFor(stText) we should try to get the verse number of the annotation. //if (stText.OwningFlid == (int)Text.TextTags.kflidContents) //{ // Insert paragraph number. int cparas = sda.get_VecSize(hvoStText, (int)StText.StTextTags.kflidParagraphs); int ipara = 0; for (; sda.get_VecItem(hvoStText, (int)StText.StTextTags.kflidParagraphs, ipara) != hvoPara; ipara++) ; ipara++; bldr.Replace(bldr.Length, bldr.Length, ipara.ToString(), props); // And a colon... bldr.Replace(bldr.Length, bldr.Length, ":", props); // And now the segment number string segnumStr = GetSegmentRange(hvo); bldr.Replace(bldr.Length, bldr.Length, segnumStr, props); //} ITsString tssRef = bldr.GetString(); cda.CacheStringAlt(hvo, tag, wsActual, tssRef); cda.CacheStringProp(hvo, tag, tssRef); }
public override void Load(int hvoStText, int vtagStTextTitle, int ws, IVwCacheDa cda) { ITsString tssTitle = null; StText stText = new StText(Cache, hvoStText); if (Scripture.IsResponsibleFor(stText)) { // it's important that we try to scripture more dynamically than during initialization // of the virtual handler, since we may not have created the Scripture object with TE // until after we've created the FLEX project (LT-8123) and it might be possible that // the scripture for that project could get deleted subsequently(?). Scripture scripture = Cache.LangProject.TranslatedScriptureOA as Scripture; if (scripture != null) { tssTitle = scripture.BookChapterVerseBridgeAsTss(stText, ws); if (stText.OwningFlid == (int)ScrSection.ScrSectionTags.kflidHeading) { string sFmt = ITextStrings.ksSectionHeading; int iMin = sFmt.IndexOf("{0}"); if (iMin < 0) { tssTitle = m_cache.MakeUserTss(sFmt); } else { ITsIncStrBldr tisb = TsIncStrBldrClass.Create(); if (iMin > 0) tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(0, iMin))); tisb.AppendTsString(tssTitle); if (iMin + 3 < sFmt.Length) tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(iMin + 3))); tssTitle = tisb.GetString(); } } } } else if (stText.OwningFlid == (int)Text.TextTags.kflidContents) { Text text = stText.Owner as Text; tssTitle = text.Name.GetAlternativeTss(ws); } else { // throw? } if (tssTitle == null) tssTitle = Cache.MakeAnalysisTss(""); cda.CacheStringAlt(hvoStText, vtagStTextTitle, ws, tssTitle); }
private void CacheStringAltForAllCurrentWs(int[] currentWsList, IVwCacheDa cda, int hvoSec, int flidSec, ISilDataAccess sdaMain, int hvoMain, int flidMain) { foreach (int ws1 in currentWsList) cda.CacheStringAlt(hvoSec, flidSec, ws1, sdaMain.get_MultiStringAlt(hvoMain, flidMain, ws1)); }
private void CopyStringsToSecondary(List<int> writingSystems, ISilDataAccess sdaMain, int hvoMain, int flidMain, IVwCacheDa cda, int hvoSec, int flidSec, ITsStrFactory tsf) { CheckDisposed(); foreach (int ws in writingSystems) { int wsActual = 0; ITsString tss; if (ws > 0) { wsActual = ws; } else if (ws == LangProject.kwsFirstAnal) { int[] currentAnalysisWsList = m_caches.MainCache.LangProject.CurAnalysisWssRS.HvoArray; CacheStringAltForAllCurrentWs(currentAnalysisWsList, cda, hvoSec, flidSec, sdaMain, hvoMain, flidMain); continue; } else if (ws == LangProject.kwsFirstVern) { int[] currentVernWsList = m_caches.MainCache.LangProject.CurVernWssRS.HvoArray; CacheStringAltForAllCurrentWs(currentVernWsList, cda, hvoSec, flidSec, sdaMain, hvoMain, flidMain); continue; } else if (ws == LangProject.kwsVernInParagraph) { wsActual = this.RawWordformWs; } if (wsActual <= 0) throw new ArgumentException(String.Format("magic ws {0} not yet supported.", ws)); if (hvoMain == 0) { tss = MakeTss("", wsActual, tsf); } else { tss = sdaMain.get_MultiStringAlt(hvoMain, flidMain, wsActual); } cda.CacheStringAlt(hvoSec, flidSec, wsActual, tss); } }
/// <summary> /// Cache an empty string if this property was missing from the cache. /// </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 (ws == 0) throw new ArgumentException(); // Initialize the string properly. ITsString tss = m_tsf.MakeString("", ws); cda.CacheStringAlt(hvo, tag, ws, tss); }
/// <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) { ICmObject obj = CmObject.CreateFromDBObject(m_cache, hvo); ITsString tss; object[] parm = new object[1]; parm[0] = ws; tss = (ITsString)m_methodInfo.Invoke(obj, parm); if (tss != null) { cda.CacheStringAlt(hvo, tag, ws, tss); } else { ITsStrFactory tsf = TsStrFactoryClass.Create(); cda.CacheStringAlt(hvo, tag, ws, tsf.MakeString("", ws)); } }
/// <summary> /// The value of this property is the concatenation of the forms of its reversal entries that /// have the correct ws. /// </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) { cda.CacheStringAlt(hvo, tag, ws, GetValue(hvo, ws)); }