public void DBObjectInstantiation() { CheckDisposed(); // Putting persons in the UsageTypes doesn't really make sense, but for testing purposes // it doesn't matter what we store there as long as it is derived from CmPossibility CmPerson person = new CmPerson(); CmPossibility pos = new CmPossibility(); Cache.LangProject.LexDbOA.UsageTypesOA.PossibilitiesOS.Append(person); Cache.LangProject.LexDbOA.UsageTypesOA.PossibilitiesOS.Append(pos); int khvoAPossibiltyObject = pos.Hvo; int khvoAPersonObject = person.Hvo; Assert.AreEqual("CmPerson", CmPossibility.CreateFromDBObject(Cache, khvoAPersonObject).GetType().Name); Assert.AreEqual("CmPossibility", CmPossibility.CreateFromDBObject(Cache, khvoAPossibiltyObject).GetType().Name); // Now try it not assuming anything about the class type (use the method on CmObject) // CmObject uses a different, less efficient method. Assert.AreEqual("CmPerson", CmObject.CreateFromDBObject(Cache, khvoAPersonObject).GetType().Name); // trying to turn a possibility into a person should throw an exception CmPerson.CreateFromDBObject(Cache, khvoAPossibiltyObject); }
public void ModifyVectors(LangProject lp) { //add a new item to an owned sequence attribute CmAnthroItem a = (CmAnthroItem)lp.AnthroListOA.PossibilitiesOS.Append(new CmAnthroItem()); //add a new item to an owned collection attribute CmOverlay overlay = (CmOverlay)lp.OverlaysOC.Add(new CmOverlay()); //add a new item to a reference collection attribute CmPossibility position = (CmPossibility)lp.PositionsOA.PossibilitiesOS [0]; CmPerson person = (CmPerson)lp.PeopleOA.PossibilitiesOS[0]; person.PositionsRC.Add(position); //move the last item in a sequence to the beginning FdoOwnSeqVector positions = lp.PositionsOA.PossibilitiesOS; position = (CmPossibility)positions[positions.Count - 1]; positions.InsertAt(position, 0); //do the same, without instantiating the object we're moving int hvo = positions.hvoArray[positions.Count - 1]; positions.InsertAt(hvo, 0); }
/// <summary> /// Create a new ICmPossibility instance with the given guid and owner. /// It will be added to the end of the Possibilities list. /// </summary> ICmPerson ICmPersonFactory.Create(Guid guid, ICmPossibilityList owner) { if (owner == null) throw new ArgumentNullException("owner"); int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo(); int flid = m_cache.MetaDataCache.GetFieldId("CmPossibilityList", "Possibilities", false); var retval = new CmPerson(m_cache, hvo, guid); owner.PossibilitiesOS.Add(retval); return retval; }