private ICmPossibilityList GetListFromAttributes(XmlReader xrdr) { string sOwner; ICmObject owner = GetOwnerFromAttribute(xrdr, out sOwner); ICmPossibilityList list; string sField = xrdr.GetAttribute("field"); if (String.IsNullOrEmpty(sField)) { throw new Exception("Missing field attribute for <List> element"); } int flid = m_mdc.GetFieldId2(owner.ClassID, sField, false); if (flid == 0) { throw new Exception(String.Format("Invalid field attribute value for <List> element: {0}", sField)); } int hvoList = m_cache.DomainDataByFlid.get_ObjectProp(owner.Hvo, flid); if (hvoList == 0) { throw new Exception(String.Format("List does not exist for {0} / {1}", sOwner, sField)); } list = m_cache.ServiceLocator.GetInstance <ICmPossibilityListRepository>().GetObject(hvoList); if (list == null) { throw new Exception(String.Format("List does not exist for {0} / {1}", sOwner, sField)); } return(list); }
public void AddModifyDeleteFieldDescription() { FieldDescription fd = new FieldDescription(Cache) { Class = 1, Name = "TESTJUNK___NotPresent", Type = CellarPropertyType.Boolean }; Assert.AreEqual(fd.Custom, 1, "Wrong value for Custom column in new FD."); Assert.AreEqual(0, fd.Id, "new field should not have been assigned a flid yet"); int flid; try { flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true); } catch (LcmInvalidFieldException) { flid = 0; // the new implementation throws instead of returning zero. } Assert.AreEqual(0, flid, "new field should not exist"); fd.UpdateCustomField(); flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true); Assert.AreNotEqual(0, fd.Id, "field should have been assigned a flid"); Assert.AreEqual(fd.Id, flid, "new field should exist"); string hs = "Abandon hope all ye who enter here."; fd.HelpString = hs; fd.UpdateCustomField(); string help = m_mdc.GetFieldHelp(fd.Id); Assert.AreEqual(hs, help, "Help string should have been updated"); fd.MarkForDeletion = true; fd.UpdateCustomField(); try { flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true); } catch (LcmInvalidFieldException) { flid = 0; // the new implementation throws instead of returning zero. } Assert.AreEqual(0, flid, "new field should have been deleted"); }
/// <summary> /// This is more efficient if the client already has the classID specified classID and field name. /// Returns 0 if not found. /// Searches superclasses as well as actual class given. ///</summary> /// <param name='luClid'> </param> /// <param name='bstrFieldName'> </param> /// <param name='fIncludeBaseClasses'> </param> /// <returns></returns> public virtual int GetFieldId2(int luClid, string bstrFieldName, bool fIncludeBaseClasses) { return(m_metaDataCache.GetFieldId2(luClid, bstrFieldName, fIncludeBaseClasses)); }
/// <summary> /// This seems a bit clumsy, but the metadata cache now throws an exception if the class /// id/field name pair isn't valid for GetFieldId2(). So we check first in cases where /// we want a zero if not found. /// </summary> private int GetFlidIfPossible(int clid, string fieldName, IFwMetaDataCacheManaged mdc) { if (!mdc.FieldExists(clid, fieldName, true)) return 0; return mdc.GetFieldId2(clid, fieldName, true); }
/// <summary> /// This seems a bit clumsy, but the metadata cache now throws an exception if the class /// id/field name pair isn't valid for GetFieldId2(). Limiting this to only one throw /// per class/field pair seems a reasonable compromise. To avoid all throws would /// require duplicating much of the metadata cache locally. /// </summary> internal int GetFlidIfPossible(int clid, string fieldName, IFwMetaDataCacheManaged mdc) { string key = fieldName + clid; if (m_setInvalidFields.Contains(key)) return 0; try { int flid = mdc.GetFieldId2(clid, fieldName, true); return flid; } catch { m_setInvalidFields.Add(key); return 0; } }