/// <summary> /// Implement the "Move Down" command. /// </summary> public bool OnMoveItemDownInVector(object argument) { CheckDisposed(); if (this.Object == null) { return(false); } IRnGenericRec rec = this.Object as IRnGenericRec; if (rec == null) { return(false); // shouldn't get here } IRnGenericRec recOwner = rec.Owner as IRnGenericRec; if (recOwner == null) { return(false); // shouldn't get here } int idxOrig = rec.OwnOrd; Debug.Assert(recOwner.SubRecordsOS[idxOrig] == rec); if (idxOrig == recOwner.SubRecordsOS.Count - 1) { return(false); // shouldn't get here. } UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoMoveDown, Resources.DetailControlsStrings.ksRedoMoveDown, Cache.ActionHandlerAccessor, () => { // idxOrig + 2 looks strange, but it's the correct value to make this work. recOwner.SubRecordsOS.MoveTo(idxOrig, idxOrig, recOwner.SubRecordsOS, idxOrig + 2); }); return(true); }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { if (DialogResult == DialogResult.OK) { if (string.IsNullOrEmpty(m_titleTextBox.Text)) { e.Cancel = true; MessageBox.Show(this, LexTextControls.ksFillInTitle, LexTextControls.ksMissingInformation, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } using (new WaitCursor(this)) { UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateRecord, LexTextControls.ksRedoCreateRecord, m_cache.ActionHandlerAccessor, () => { var recFactory = m_cache.ServiceLocator.GetInstance <IRnGenericRecFactory>(); int posHvo = ((HvoTreeNode)m_typeCombo.SelectedNode).Hvo; ICmPossibility type = m_cache.ServiceLocator.GetInstance <ICmPossibilityRepository>().GetObject(posHvo); switch (m_owner.ClassID) { case RnResearchNbkTags.kClassId: m_newRecord = recFactory.Create((IRnResearchNbk)m_owner, m_titleTextBox.Tss, type); break; case RnGenericRecTags.kClassId: m_newRecord = recFactory.Create((IRnGenericRec)m_owner, m_titleTextBox.Tss, type); break; } }); } } base.OnClosing(e); }
private void CollectRecords(IRnGenericRec rec, HashSet <IRnGenericRec> records) { records.Add(rec); foreach (var subrec in rec.SubRecordsOS) { CollectRecords(subrec, records); } }
private RnGenericRec MakeSubRecord(IRnGenericRec parent, string title, int index) { var typeList = EnsureRecTypesList(); IRnGenericRec entry = null; entry = Cache.ServiceLocator.GetInstance<IRnGenericRecFactory>().Create(); parent.SubRecordsOS.Insert(index, entry); entry.Title = Cache.TsStrFactory.MakeString(title, Cache.DefaultAnalWs); entry.TypeRA = typeList.PossibilitiesOS[0]; return (RnGenericRec)entry; }
private RnGenericRec MakeRnRecord(string title) { var typeList = EnsureRecTypesList(); IRnGenericRec entry = null; entry = Cache.ServiceLocator.GetInstance <IRnGenericRecFactory>().Create(); Cache.LangProject.ResearchNotebookOA.RecordsOC.Add(entry); entry.Title = TsStringUtils.MakeString(title, Cache.DefaultAnalWs); entry.TypeRA = typeList.PossibilitiesOS[0]; return((RnGenericRec)entry); }
private RnGenericRec MakeSubRecord(IRnGenericRec parent, string title, int index) { var typeList = EnsureRecTypesList(); IRnGenericRec entry = null; entry = Cache.ServiceLocator.GetInstance <IRnGenericRecFactory>().Create(); parent.SubRecordsOS.Insert(index, entry); entry.Title = TsStringUtils.MakeString(title, Cache.DefaultAnalWs); entry.TypeRA = typeList.PossibilitiesOS[0]; return((RnGenericRec)entry); }
private static IText MakeATextWith2Paragraphs(IServiceLocator servLoc, IRnGenericRec owner) { var result = servLoc.GetInstance <ITextFactory>().Create(); owner.TextRA = result; var stText = servLoc.GetInstance <IStTextFactory>().Create(); result.ContentsOA = stText; var paraFact = servLoc.GetInstance <IStTxtParaFactory>(); stText.ParagraphsOS.Add(paraFact.Create()); stText.ParagraphsOS.Add(paraFact.Create()); return(result); }
/// <summary> /// Implement the "Promote" command. /// </summary> public bool OnPromoteSubitemInVector(object argument) { CheckDisposed(); if (this.Object == null) { return(false); } IRnGenericRec rec = this.Object as IRnGenericRec; if (rec == null) { return(false); // shouldn't get here } IRnGenericRec recOwner = rec.Owner as IRnGenericRec; if (recOwner == null) { return(false); // shouldn't get here } // Grab the mediator now for later use, because this slice may get disposed before we // use it. Mediator mediator = m_mediator; UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoPromote, Resources.DetailControlsStrings.ksRedoPromote, Cache.ActionHandlerAccessor, () => { if (recOwner.Owner is IRnGenericRec) { (recOwner.Owner as IRnGenericRec).SubRecordsOS.Insert(recOwner.OwnOrd + 1, rec); } else if (recOwner.Owner is IRnResearchNbk) { (recOwner.Owner as IRnResearchNbk).RecordsOC.Add(rec); } else { throw new Exception("RnGenericRec object not owned by either RnResearchNbk or RnGenericRec??"); } }); if (recOwner.Owner is IRnResearchNbk) { // If possible, jump to the newly promoted record. mediator.BroadcastMessageUntilHandled("JumpToRecord", rec.Hvo); } return(true); }
/// <summary> /// Handles the xWorks message to insert a new Data Notebook record. /// Invoked by the RecordClerk /// </summary> /// <param name="argument">The xCore Command object.</param> /// <returns>true, if we handled the message, otherwise false, if there was an unsupported 'classname' parameter</returns> public bool OnDialogInsertItemInVector(object argument) { CheckDisposed(); var command = (Command)argument; string className = XmlUtils.GetOptionalAttributeValue(command.Parameters[0], "className"); if (className == null || className != "RnGenericRec") { return(false); } bool subrecord = XmlUtils.GetOptionalBooleanAttributeValue(command.Parameters[0], "subrecord", false); bool subsubrecord = XmlUtils.GetOptionalBooleanAttributeValue(command.Parameters[0], "subsubrecord", false); using (var dlg = new InsertRecordDlg()) { var cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); ICmObject obj = null; ICmObject objSelected = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ICmObject; ICmObject objOwning = m_mediator.PropertyTable.GetValue("ActiveClerkOwningObject") as ICmObject; if (subsubrecord) { obj = objSelected; } else if (subrecord && objSelected != null) { obj = objSelected; while (obj.Owner is IRnGenericRec) { obj = obj.Owner; } } else { obj = objOwning; } dlg.SetDlgInfo(cache, m_mediator, obj); if (dlg.ShowDialog(Form.ActiveForm) == DialogResult.OK) { IRnGenericRec newRec = dlg.NewRecord; m_mediator.SendMessage("JumpToRecord", newRec.Hvo); } } return(true); // We "handled" the message, regardless of what happened. }
/// <summary> /// See if it makes sense to provide the "Move Up" command. /// </summary> public bool OnDisplayMoveItemUpInVector(object commandObject, ref UIItemDisplayProperties display) { CheckDisposed(); var command = (Command)commandObject; string className = XmlUtils.GetManditoryAttributeValue(command.Parameters[0], "className"); bool fIsValid = false; if (className == "RnGenericRec") { if (this.Object != null) { IRnGenericRec rec = this.Object as IRnGenericRec; if (rec != null && rec.Owner is IRnGenericRec && rec.OwnOrd > 0) { fIsValid = true; } } } display.Enabled = fIsValid; return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get a label for a cross-referenced record. /// </summary> /// ------------------------------------------------------------------------------------ private string GetLinkLabelForRecord(IRnGenericRec rec) { StringBuilder bldr = new StringBuilder(); if (rec.TypeRA != null && rec.TypeRA.Name != null) { int ws; ITsString tss = rec.TypeRA.Name.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out ws); if (tss.Length > 0) { bldr.AppendFormat("{0} - ", tss.Text); } } if (rec.Title != null && rec.Title.Length > 0) { bldr.Append(TsStringUtils.GetXmlRep(rec.Title, m_cache.WritingSystemFactory, 0, true)); } if (!rec.DateOfEvent.IsEmpty) { bldr.AppendFormat(" - {0}", rec.DateOfEvent.ToXMLExportShortString()); } return(bldr.ToString()); }
private bool StoreCustomListRefItem(IRnGenericRec rec, RnSfMarker rsf, string sData, ICmPossibilityList list) { // First, get the existing data so we can check whether the new item is needed, // and so that we know where to insert it (at the end) if it is. int chvo = m_cache.DomainDataByFlid.get_VecSize(rec.Hvo, rsf.m_flid); int[] hvosField; using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative<int>(chvo)) { m_cache.DomainDataByFlid.VecProp(rec.Hvo, rsf.m_flid, chvo, out chvo, arrayPtr); hvosField = MarshalEx.NativeToArray<int>(arrayPtr, chvo); } ICmPossibility poss; List<string> rgsHier = SplitForSubitems(rsf, sData); if (rgsHier == null || rgsHier.Count == 0) { poss = rsf.m_tlo.m_default; if (poss != null && !hvosField.Contains(poss.Hvo) && poss.ClassID == list.ItemClsid) { m_cache.DomainDataByFlid.Replace(rec.Hvo, rsf.m_flid, chvo, chvo, new int[] { poss.Hvo }, 1); } return true; } switch (list.OwningFlid) { case LangProjectTags.kflidAnthroList: if (m_mapAnthroCode.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.AnthroListOA.PossibilitiesOS, m_mapAnthroCode); poss = FindPossibilityOrNull(rgsHier, m_mapAnthroCode); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewAnthroItem(rgsHier); break; case LangProjectTags.kflidConfidenceLevels: if (m_mapConfidence.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.ConfidenceLevelsOA.PossibilitiesOS, m_mapConfidence); poss = FindPossibilityOrNull(rgsHier, m_mapConfidence); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewConfidenceItem(rgsHier); break; case LangProjectTags.kflidLocations: if (m_mapLocation.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.LocationsOA.PossibilitiesOS, m_mapLocation); poss = FindPossibilityOrNull(rgsHier, m_mapLocation); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewLocation(rgsHier); break; case RnResearchNbkTags.kflidRecTypes: if (m_mapRecType.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.ResearchNotebookOA.RecTypesOA.PossibilitiesOS, m_mapRecType); poss = FindPossibilityOrNull(rgsHier, m_mapRecType); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewRecType(rgsHier); break; case LangProjectTags.kflidTextMarkupTags: if (m_mapPhraseTag.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.TextMarkupTagsOA.PossibilitiesOS, m_mapPhraseTag); poss = FindPossibilityOrNull(rgsHier, m_mapPhraseTag); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewPhraseTag(rgsHier); break; case LangProjectTags.kflidPeople: if (m_mapPeople.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.PeopleOA.PossibilitiesOS, m_mapPeople); poss = FindPossibilityOrNull(rgsHier, m_mapPeople); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewPerson(rgsHier); break; case LangProjectTags.kflidRestrictions: if (m_mapRestriction.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.RestrictionsOA.PossibilitiesOS, m_mapRestriction); poss = FindPossibilityOrNull(rgsHier, m_mapRestriction); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewRestriction(rgsHier); break; case LangProjectTags.kflidStatus: if (m_mapStatus.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.StatusOA.PossibilitiesOS, m_mapStatus); poss = FindPossibilityOrNull(rgsHier, m_mapStatus); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewStatus(rgsHier); break; case LangProjectTags.kflidTimeOfDay: if (m_mapTimeOfDay.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.TimeOfDayOA.PossibilitiesOS, m_mapTimeOfDay); poss = FindPossibilityOrNull(rgsHier, m_mapTimeOfDay); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) poss = CreateNewTimeOfDay(rgsHier); break; default: Dictionary<string, ICmPossibility> map; if (!m_mapListMapPossibilities.TryGetValue(list.Guid, out map)) { map = new Dictionary<string, ICmPossibility>(); FillPossibilityMap(rsf, list.PossibilitiesOS, map); m_mapListMapPossibilities.Add(list.Guid, map); } List<ICmPossibility> rgNew; if (!m_mapNewPossibilities.TryGetValue(list.Guid, out rgNew)) { rgNew = new List<ICmPossibility>(); m_mapNewPossibilities.Add(list.Guid, rgNew); } poss = FindPossibilityOrNull(rgsHier, map); if (poss == null && !rsf.m_tlo.m_fIgnoreNewStuff) { CmPossibilityCreator creator = null; switch (list.ItemClsid) { case CmPossibilityTags.kClassId: creator = PossibilityCreator; break; case CmLocationTags.kClassId: creator = LocationCreator; break; case CmPersonTags.kClassId: creator = PersonCreator; break; case CmAnthroItemTags.kClassId: creator = AnthroItemCreator; break; case CmCustomItemTags.kClassId: creator = CustomItemCreator; break; case CmSemanticDomainTags.kClassId: creator = SemanticDomainCreator; break; // These are less likely, but legal, so we have to allow for them. case MoMorphTypeTags.kClassId: creator = MorphTypeCreator; break; case PartOfSpeechTags.kClassId: creator = NewPartOfSpeechCreator; break; case LexEntryTypeTags.kClassId: creator = NewLexEntryTypeCreator; break; case LexRefTypeTags.kClassId: creator = NewLexRefTypeCreator; break; } if (creator != null) poss = CreateNewPossibility(rgsHier, creator, list.PossibilitiesOS, map, rgNew); } break; } if (poss != null && !hvosField.Contains(poss.Hvo) && poss.ClassID == list.ItemClsid) { m_cache.DomainDataByFlid.Replace(rec.Hvo, rsf.m_flid, chvo, chvo, new int[] { poss.Hvo }, 1); return true; } else { return !rsf.m_tlo.m_fIgnoreNewStuff; } }
public void ReconcileModifyingProperties() { var entry1 = MakeEntry("kick", "strike with foot"); var sense1 = entry1.SensesOS[0]; VerifyReconcilingAChange( () => { SetString(sense1.Definition, Cache.DefaultAnalWs, "swing foot and make sharp contact with object"); SetString(sense1.Definition, Cache.DefaultVernWs, "slam with nether appendage"); SetString(sense1.Gloss, Cache.DefaultVernWs, "hit with foot"); }, "set multistring properties"); VerifyReconcilingAChange( () => AddSense(entry1, "strike with boot"), "edit owing sequence"); IText text = null; UndoableUnitOfWorkHelper.Do("undo make text", "redo make text", m_actionHandler, () => { text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(text); }); IStText stText = null; ICmObjectId id1 = null; VerifyReconcilingAChange( () => { stText = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); text.ContentsOA = stText; id1 = stText.Id; }, "set owning atomic"); stText = (IStText)Cache.ServiceLocator.GetObject(id1); ICmPossibility senseType = null; UndoableUnitOfWorkHelper.Do("undo make sense type", "redo make sense type", m_actionHandler, () => { var senseTypesList = Cache.LangProject.LexDbOA.SenseTypesOA; if (senseTypesList == null) { senseTypesList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); Cache.LangProject.LexDbOA.SenseTypesOA = senseTypesList; } senseType = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); senseTypesList.PossibilitiesOS.Add(senseType); }); VerifyReconcilingAChange( () => sense1.SenseTypeRA = senseType, "set ref atomic"); ICmPossibilityList thesaurusItemsList = null; UndoableUnitOfWorkHelper.Do("undo make thes list", "redo make thes list", m_actionHandler, () => { thesaurusItemsList = Cache.LangProject.ThesaurusRA; if (thesaurusItemsList == null) { thesaurusItemsList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); Cache.LangProject.ThesaurusRA = thesaurusItemsList; } }); ICmPossibility thesaurusItem1 = null; ICmPossibility thesaurusItem2 = null; ICmObjectId id2 = null; VerifyReconcilingAChange( () => { thesaurusItem1 = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); thesaurusItemsList.PossibilitiesOS.Add(thesaurusItem1); id1 = thesaurusItem1.Id; thesaurusItem2 = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); thesaurusItemsList.PossibilitiesOS.Add(thesaurusItem2); id2 = thesaurusItem2.Id; }, "adding two items to an owning collection"); // Verify undoes creating them, then creates new ones with the same IDs. We need the new valid objects. thesaurusItem1 = (ICmPossibility)Cache.ServiceLocator.GetObject(id1); thesaurusItem2 = (ICmPossibility)Cache.ServiceLocator.GetObject(id1); VerifyReconcilingAChange( () => { sense1.ThesaurusItemsRC.Add(thesaurusItem1); sense1.ThesaurusItemsRC.Add(thesaurusItem2); }, "adding two items to a reference collection"); VerifyReconcilingAChange( () => { entry1.MainEntriesOrSensesRS.Add(sense1); }, "adding an item to a reference sequence"); IStTxtPara para = null; UndoableUnitOfWorkHelper.Do("undo make para", "redo make para", m_actionHandler, () => { para = Cache.ServiceLocator.GetInstance <IStTxtParaFactory>().Create(); stText.ParagraphsOS.Add(para); }); VerifyReconcilingAChange( () => { SetParaContents(para, "Hello world"); // big string para.Label = Cache.TsStrFactory.MakeString("label", Cache.DefaultVernWs); // non-big string, just to be sure }, "setting a simple string, previously empty"); VerifyReconcilingAChange( () => SetParaContents(para, "Goodbye, world"), "setting a simple string, previously non-empty"); VerifyReconcilingAChange( () => para.ParseIsCurrent = true, "setting a boolean"); VerifyReconcilingAChange( () => thesaurusItem2.HelpId = "look for help here!", "setting a plain unicode string"); VerifyReconcilingAChange( () => thesaurusItemsList.Depth = 17, "setting an integer"); VerifyReconcilingAChange( () => thesaurusItemsList.ListVersion = Guid.NewGuid(), "setting a guid property"); var propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "red hot"); var props = propsBldr.GetTextProps(); VerifyReconcilingAChange( () => para.StyleRules = props, "setting a text props"); IRnGenericRec genericRec = null; UndoableUnitOfWorkHelper.Do("undo make notebook record", "redo make notebook record", m_actionHandler, () => { genericRec = Cache.ServiceLocator.GetInstance <IRnGenericRecFactory>().Create(); Cache.LangProject.ResearchNotebookOA.RecordsOC.Add(genericRec); }); VerifyReconcilingAChange( () => genericRec.DateOfEvent = new GenDate(GenDate.PrecisionType.Exact, 7, 23, 1908, true), "setting a generic date"); IUserConfigAcct acct = null; UndoableUnitOfWorkHelper.Do("undo make user view", "redo", m_actionHandler, () => { acct = Cache.ServiceLocator.GetInstance <IUserConfigAcctFactory>().Create(); Cache.LanguageProject.UserAccountsOC.Add(acct); }); VerifyReconcilingAChange(() => acct.Sid = new byte[] { 1, 2, 3 }, "setting a binary property"); }
private bool StoreRecType(IRnGenericRec rec, RnSfMarker rsf, string sData) { List<string> rgsHier = SplitForSubitems(rsf, sData); if (rgsHier == null || rgsHier.Count == 0) { rec.TypeRA = rsf.m_tlo.m_default; return true; } if (m_mapRecType.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.ResearchNotebookOA.RecTypesOA.PossibilitiesOS, m_mapRecType); ICmPossibility poss = FindPossibilityOrNull(rgsHier, m_mapRecType); if (poss != null) { rec.TypeRA = poss; return true; } else if (rsf.m_tlo.m_fIgnoreNewStuff) { return false; } else { ICmPossibility item = CreateNewRecType(rgsHier); rec.TypeRA = item; return true; } }
private bool StoreParticipant(IRnGenericRec rec, RnSfMarker rsf, string sData) { var partic = rec.ParticipantsOC.FirstOrDefault(part => part.RoleRA == null); if (partic == null) { partic = m_cache.ServiceLocator.GetInstance<IRnRoledParticFactory>().Create(); rec.ParticipantsOC.Add(partic); } var rgsHier = SplitForSubitems(rsf, sData); if (rgsHier == null || rgsHier.Count == 0) { var def = rsf.m_tlo.m_default as ICmPerson; if (def != null && !partic.ParticipantsRC.Contains(def)) partic.ParticipantsRC.Add(def); return true; } if (m_mapPeople.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.PeopleOA.PossibilitiesOS, m_mapPeople); var poss = FindPossibilityOrNull(rgsHier, m_mapPeople); if (poss != null) { if (!partic.ParticipantsRC.Contains(poss as ICmPerson)) partic.ParticipantsRC.Add(poss as ICmPerson); return true; } if (!rsf.m_tlo.m_fIgnoreNewStuff) { var item = CreateNewPerson(rgsHier); if (item != null) { partic.ParticipantsRC.Add(item); return true; } } return false; }
public void AutoLoad() { // Get the language project as an FDO object ILangProject lp = m_fdoCache.LangProject; // Use it to get the HVO of the data notebook, but without making an FDO object // and thus loading data. Assert.IsTrue(m_sda.get_IsPropInCache(lp.Hvo, (int)LangProject.LangProjectTags.kflidResearchNotebook, (int)CellarModuleDefns.kcptOwningAtom, 0), "LP notebook loaded by FDO"); int hvoNotebook = m_fdoCache.GetObjProperty(lp.Hvo, (int)LangProject.LangProjectTags.kflidResearchNotebook); // Owning atomic Assert.IsFalse(m_sda.get_IsPropInCache(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes, (int)CellarModuleDefns.kcptOwningAtom, 0), "Notebook event types not preloaded"); int hvoEventTypes = m_sda.get_ObjectProp(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes); Assert.IsTrue(m_sda.get_IsPropInCache(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes, (int)CellarModuleDefns.kcptOwningAtom, 0), "Notebook event types autoloaded"); Assert.IsTrue(hvoEventTypes != 0, "got real event types"); int flidET = m_sda.get_IntProp(hvoEventTypes, (int)CmObjectFields.kflidCmObject_OwnFlid); Assert.AreEqual((int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes, flidET, "owning flid loaded correctly"); int clsidET = m_sda.get_IntProp(hvoEventTypes, (int)CmObjectFields.kflidCmObject_Class); Assert.AreEqual((int)CmPossibilityList.kClassId, clsidET, "class autoloaded"); int ownerET = m_sda.get_ObjectProp(hvoEventTypes, (int)CmObjectFields.kflidCmObject_Owner); Assert.AreEqual(hvoNotebook, ownerET, "owner auto-loaded"); // Todo: test ref atomic. // Owning collection. Assert.IsFalse(m_sda.get_IsPropInCache(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, (int)CellarModuleDefns.kcptOwningCollection, 0), "Nb records not preloaded"); // Forces a load int chvoRecs = m_sda.get_VecSize(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords); Assert.IsTrue(m_sda.get_IsPropInCache(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, (int)CellarModuleDefns.kcptOwningCollection, 0), "Nb records autoloaded"); // Be careful what we assert...don't want it too dependent on the exact data. // Should be OK to assume at least a few records. Assert.IsTrue(chvoRecs > 4, "at least 4 recs"); int hvoRec3 = m_sda.get_VecItem(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, 3); int clsIDR3 = m_sda.get_IntProp(hvoRec3, (int)CmObjectFields.kflidCmObject_Class); Assert.IsTrue((int)RnEvent.kClassId == clsIDR3 || (int)RnAnalysis.kClassId == clsIDR3, "class of rec 3 valid"); Assert.IsFalse(m_sda.get_IsPropInCache(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidResearchers, (int)CellarModuleDefns.kcptReferenceCollection, 0), "R3 researchers not preloaded"); int chvoR3Researchers = m_sda.get_VecSize(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidResearchers); Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidResearchers, (int)CellarModuleDefns.kcptReferenceCollection, 0), "R3 researchers autoloaded"); // We can't assume anything about any one record, but we should be able to find // at least one where researchers is non-empty. Along the way we do at least // some testing of VecProp and also make sure we can load a string that is a // BigString bool fGotEmpty = false; bool fGotNonEmpty = false; bool fGotEvent = false; int hvoEvent = 0; // some record will be an event... int hvoText = 0; // that has a non-empty structured text... int hvoPara = 0; // that has a non-empty paragraph with a label. for (int ihvo = 0; ihvo < chvoRecs && ((!fGotEmpty) || (!fGotNonEmpty) || (!fGotEvent) || hvoText == 0); ihvo++) { int hvoRec = m_sda.get_VecItem(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, ihvo); int chvoResearchers = m_sda.get_VecSize(hvoRec, (int)RnGenericRec.RnGenericRecTags.kflidResearchers); if (chvoResearchers > 0) { if (!fGotNonEmpty) { fGotNonEmpty = true; // Try this on the first non-empty list. int hvoResearcher = m_sda.get_VecItem(hvoRec, (int)RnGenericRec.RnGenericRecTags.kflidResearchers, 0); int clsidResearcher = m_sda.get_IntProp(hvoResearcher, (int)CmObjectFields.kflidCmObject_Class); Assert.AreEqual(CmPerson.kClassId, clsidResearcher, "class of researcher"); } } else { fGotEmpty = true; // should now be considered cached anyway. Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec, (int)RnGenericRec.RnGenericRecTags.kflidResearchers, (int)CellarModuleDefns.kcptReferenceCollection, 0), "empty researchers autoloaded"); } int clsIDRec = m_sda.get_IntProp(hvoRec, (int)CmObjectFields.kflidCmObject_Class); if (clsIDRec == (int)RnEvent.kClassId && !fGotEvent) { hvoEvent = hvoRec; hvoText = m_sda.get_ObjectProp(hvoEvent, (int)RnEvent.RnEventTags.kflidDescription); if (hvoText != 0) { int chvo; using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(int))) { // if there's a description with more than 1000 paragraphs this will break and // we'll fix it then. m_sda.VecProp(hvoText, (int)StText.StTextTags.kflidParagraphs, 1000, out chvo, arrayPtr); int[] rgHvo = (int[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(int)); // search for the paragraph that has non-empty label (there are a couple). for (int ihvoPara = 0; ihvoPara < chvo; ++ihvoPara) { hvoPara = rgHvo[ihvoPara]; // BigString ITsString tssPara = m_sda.get_StringProp(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents); if (tssPara.Length > 0) { string sname = m_sda.get_UnicodeProp(hvoPara, (int)StPara.StParaTags.kflidStyleName); if (sname != null && sname.Length > 0) { fGotEvent = true; } // Todo: it would be nice to test UnicodePropRgch, but we can't test // on the same prop because it's already loaded. Also, the modification // for data loading is shared code. We could make another cache instance // to test from, maybe? Or keep searching till we find another instance? // Could also look for a kcptBigUnicode, but implementation is identical. } } } } } } Assert.IsTrue(fGotEmpty && fGotNonEmpty, "found both empty and non-empty researcher lists"); Assert.IsTrue(hvoEvent != 0, "got at least one event"); // todo: test sequence (somehow verify order). // todo: test ref seq/collection (verify it does NOT set the owner to the referring obj). // Ref atomic Assert.IsFalse(m_sda.get_IsPropInCache(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidConfidence, (int)CellarModuleDefns.kcptReferenceAtom, 0), "R3 confidence not preloaded"); int hvoConfidence = m_sda.get_ObjectProp(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidConfidence); Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidConfidence, (int)CellarModuleDefns.kcptReferenceAtom, 0), "R3 confidence autoloaded"); if (hvoConfidence != 0) { int clsidConfidence = m_sda.get_IntProp(hvoConfidence, (int)CmObjectFields.kflidCmObject_Class); Assert.AreEqual(CmPossibility.kClassId, clsidConfidence, "class of confidence"); } // TsString. Assert.IsFalse(m_sda.get_IsPropInCache(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidTitle, (int)CellarModuleDefns.kcptString, 0), "title of rec 3 not preloaded"); ITsString qtssRec3Title = m_sda.get_StringProp(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidTitle); Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidTitle, (int)CellarModuleDefns.kcptString, 0), "autoloaded title of rec 3"); // Int (e.g., gendate) Assert.IsFalse(m_sda.get_IsPropInCache(hvoEvent, (int)RnEvent.RnEventTags.kflidDateOfEvent, (int)CellarModuleDefns.kcptInteger, 0), "date of event not preloaded"); int nDateEvent = m_sda.get_IntProp(hvoEvent, (int)RnEvent.RnEventTags.kflidDateOfEvent); Assert.IsTrue(m_sda.get_IsPropInCache(hvoEvent, (int)RnEvent.RnEventTags.kflidDateOfEvent, (int)CellarModuleDefns.kcptInteger, 0), "autoloaded date of event"); // Todo: find example of int64 prop and test. // Test loading of binary data (into a TsTextProps). object obj = m_sda.get_UnknownProp(hvoPara, (int)StPara.StParaTags.kflidStyleRules); Assert.IsNotNull(obj as ITsTextProps); // Also loading of raw binary data, using the same prop. using (ArrayPtr rgbData = MarshalEx.ArrayToNative(10000, typeof(byte))) { int cb = -1; m_sda.BinaryPropRgb(hvoPara, (int)StPara.StParaTags.kflidStyleRules, rgbData, 10000, out cb); Assert.IsTrue(cb > 0, "got some bytes using BinaryPropRgb"); // Enhance JohnT: wish I could figure what they ought to be and test... // Get a UserView object (they have no owner, so go direct) SqlConnection con = new SqlConnection(string.Format("Server={0}; Database={1}; User ID = fwdeveloper;" + "Password=careful; Pooling=false;", m_fdoCache.ServerName, m_fdoCache.DatabaseName)); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "select top 2 id from UserView"; SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); int hvoUv = reader.GetInt32(0); reader.Close(); con.Close(); // Guid prop Guid guidUv = m_sda.get_GuidProp(hvoUv, (int)UserView.UserViewTags.kflidApp); Assert.IsFalse(guidUv == Guid.Empty, "got non-empty guid"); // Time prop long lEventTime = m_sda.get_TimeProp(hvoEvent, (int)RnGenericRec.RnGenericRecTags.kflidDateCreated); Assert.IsFalse(lEventTime == 0, "got meaningful time"); // Enhance JohnT: really verify. // Int prop int viewSubtype = m_sda.get_IntProp(hvoUv, (int)UserView.UserViewTags.kflidSubType); // Enhance JohnT: think of a way to verify... // get_Prop: Time object objMod = m_sda.get_Prop(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidDateModified); Assert.IsTrue(objMod is long); // get_Prop: String int hvoRec0 = m_sda.get_VecItem(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, 0); object objTitle = m_sda.get_Prop(hvoRec0, (int)RnGenericRec.RnGenericRecTags.kflidTitle); Assert.IsTrue(objTitle is ITsString, "get_Prop title is string"); // get_Prop: Int object objType = m_sda.get_Prop(hvoUv, (int)UserView.UserViewTags.kflidType); Assert.IsTrue(objType is int, "get_Prop type is integer"); // Confirm some more results by loading through FDO ICmObject objRec3 = CmObject.CreateFromDBObject(m_fdoCache, hvoRec3); Assert.IsTrue(objRec3 is IRnGenericRec, "object of correct type"); IRnGenericRec grRec3 = (IRnGenericRec)objRec3; // I'd prefer to use full ITsString equality test, but not sure how to get // a regular ITsString from FDO obj. Assert.AreEqual(qtssRec3Title.Text, grRec3.Title.Text, "two ways to retrieve R3 title match"); // Can't try this yet because FDO GenDate not yet implemented. The data type might not // be right anyway. // CmObject objEvent = CmObject.CreateFromDBObject(m_fdoCache, hvoEvent); // Assert.IsTrue(objEvent is RnEvent, "type of event"); // RnEvent ev1 = (RnEvent) objEvent; // Assert.AreEqual(ev1.DateOfEvent, nDateEvent, "date of event matches"); } }
private static IText MakeATextWith2Paragraphs(IServiceLocator servLoc, IRnGenericRec owner) { var result = servLoc.GetInstance<ITextFactory>().Create(); owner.TextRA = result; var stText = servLoc.GetInstance<IStTextFactory>().Create(); result.ContentsOA = stText; var paraFact = servLoc.GetInstance<IStTxtParaFactory>(); stText.ParagraphsOS.Add(paraFact.Create()); stText.ParagraphsOS.Add(paraFact.Create()); return result; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get a label for a cross-referenced record. /// </summary> /// ------------------------------------------------------------------------------------ private string GetLinkLabelForRecord(IRnGenericRec rec) { StringBuilder bldr = new StringBuilder(); if (rec.TypeRA != null && rec.TypeRA.Name != null) { int ws; ITsString tss = rec.TypeRA.Name.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out ws); if (tss.Length > 0) bldr.AppendFormat("{0} - ", tss.Text); } if (rec.Title != null && rec.Title.Length > 0) bldr.Append(TsStringUtils.GetXmlRep(rec.Title, m_cache.WritingSystemFactory, 0, true)); if (!rec.DateOfEvent.IsEmpty) bldr.AppendFormat(" - {0}", rec.DateOfEvent.ToXMLExportShortString()); return bldr.ToString(); }
/// <summary> /// Implement the "Demote..." command. /// </summary> public bool OnDemoteSubitemInVector(object argument) { CheckDisposed(); if (this.Object == null) { return(false); } IRnGenericRec rec = this.Object as IRnGenericRec; if (rec == null) { return(false); // shouldn't get here } IRnGenericRec newOwner = null; if (Object.Owner is IRnGenericRec) { IRnGenericRec recOwner = Object.Owner as IRnGenericRec; if (recOwner.SubRecordsOS.Count == 2) { if (Object.OwnOrd == 0) { newOwner = recOwner.SubRecordsOS[1]; } else { newOwner = recOwner.SubRecordsOS[0]; } } else { List <IRnGenericRec> owners = new List <IRnGenericRec>(); foreach (var recT in recOwner.SubRecordsOS) { if (recT != rec) { owners.Add(recT); } } newOwner = ContainingDataTree.ChooseNewOwner(owners.ToArray(), Resources.DetailControlsStrings.ksChooseOwnerOfDemotedSubrecord); } } else { return(false); } if (newOwner == null) { return(true); } if (newOwner == rec) { throw new Exception("RnGenericRec cannot own itself!"); } UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoDemote, Resources.DetailControlsStrings.ksRedoDemote, Cache.ActionHandlerAccessor, () => { newOwner.SubRecordsOS.Insert(0, rec); }); return(true); }
/// <summary> /// Store a value with a "kcptTime" type value. These are less forgiving than those with /// "kcptGenDate" values, because they are generally created by a computer program instead /// of typed by a user. /// </summary> private void SetDateTimeValue(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { string sData = field.Data.Trim(); if (sData.Length == 0) return; // nothing we can do without data! DateTime dt; if (!DateTime.TryParseExact(sData, rsf.m_dto.m_rgsFmt.ToArray(), null, DateTimeStyles.None, out dt)) { LogMessage(String.Format(LexTextControls.ksCannotParseDateTime, field.Data, field.Marker), field.LineNumber); return; } switch (rsf.m_flid) { case RnGenericRecTags.kflidDateCreated: rec.DateCreated = dt; break; case RnGenericRecTags.kflidDateModified: rec.DateModified = dt; break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); SilTime.SetTimeProperty(m_cache.DomainDataByFlid, rec.Hvo, rsf.m_flid, dt); break; } }
private void ExportRecord(TextWriter writer, IRnGenericRec record, int level) { writer.WriteLine( "<Entry level=\"{0}\" dateCreated=\"{1}\" dateModified=\"{2}\" guid=\"{3}\">", level, record.DateCreated.ToString("yyyy-MM-ddThh:mm:ss"), record.DateModified.ToString("yyyy-MM-ddThh:mm:ss"), record.Guid); ExportString(writer, record.Title, "Title"); ExportAtomicReference(writer, record.TypeRA, "Type", "CmPossibility"); List <ICmPossibility> collection = new List <ICmPossibility>(); collection.AddRange(record.RestrictionsRC); ExportReferenceList(writer, collection, "Restrictions", "CmPossibility", CellarPropertyType.ReferenceCollection); collection.Clear(); if (!record.DateOfEvent.IsEmpty) { writer.WriteLine("<Field name=\"DateOfEvent\" type=\"GenDate\" card=\"atomic\">"); writer.WriteLine("<Item ws=\"{0}\">{1}</Item>", UserWsTag, XmlUtils.MakeSafeXml(record.DateOfEvent.ToXMLExportShortString())); writer.WriteLine("</Field>"); } collection.AddRange(record.TimeOfEventRC); ExportReferenceList(writer, collection, "TimeOfEvent", "CmPossibility", CellarPropertyType.ReferenceCollection); collection.Clear(); collection.AddRange(record.ResearchersRC.ToArray()); ExportReferenceList(writer, collection, "Researchers", "CmPerson", CellarPropertyType.ReferenceCollection); collection.Clear(); collection.AddRange(record.SourcesRC.ToArray()); ExportReferenceList(writer, collection, "Sources", "CmPerson", CellarPropertyType.ReferenceCollection); collection.Clear(); ExportAtomicReference(writer, record.ConfidenceRA, "Confidence", "CmPossibility"); if (record.ParticipantsOC != null && record.ParticipantsOC.Count > 0) { foreach (var part in record.ParticipantsOC) { collection.AddRange(part.ParticipantsRC.ToArray()); if (part.RoleRA != null) { int wsRole; ITsString tssRole = part.RoleRA.Name.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsRole); ExportReferenceList(writer, collection, tssRole.Text, "RnRoledPartic", CellarPropertyType.ReferenceCollection); } else { ExportReferenceList(writer, collection, "Participants", "RnRoledPartic", CellarPropertyType.ReferenceCollection); } collection.Clear(); } } if (record.LocationsRC != null && record.LocationsRC.Count > 0) { collection.AddRange(record.LocationsRC.ToArray()); ExportReferenceList(writer, collection, "Locations", "CmLocation", CellarPropertyType.ReferenceCollection); collection.Clear(); } ExportStText(writer, record.DescriptionOA, "Description"); ExportStText(writer, record.HypothesisOA, "Hypothesis"); ExportAtomicReference(writer, record.StatusRA, "Status", "CmPossibility"); ExportStText(writer, record.DiscussionOA, "Discussion"); if (record.AnthroCodesRC != null && record.AnthroCodesRC.Count > 0) { writer.WriteLine("<Field name=\"AnthroCodes\" type=\"CmAnthroItem\" card=\"collection\">"); foreach (var item in record.AnthroCodesRC) { writer.WriteLine("<Item ws=\"{0}\">{1}</Item>", AnalWsTag, XmlUtils.MakeSafeXml(item.AbbrAndName)); } writer.WriteLine("</Field>"); } ExportStText(writer, record.ConclusionsOA, "Conclusions"); if (record.SupportingEvidenceRS != null && record.SupportingEvidenceRS.Count > 0) { writer.WriteLine("<Field name=\"SupportingEvidence\" type=\"RnGenericRec\" card=\"sequence\">"); foreach (var item in record.SupportingEvidenceRS) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } if (record.CounterEvidenceRS != null && record.CounterEvidenceRS.Count > 0) { writer.WriteLine("<Field name=\"CounterEvidence\" type=\"RnGenericRec\" card=\"sequence\">"); foreach (var item in record.CounterEvidenceRS) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } if (record.SupersededByRC != null && record.SupersededByRC.Count > 0) { writer.WriteLine("<Field name=\"SupersededBy\" type=\"RnGenericRec\" card=\"collection\">"); foreach (var item in record.SupersededByRC) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } if (record.SeeAlsoRC != null && record.SeeAlsoRC.Count > 0) { writer.WriteLine("<Field name=\"SeeAlso\" type=\"RnGenericRec\" card=\"collection\">"); foreach (var item in record.SeeAlsoRC) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } ExportStText(writer, record.ExternalMaterialsOA, "ExternalMaterials"); ExportStText(writer, record.FurtherQuestionsOA, "FurtherQuestions"); ExportStText(writer, record.ResearchPlanOA, "ResearchPlan"); ExportStText(writer, record.PersonalNotesOA, "PersonalNotes"); // The following are in the model, but not used in practice. //ExportStText(writer, record.VersionHistoryOA, "VersionHistory"); //if (record.RemindersRC != null && record.RemindersRC.Count > 0) // MessageBox.Show("Cannot export Reminders from RnGenericRec", "Not yet implemented"); //if (record.CrossReferencesRC != null && record.CrossReferencesRC.Count > 0) // MessageBox.Show("Cannot export CrossReferences from RnGenericRec", "Not yet implemented"); ExportCustomFields(writer, record); if (record.SubRecordsOS != null && record.SubRecordsOS.Count > 0) { writer.WriteLine("<Field name=\"Subentries\" type=\"RnGenericRec\" card=\"sequence\">"); foreach (var subrec in record.SubRecordsOS) { ExportRecord(writer, subrec, level + 1); } writer.WriteLine("</Field>"); } writer.WriteLine("</Entry>"); }
/// <summary> /// Store a value with a "kcptGenDate" type value. Try to handle incomplete data if /// possible, since this value is typed by hand. The user may have substituted /// question marks for the date, and may even the month. /// </summary> private void SetGenDateValue(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { string sData = field.Data.Trim(); if (sData.Length == 0) return; // nothing we can do without data! GenDate gdt; if (!TryParseGenDate(sData, rsf.m_dto.m_rgsFmt, out gdt)) { LogMessage(String.Format(LexTextControls.ksCannotParseGenericDate, sData, field.Marker), field.LineNumber); return; } switch (rsf.m_flid) { case RnGenericRecTags.kflidDateOfEvent: rec.DateOfEvent = gdt; break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); // There's no way to pass a GenDate item into a custom field! break; } }
/// <summary> /// Store a value for either a simple formatted string or a multilingual string. /// </summary> private void SetStringValue(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field, CellarPropertyType cpt) { // REVIEW: SHOULD WE WORRY ABOUT EMBEDDED CHAR MAPPINGS THAT CHANGE THE WRITING SYSTEM // WHEN IT COMES TO ENCODING CONVERSION??? ReconvertEncodedDataIfNeeded(field, rsf.m_sto.m_wsId); ITsString tss = MakeTsString(field.Data, rsf.m_sto.m_ws.Handle); switch (rsf.m_flid) { case RnGenericRecTags.kflidTitle: rec.Title = tss; break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); switch (cpt) { case CellarPropertyType.MultiString: case CellarPropertyType.MultiUnicode: m_cache.DomainDataByFlid.SetMultiStringAlt(rec.Hvo, rsf.m_flid, rsf.m_sto.m_ws.Handle, tss); break; case CellarPropertyType.String: m_cache.DomainDataByFlid.SetString(rec.Hvo, rsf.m_flid, tss); break; } break; } }
/// <summary> /// Store the data for a multi-paragraph text field. /// </summary> private void SetTextContent(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { // REVIEW: SHOULD WE WORRY ABOUT EMBEDDED CHAR MAPPINGS THAT CHANGE THE WRITING SYSTEM // WHEN IT COMES TO ENCODING CONVERSION??? ReconvertEncodedDataIfNeeded(field, rsf.m_txo.m_wsId); List<string> rgsParas = SplitIntoParagraphs(rsf, field); if (rgsParas.Count == 0) return; if (m_factStText == null) m_factStText = m_cache.ServiceLocator.GetInstance<IStTextFactory>(); switch (rsf.m_flid) { case RnGenericRecTags.kflidConclusions: if (rec.ConclusionsOA == null) rec.ConclusionsOA = m_factStText.Create(); StoreTextData(rec.ConclusionsOA, rsf, rgsParas); break; case RnGenericRecTags.kflidDescription: if (rec.DescriptionOA == null) rec.DescriptionOA = m_factStText.Create(); StoreTextData(rec.DescriptionOA, rsf, rgsParas); break; case RnGenericRecTags.kflidDiscussion: if (rec.DiscussionOA == null) rec.DiscussionOA = m_factStText.Create(); StoreTextData(rec.DiscussionOA, rsf, rgsParas); break; case RnGenericRecTags.kflidExternalMaterials: if (rec.ExternalMaterialsOA == null) rec.ExternalMaterialsOA = m_factStText.Create(); StoreTextData(rec.ExternalMaterialsOA, rsf, rgsParas); break; case RnGenericRecTags.kflidFurtherQuestions: if (rec.FurtherQuestionsOA == null) rec.FurtherQuestionsOA = m_factStText.Create(); StoreTextData(rec.FurtherQuestionsOA, rsf, rgsParas); break; case RnGenericRecTags.kflidHypothesis: if (rec.HypothesisOA == null) rec.HypothesisOA = m_factStText.Create(); StoreTextData(rec.HypothesisOA, rsf, rgsParas); break; case RnGenericRecTags.kflidPersonalNotes: if (rec.PersonalNotesOA == null) rec.PersonalNotesOA = m_factStText.Create(); StoreTextData(rec.PersonalNotesOA, rsf, rgsParas); break; case RnGenericRecTags.kflidResearchPlan: if (rec.ResearchPlanOA == null) rec.ResearchPlanOA = m_factStText.Create(); StoreTextData(rec.ResearchPlanOA, rsf, rgsParas); break; case RnGenericRecTags.kflidVersionHistory: if (rec.VersionHistoryOA == null) rec.VersionHistoryOA = m_factStText.Create(); StoreTextData(rec.VersionHistoryOA, rsf, rgsParas); break; default: // Handle custom field (don't think any can exist yet, but...) Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); IStText text; int hvo = m_cache.DomainDataByFlid.get_ObjectProp(rec.Hvo, rsf.m_flid); if (hvo == 0) { text = m_factStText.Create(); m_cache.DomainDataByFlid.SetObjProp(rec.Hvo, rsf.m_flid, text.Hvo); } else { if (m_repoStText == null) m_repoStText = m_cache.ServiceLocator.GetInstance<IStTextRepository>(); text = m_repoStText.GetObject(hvo); } StoreTextData(text, rsf, rgsParas); break; } }
internal IRnGenericRec ChooseNewOwner(IRnGenericRec[] records, string sTitle) { var helpTopic = "khtpDataNotebook-ChooseOwnerOfDemotedRecord"; XCore.PersistenceProvider persistProvider = new PersistenceProvider(m_mediator.PropertyTable); var labels = ObjectLabel.CreateObjectLabels(m_cache, records.Cast<ICmObject>(), "ShortName", m_cache.WritingSystemFactory.GetStrFromWs(m_cache.DefaultAnalWs)); using (var dlg = new ReallySimpleListChooser(persistProvider, labels, String.Empty, m_mediator.HelpTopicProvider)) { dlg.Text = sTitle; dlg.SetHelpTopic(helpTopic); if (dlg.ShowDialog() == DialogResult.OK) return dlg.SelectedObject as IRnGenericRec; } return null; }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { if (DialogResult == DialogResult.OK) { if (string.IsNullOrEmpty(m_titleTextBox.Text)) { e.Cancel = true; MessageBox.Show(this, LexTextControls.ksFillInTitle, LexTextControls.ksMissingInformation, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } using (new WaitCursor(this)) { UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateRecord, LexTextControls.ksRedoCreateRecord, m_cache.ActionHandlerAccessor, () => { var recFactory = m_cache.ServiceLocator.GetInstance<IRnGenericRecFactory>(); int posHvo = ((HvoTreeNode) m_typeCombo.SelectedNode).Hvo; ICmPossibility type = m_cache.ServiceLocator.GetInstance<ICmPossibilityRepository>().GetObject(posHvo); switch (m_owner.ClassID) { case RnResearchNbkTags.kClassId: m_newRecord = recFactory.Create((IRnResearchNbk) m_owner, m_titleTextBox.Tss, type); break; case RnGenericRecTags.kClassId: m_newRecord = recFactory.Create((IRnGenericRec) m_owner, m_titleTextBox.Tss, type); break; } }); } } base.OnClosing(e); }
internal static bool NotebookRecordRefersToThisText(IText text, out IRnGenericRec referringRecord) { referringRecord = null; if (text == null) throw new ArgumentException("Don't call this unless the CurrentSlice.Object is a Text."); referringRecord = text.AssociatedNotebookRecord; return referringRecord != null; }
private void CollectRecords(IRnGenericRec rec, HashSet<IRnGenericRec> records) { records.Add(rec); foreach (var subrec in rec.SubRecordsOS) CollectRecords(subrec, records); }
/// <summary> /// Creates a new record with the specified record as the owner. /// </summary> /// <param name="record">The record.</param> /// <param name="title">The title.</param> /// <param name="type">The type.</param> /// <returns></returns> public IRnGenericRec Create(IRnGenericRec record, ITsString title, ICmPossibility type) { return Create(record.SubRecordsOS, title, type); }
private void ExportRecord(TextWriter writer, IRnGenericRec record, int level) { writer.WriteLine( "<Entry level=\"{0}\" dateCreated=\"{1}\" dateModified=\"{2}\" guid=\"{3}\">", level, record.DateCreated.ToString("yyyy-MM-ddThh:mm:ss"), record.DateModified.ToString("yyyy-MM-ddThh:mm:ss"), record.Guid); ExportString(writer, record.Title, "Title"); ExportAtomicReference(writer, record.TypeRA, "Type", "CmPossibility"); List<ICmPossibility> collection = new List<ICmPossibility>(); collection.AddRange(record.RestrictionsRC); ExportReferenceList(writer, collection, "Restrictions", "CmPossibility", CellarPropertyType.ReferenceCollection); collection.Clear(); if (!record.DateOfEvent.IsEmpty) { writer.WriteLine("<Field name=\"DateOfEvent\" type=\"GenDate\" card=\"atomic\">"); writer.WriteLine("<Item ws=\"{0}\">{1}</Item>", UserWsTag, XmlUtils.MakeSafeXml(record.DateOfEvent.ToXMLExportShortString())); writer.WriteLine("</Field>"); } collection.AddRange(record.TimeOfEventRC); ExportReferenceList(writer, collection, "TimeOfEvent", "CmPossibility", CellarPropertyType.ReferenceCollection); collection.Clear(); collection.AddRange(record.ResearchersRC.ToArray()); ExportReferenceList(writer, collection, "Researchers", "CmPerson", CellarPropertyType.ReferenceCollection); collection.Clear(); collection.AddRange(record.SourcesRC.ToArray()); ExportReferenceList(writer, collection, "Sources", "CmPerson", CellarPropertyType.ReferenceCollection); collection.Clear(); ExportAtomicReference(writer, record.ConfidenceRA, "Confidence", "CmPossibility"); if (record.ParticipantsOC != null && record.ParticipantsOC.Count > 0) { foreach (var part in record.ParticipantsOC) { collection.AddRange(part.ParticipantsRC.ToArray()); if (part.RoleRA != null) { int wsRole; ITsString tssRole = part.RoleRA.Name.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsRole); ExportReferenceList(writer, collection, tssRole.Text, "RnRoledPartic", CellarPropertyType.ReferenceCollection); } else { ExportReferenceList(writer, collection, "Participants", "RnRoledPartic", CellarPropertyType.ReferenceCollection); } collection.Clear(); } } if (record.LocationsRC != null && record.LocationsRC.Count > 0) { collection.AddRange(record.LocationsRC.ToArray()); ExportReferenceList(writer, collection, "Locations", "CmLocation", CellarPropertyType.ReferenceCollection); collection.Clear(); } ExportStText(writer, record.DescriptionOA, "Description"); ExportStText(writer, record.HypothesisOA, "Hypothesis"); ExportAtomicReference(writer, record.StatusRA, "Status", "CmPossibility"); ExportStText(writer, record.DiscussionOA, "Discussion"); if (record.AnthroCodesRC != null && record.AnthroCodesRC.Count > 0) { writer.WriteLine("<Field name=\"AnthroCodes\" type=\"CmAnthroItem\" card=\"collection\">"); foreach (var item in record.AnthroCodesRC) writer.WriteLine("<Item ws=\"{0}\">{1}</Item>", AnalWsTag, XmlUtils.MakeSafeXml(item.AbbrAndName)); writer.WriteLine("</Field>"); } ExportStText(writer, record.ConclusionsOA, "Conclusions"); if (record.SupportingEvidenceRS != null && record.SupportingEvidenceRS.Count > 0) { writer.WriteLine("<Field name=\"SupportingEvidence\" type=\"RnGenericRec\" card=\"sequence\">"); foreach (var item in record.SupportingEvidenceRS) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } if (record.CounterEvidenceRS != null && record.CounterEvidenceRS.Count > 0) { writer.WriteLine("<Field name=\"CounterEvidence\" type=\"RnGenericRec\" card=\"sequence\">"); foreach (var item in record.CounterEvidenceRS) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } if (record.SupersededByRC != null && record.SupersededByRC.Count > 0) { writer.WriteLine("<Field name=\"SupersededBy\" type=\"RnGenericRec\" card=\"collection\">"); foreach (var item in record.SupersededByRC) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } if (record.SeeAlsoRC != null && record.SeeAlsoRC.Count > 0) { writer.WriteLine("<Field name=\"SeeAlso\" type=\"RnGenericRec\" card=\"collection\">"); foreach (var item in record.SeeAlsoRC) { writer.WriteLine("<Item guid=\"{0}\" ws=\"{1}\">{2}</Item>", item.Guid, AnalWsTag, GetLinkLabelForRecord(item)); } writer.WriteLine("</Field>"); } ExportStText(writer, record.ExternalMaterialsOA, "ExternalMaterials"); ExportStText(writer, record.FurtherQuestionsOA, "FurtherQuestions"); ExportStText(writer, record.ResearchPlanOA, "ResearchPlan"); ExportStText(writer, record.PersonalNotesOA, "PersonalNotes"); // The following are in the model, but not used in practice. //ExportStText(writer, record.VersionHistoryOA, "VersionHistory"); //if (record.RemindersRC != null && record.RemindersRC.Count > 0) // MessageBox.Show("Cannot export Reminders from RnGenericRec", "Not yet implemented"); //if (record.CrossReferencesRC != null && record.CrossReferencesRC.Count > 0) // MessageBox.Show("Cannot export CrossReferences from RnGenericRec", "Not yet implemented"); ExportCustomFields(writer, record); if (record.SubRecordsOS != null && record.SubRecordsOS.Count > 0) { writer.WriteLine("<Field name=\"Subentries\" type=\"RnGenericRec\" card=\"sequence\">"); foreach (var subrec in record.SubRecordsOS) ExportRecord(writer, subrec, level + 1); writer.WriteLine("</Field>"); } writer.WriteLine("</Entry>"); }
public void LoadData() { // Get the language project as an FDO object ILangProject lp = m_fdoCache.LangProject; // Use it to get the HVO of the data notebook, but without making an FDO object // and thus loading data. Assert.IsTrue(m_sda.get_IsPropInCache(lp.Hvo, (int)LangProject.LangProjectTags.kflidResearchNotebook, (int)CellarModuleDefns.kcptOwningAtom, 0), "LP notebook loaded by FDO"); int hvoNotebook = m_fdoCache.GetObjProperty(lp.Hvo, (int)LangProject.LangProjectTags.kflidResearchNotebook); Assert.IsFalse(m_sda.get_IsPropInCache(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, (int)CellarModuleDefns.kcptOwningCollection, 0), "Nb records not loaded"); // Do a simple pre-load to get the records. IVwDataSpec dts = VwDataSpecClass.Create(); // Request loading the title of each record. (Note that currently we must make // an entry for each concrete class; making one for the base class does not work.) dts.AddField(RnAnalysis.kClassId, (int)RnGenericRec.RnGenericRecTags.kflidTitle, FldType.kftString, m_fdoCache.LanguageWritingSystemFactoryAccessor, 0); dts.AddField(RnEvent.kClassId, (int)RnGenericRec.RnGenericRecTags.kflidTitle, FldType.kftString, m_fdoCache.LanguageWritingSystemFactoryAccessor, 0); int[] clsids = new int[1]; clsids[0] = RnResearchNbk.kClassId; int[] hvos = new int[1]; hvos[0] = hvoNotebook; m_da.LoadData(hvos, clsids, hvos.Length, dts, null, true); Assert.IsTrue(m_sda.get_IsPropInCache(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, (int)CellarModuleDefns.kcptOwningCollection, 0), "Nb records are loaded"); int chvoRecs = m_sda.get_VecSize(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords); // Be careful what we assert...don't want it too dependent on the exact data. // Should be OK to assume at least a few records. Assert.IsTrue(chvoRecs > 4, "at least 4 recs"); int hvoRec3 = m_sda.get_VecItem(hvoNotebook, (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, 3); Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidTitle, (int)CellarModuleDefns.kcptString, 0), "Got title of rec 3"); ITsString qtssRec3Title = m_sda.get_StringProp(hvoRec3, (int)RnGenericRec.RnGenericRecTags.kflidTitle); // Now get the info through FDO ICmObject objRec3 = CmObject.CreateFromDBObject(m_fdoCache, hvoRec3); Assert.IsTrue(objRec3 is IRnGenericRec, "object of correct type"); IRnGenericRec grRec3 = (IRnGenericRec)objRec3; // I'd prefer to use full ITsString equality test, but not sure how to get // a regular ITsString from FDO obj. Assert.AreEqual(qtssRec3Title.Text, grRec3.Title.Text, "two ways to retrieve R3 title match"); }
private bool StoreSource(IRnGenericRec rec, RnSfMarker rsf, string sData) { List<string> rgsHier = SplitForSubitems(rsf, sData); if (rgsHier == null || rgsHier.Count == 0) { ICmPerson def = rsf.m_tlo.m_default as ICmPerson; if (def != null && !rec.SourcesRC.Contains(def)) rec.SourcesRC.Add(def); return true; } if (m_mapPeople.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.PeopleOA.PossibilitiesOS, m_mapPeople); ICmPossibility poss = FindPossibilityOrNull(rgsHier, m_mapPeople); if (poss != null) { if (!rec.SourcesRC.Contains(poss as ICmPerson)) rec.SourcesRC.Add(poss as ICmPerson); return true; } else if (rsf.m_tlo.m_fIgnoreNewStuff) { return false; } else { ICmPerson item = CreateNewPerson(rgsHier); if (item != null) rec.SourcesRC.Add(item); return true; } }
/// <summary> /// Store the information needed to make any cross reference links after all the records /// have been created. /// </summary> private void StoreLinkData(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { if (String.IsNullOrEmpty(field.Data)) return; var pend = new PendingLink { Marker = rsf, Field = field, Record = rec }; m_pendingLinks.Add(pend); }
private bool StoreTimeOfEvent(IRnGenericRec rec, RnSfMarker rsf, string sData) { List<string> rgsHier = SplitForSubitems(rsf, sData); if (rgsHier == null || rgsHier.Count == 0) { if (rsf.m_tlo.m_default != null && !rec.TimeOfEventRC.Contains(rsf.m_tlo.m_default)) rec.TimeOfEventRC.Add(rsf.m_tlo.m_default); return true; } if (m_mapTimeOfDay.Count == 0) FillPossibilityMap(rsf, m_cache.LangProject.TimeOfDayOA.PossibilitiesOS, m_mapTimeOfDay); ICmPossibility poss = FindPossibilityOrNull(rgsHier, m_mapTimeOfDay); if (poss != null) { if (!rec.TimeOfEventRC.Contains(poss)) rec.TimeOfEventRC.Add(poss); return true; } else if (rsf.m_tlo.m_fIgnoreNewStuff) { return false; } else { ICmPossibility item = CreateNewTimeOfDay(rgsHier); if (item != null) rec.TimeOfEventRC.Add(item); return true; } }
private void ExportCustomFields(TextWriter writer, IRnGenericRec record) { ISilDataAccessManaged sda = m_cache.DomainDataByFlid as ISilDataAccessManaged; Debug.Assert(sda != null); foreach (int flid in m_customFlids) { string fieldName = m_mdc.GetFieldName(flid); bool fHandled = false; ITsString tss; string s; CellarPropertyType cpt = (CellarPropertyType)m_mdc.GetFieldType(flid); switch (cpt) { case CellarPropertyType.Boolean: break; case CellarPropertyType.Integer: break; case CellarPropertyType.Numeric: break; case CellarPropertyType.Float: break; case CellarPropertyType.Time: break; case CellarPropertyType.Guid: break; case CellarPropertyType.Image: case CellarPropertyType.Binary: break; case CellarPropertyType.GenDate: break; case CellarPropertyType.String: tss = sda.get_StringProp(record.Hvo, flid); if (tss != null && tss.Text != null) { ExportString(writer, tss, fieldName); } fHandled = true; break; case CellarPropertyType.MultiString: case CellarPropertyType.MultiUnicode: ITsMultiString tms = sda.get_MultiStringProp(record.Hvo, flid); int cch = 0; for (int i = 0; i < tms.StringCount; ++i) { int ws; tss = tms.GetStringFromIndex(i, out ws); cch += tss.Length; if (cch > 0) { break; } } if (cch > 0) { writer.WriteLine("<Field name=\"{0}\" type=\"MultiString\">", fieldName); for (int i = 0; i < tms.StringCount; ++i) { int ws; tss = tms.GetStringFromIndex(i, out ws); if (tss != null && tss.Length > 0) { if (cpt == CellarPropertyType.MultiString) { writer.WriteLine(TsStringUtils.GetXmlRep(tss, m_cache.WritingSystemFactory, ws, true)); } else { writer.WriteLine("<AUni ws=\"{0}\">{1}</AUni>", m_cache.WritingSystemFactory.GetStrFromWs(ws), XmlUtils.MakeSafeXml(tss.Text)); } } } writer.WriteLine("</Field>"); } fHandled = true; break; case CellarPropertyType.Unicode: break; case CellarPropertyType.ReferenceAtomic: case CellarPropertyType.ReferenceCollection: case CellarPropertyType.ReferenceSequence: { int destClid = m_mdc.GetDstClsId(flid); List <int> rghvoDest = new List <int>(); if (cpt == CellarPropertyType.ReferenceAtomic) { int hvo = sda.get_ObjectProp(record.Hvo, flid); if (hvo != 0) { if (destClid == CmPossibilityTags.kClassId) { ICmPossibility poss = PossibilityRepository.GetObject(hvo); ExportAtomicReference(writer, poss, fieldName, "CmPossibility"); fHandled = true; } else { rghvoDest.Add(hvo); } } else { fHandled = true; } } else { int[] hvos = sda.VecProp(record.Hvo, flid); if (hvos.Length > 0) { if (destClid == CmPossibilityTags.kClassId) { List <ICmPossibility> collection = new List <ICmPossibility>(); foreach (int hvo in hvos) { collection.Add(PossibilityRepository.GetObject(hvo)); } ExportReferenceList(writer, collection, fieldName, "CmPossibility", cpt); fHandled = true; } else { rghvoDest.AddRange(hvos); } } else { fHandled = true; } } if (rghvoDest.Count > 0) { } } break; case CellarPropertyType.OwningAtomic: case CellarPropertyType.OwningCollection: case CellarPropertyType.OwningSequence: { int destClid = m_mdc.GetDstClsId(flid); List <int> rghvoDest = new List <int>(); if (cpt == CellarPropertyType.OwningAtomic) { int hvo = sda.get_ObjectProp(record.Hvo, flid); if (hvo != 0) { if (destClid == StTextTags.kClassId) { IStText text = StTextRepository.GetObject(hvo); ExportStText(writer, text, fieldName); fHandled = true; } else { rghvoDest.Add(hvo); } } else { fHandled = true; } } else { } } break; } if (!fHandled) { } } }
private static bool SetLink(PendingLink pend, IRnGenericRec rec) { switch (pend.Marker.m_flid) { case RnGenericRecTags.kflidCounterEvidence: pend.Record.CounterEvidenceRS.Add(rec); return true; case RnGenericRecTags.kflidSeeAlso: pend.Record.SeeAlsoRC.Add(rec); return true; case RnGenericRecTags.kflidSupersededBy: pend.Record.SupersededByRC.Add(rec); return true; case RnGenericRecTags.kflidSupportingEvidence: pend.Record.SupportingEvidenceRS.Add(rec); return true; } return false; }
/// <summary> /// Store the data for a field that contains one or more references to a possibility /// list. /// </summary> private void SetListReference(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { ReconvertEncodedDataIfNeeded(field, rsf.m_tlo.m_wsId); string sData = field.Data; if (sData == null) sData = String.Empty; sData = ApplyChanges(rsf, sData); sData = sData.Trim(); List<string> rgsData = null; if (sData.Length > 0) { if (rsf.m_tlo.m_fHaveMulti) { rgsData = SplitString(sData, rsf.m_tlo.m_rgsDelimMulti); rgsData = PruneEmptyStrings(rgsData); } else { rgsData = new List<string> {sData}; } } if ((rgsData == null || rgsData.Count == 0) && rsf.m_tlo.m_default == null) { return; } if (rgsData == null) rgsData = new List<string>(); rgsData = ApplyBeforeAndBetween(rsf, rgsData); if (rgsData.Count == 0) rgsData.Add(String.Empty); foreach (var sItem in rgsData) { switch (rsf.m_flid) { case RnGenericRecTags.kflidAnthroCodes: if (!StoreAnthroCode(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidConfidence: if (!StoreConfidence(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidLocations: if (!StoreLocation(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidPhraseTags: if (!StorePhraseTag(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidResearchers: if (!StoreResearcher(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidRestrictions: if (!StoreRestriction(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidSources: if (!StoreSource(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidStatus: if (!StoreStatus(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidTimeOfEvent: if (!StoreTimeOfEvent(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidType: if (!StoreRecType(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidParticipants: if (!StoreParticipant(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); Guid guidList = m_mdc.GetFieldListRoot(rsf.m_flid); if (guidList != Guid.Empty) { if (m_repoList == null) m_repoList = m_cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>(); ICmPossibilityList list = m_repoList.GetObject(guidList); if (list != null) { if (!StoreCustomListRefItem(rec, rsf, sItem, list)) LogCannotFindListItem(sItem, field); break; } } LogMessage( String.Format(LexTextControls.ksCannotFindPossibilityList, field.Marker), field.LineNumber); return; } } }
private void ExportCustomFields(TextWriter writer, IRnGenericRec record) { ISilDataAccessManaged sda = m_cache.DomainDataByFlid as ISilDataAccessManaged; Debug.Assert(sda != null); foreach (int flid in m_customFlids) { string fieldName = m_mdc.GetFieldName(flid); bool fHandled = false; ITsString tss; string s; CellarPropertyType cpt = (CellarPropertyType)m_mdc.GetFieldType(flid); switch (cpt) { case CellarPropertyType.Boolean: break; case CellarPropertyType.Integer: break; case CellarPropertyType.Numeric: break; case CellarPropertyType.Float: break; case CellarPropertyType.Time: break; case CellarPropertyType.Guid: break; case CellarPropertyType.Image: case CellarPropertyType.Binary: break; case CellarPropertyType.GenDate: break; case CellarPropertyType.String: tss = sda.get_StringProp(record.Hvo, flid); if (tss != null && tss.Text != null) ExportString(writer, tss, fieldName); fHandled = true; break; case CellarPropertyType.MultiString: case CellarPropertyType.MultiUnicode: ITsMultiString tms = sda.get_MultiStringProp(record.Hvo, flid); int cch = 0; for (int i = 0; i < tms.StringCount; ++i) { int ws; tss = tms.GetStringFromIndex(i, out ws); cch += tss.Length; if (cch > 0) break; } if (cch > 0) { writer.WriteLine("<Field name=\"{0}\" type=\"MultiString\">", fieldName); for (int i = 0; i < tms.StringCount; ++i) { int ws; tss = tms.GetStringFromIndex(i, out ws); if (tss != null && tss.Length > 0) { if (cpt == CellarPropertyType.MultiString) { writer.WriteLine(TsStringUtils.GetXmlRep(tss, m_cache.WritingSystemFactory, ws, true)); } else { writer.WriteLine("<AUni ws=\"{0}\">{1}</AUni>", m_cache.WritingSystemFactory.GetStrFromWs(ws), XmlUtils.MakeSafeXml(tss.Text)); } } } writer.WriteLine("</Field>"); } fHandled = true; break; case CellarPropertyType.Unicode: break; case CellarPropertyType.ReferenceAtomic: case CellarPropertyType.ReferenceCollection: case CellarPropertyType.ReferenceSequence: { int destClid = m_mdc.GetDstClsId(flid); List<int> rghvoDest = new List<int>(); if (cpt == CellarPropertyType.ReferenceAtomic) { int hvo = sda.get_ObjectProp(record.Hvo, flid); if (hvo != 0) { if (destClid == CmPossibilityTags.kClassId) { ICmPossibility poss = PossibilityRepository.GetObject(hvo); ExportAtomicReference(writer, poss, fieldName, "CmPossibility"); fHandled = true; } else { rghvoDest.Add(hvo); } } else { fHandled = true; } } else { int[] hvos = sda.VecProp(record.Hvo, flid); if (hvos.Length > 0) { if (destClid == CmPossibilityTags.kClassId) { List<ICmPossibility> collection = new List<ICmPossibility>(); foreach (int hvo in hvos) collection.Add(PossibilityRepository.GetObject(hvo)); ExportReferenceList(writer, collection, fieldName, "CmPossibility", cpt); fHandled = true; } else { rghvoDest.AddRange(hvos); } } else { fHandled = true; } } if (rghvoDest.Count > 0) { } } break; case CellarPropertyType.OwningAtomic: case CellarPropertyType.OwningCollection: case CellarPropertyType.OwningSequence: { int destClid = m_mdc.GetDstClsId(flid); List<int> rghvoDest = new List<int>(); if (cpt == CellarPropertyType.OwningAtomic) { int hvo = sda.get_ObjectProp(record.Hvo, flid); if (hvo != 0) { if (destClid == StTextTags.kClassId) { IStText text = StTextRepository.GetObject(hvo); ExportStText(writer, text, fieldName); fHandled = true; } else { rghvoDest.Add(hvo); } } else { fHandled = true; } } else { } } break; } if (!fHandled) { } } }