/// <summary> /// Setup DependencyPaths property /// </summary> /// <param name="configuration"></param> /// <param name="cache"></param> protected void SetupDependencies(XmlNode configuration, FdoCache cache) { if (DependencyPaths.Count > 0) { return; // already setup. } string dependsStr = XmlUtils.GetOptionalAttributeValue(configuration, "depends"); if (dependsStr == null || cache == null) { return; } string[] depends = dependsStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string fieldPath in depends) { string[] fieldtree = fieldPath.Split(new char[] { '.' }); List <int> tags = new List <int>(fieldtree.Length); string srcClassName = this.ClassName; foreach (string field in fieldtree) { int tag = cache.GetFlid(0, srcClassName, field); Debug.Assert(tag > 0, String.Format("Invalid dependency field {0} in field path {1}.", field, fieldPath)); if (tag <= 0) { break; } tags.Add(tag); if (tags.Count < fieldtree.Length) { string nextFieldName = fieldtree[tags.Count]; // make dst class the source class of next field uint clsidDst = 0; if (field == "OwnerHVO") { // handle the special case where we need the owning class // this is only possible if srcClassName is has a unique owner. // find the first class that owns the given 'classId' and the given fieldName. clsidDst = GetClassOwningClassAndFieldName(cache, srcClassName, nextFieldName); } else { ClassAndPropInfo cpi = cache.GetClassAndPropInfo((uint)tag); if (ClassHasField(cache, cache.GetClassName(cpi.signatureClsid), nextFieldName)) { clsidDst = cpi.signatureClsid; } else if (cpi.isAbstract) { // find a subclasses that could refer to the nextFieldName. clsidDst = GetSubclassOwningNextField(cache, tag, nextFieldName); } } srcClassName = cache.GetClassName(clsidDst); } } m_fieldPaths.Add(tags); } }
/// <summary> /// Setup DependencyPaths property /// </summary> /// <param name="configuration"></param> /// <param name="cache"></param> protected void SetupDependencies(XmlNode configuration, FdoCache cache) { if (DependencyPaths.Count > 0) return; // already setup. string dependsStr = XmlUtils.GetOptionalAttributeValue(configuration, "depends"); if (dependsStr == null || cache == null) return; string[] depends = dependsStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string fieldPath in depends) { string[] fieldtree = fieldPath.Split(new char[] { '.' }); List<int> tags = new List<int>(fieldtree.Length); string srcClassName = this.ClassName; foreach (string field in fieldtree) { int tag = cache.GetFlid(0, srcClassName, field); Debug.Assert(tag > 0, String.Format("Invalid dependency field {0} in field path {1}.", field, fieldPath)); if (tag <= 0) break; tags.Add(tag); if (tags.Count < fieldtree.Length) { string nextFieldName = fieldtree[tags.Count]; // make dst class the source class of next field uint clsidDst = 0; if (field == "OwnerHVO") { // handle the special case where we need the owning class // this is only possible if srcClassName is has a unique owner. // find the first class that owns the given 'classId' and the given fieldName. clsidDst = GetClassOwningClassAndFieldName(cache, srcClassName, nextFieldName); } else { ClassAndPropInfo cpi = cache.GetClassAndPropInfo((uint)tag); if (ClassHasField(cache, cache.GetClassName(cpi.signatureClsid), nextFieldName)) { clsidDst = cpi.signatureClsid; } else if (cpi.isAbstract) { // find a subclasses that could refer to the nextFieldName. clsidDst = GetSubclassOwningNextField(cache, tag, nextFieldName); } } srcClassName = cache.GetClassName(clsidDst); } } m_fieldPaths.Add(tags); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Use to try to reload the ws from the configuration node. Default writing systems such as "vernacular" or "analysis" /// may change after initialization. (cf. LT-4882). /// </summary> /// <param name="cache">The cache.</param> /// <param name="hvo">the object we want to find the ws for magic writing systems (e.g. for best analysis)</param> /// <param name="defaultWsId">ws we will use if we can't find one.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected virtual int WsId(FdoCache cache, int hvo, int defaultWsId) { int ws = 0; if (m_configuration != null && cache != null) { if (hvo != 0) { int flid = cache.GetFlid(hvo, ClassName, FieldName); ws = LangProject.GetWritingSystem(m_configuration, cache, null, hvo, flid, defaultWsId); } else { ws = LangProject.GetWritingSystem(m_configuration, cache, null, 0); } } if (ws == 0) { ws = defaultWsId; } return(ws); }
private static int GetFlidFromClassDotName(FdoCache cache, string descriptor) { string[] parts = descriptor.Trim().Split('.'); if (parts.Length != 2) throw new ConfigurationException("atomicFlatListItem field must be class.field"); int flid = cache.GetFlid(0, parts[0], parts[1]); if (flid == 0) throw new ConfigurationException("Don't recognize atomicFlatListItem field " + descriptor); return flid; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Use to try to reload the ws from the configuration node. Default writing systems such as "vernacular" or "analysis" /// may change after initialization. (cf. LT-4882). /// </summary> /// <param name="cache">The cache.</param> /// <param name="hvo">the object we want to find the ws for magic writing systems (e.g. for best analysis)</param> /// <param name="defaultWsId">ws we will use if we can't find one.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected virtual int WsId(FdoCache cache, int hvo, int defaultWsId) { int ws = 0; if (m_configuration != null && cache != null) { if (hvo != 0) { int flid = cache.GetFlid(hvo, ClassName, FieldName); ws = LangProject.GetWritingSystem(m_configuration, cache, null, hvo, flid, defaultWsId); } else { ws = LangProject.GetWritingSystem(m_configuration, cache, null, 0); } } if (ws == 0) ws = defaultWsId; return ws; }
private static bool ClassHasField(FdoCache cache, string className, string fieldName) { return cache.GetFlid(0, className, fieldName) > 0; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This is a simplified version of XmlVc.GetFlid. /// It does not look for a flid attr, nor try to cache the result. /// It looks for a "field" property, and optionally a "class" one, and uses them /// (or the class of hvo, if "class" is missing) to figure the flid. /// Virtual properties are assumed already created. /// </summary> /// <param name="fdoCache">The fdo cache.</param> /// <param name="frag">The frag.</param> /// <param name="hvo">The hvo.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ static int GetFlid(FdoCache fdoCache, XmlNode frag, int hvo) { string stClassName = XmlUtils.GetOptionalAttributeValue(frag,"class"); string stFieldName = XmlUtils.GetManditoryAttributeValue(frag,"field"); return fdoCache.GetFlid(hvo, stClassName, stFieldName); }
private static bool ClassHasField(FdoCache cache, string className, string fieldName) { return(cache.GetFlid(0, className, fieldName) > 0); }