private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int num1 = -1; foreach (TypeOrGroupReference reference in appliesTo.referenceList) { MshExpression ex = (MshExpression)null; if (reference.conditionToken != null) { ex = this._expressionFactory.CreateFromExpressionToken(reference.conditionToken); } int num2 = -1; if (reference is TypeReference typeReference) { num2 = this.MatchTypeIndex(typeReference.name, currentObject, ex); } else { TypeGroupDefinition groupDefinition = DisplayDataQuery.FindGroupDefinition(this._db, (reference as TypeGroupReference).name); if (groupDefinition != null) { num2 = this.ComputeBestMatchInGroup(groupDefinition, currentObject, ex); } } if (num2 == 0) { return(num2); } if (num1 == -1 || num1 < num2) { num1 = num2; } } return(num1); }
/// <summary> /// given an appliesTo list, it finds all the types that are contained (following type /// group references) /// </summary> /// <param name="db">database to use</param> /// <param name="appliesTo">object to lookup</param> /// <returns></returns> internal static AppliesTo GetAllApplicableTypes(TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable allTypes = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference r in appliesTo.referenceList) { // if it is a type reference, just add the type name TypeReference tr = r as TypeReference; if (tr != null) { if (!allTypes.ContainsKey(tr.name)) { allTypes.Add(tr.name, null); } } else { // check if we have a type group reference TypeGroupReference tgr = r as TypeGroupReference; if (tgr == null) { continue; } // find the type group definition the reference points to TypeGroupDefinition tgd = FindGroupDefinition(db, tgr.name); if (tgd == null) { continue; } // we found the group, go over it foreach (TypeReference x in tgd.typeReferenceList) { if (!allTypes.ContainsKey(x.name)) { allTypes.Add(x.name, null); } } } } AppliesTo retVal = new AppliesTo(); foreach (DictionaryEntry x in allTypes) { retVal.AddAppliesToType(x.Key as string); } return(retVal); }
private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int best = BestMatchIndexUndefined; foreach (TypeOrGroupReference r in appliesTo.referenceList) { PSPropertyExpression ex = null; if (r.conditionToken != null) { ex = _expressionFactory.CreateFromExpressionToken(r.conditionToken); } int currentMatch = BestMatchIndexUndefined; TypeReference tr = r as TypeReference; if (tr != null) { // we have a type currentMatch = MatchTypeIndex(tr.name, currentObject, ex); } else { // we have a type group reference TypeGroupReference tgr = r as TypeGroupReference; // find the type group definition the reference points to TypeGroupDefinition tgd = DisplayDataQuery.FindGroupDefinition(_db, tgr.name); if (tgd != null) { // we found the group, see if the group has the type currentMatch = ComputeBestMatchInGroup(tgd, currentObject, ex); } } if (currentMatch == BestMatchIndexPerfect) { return(currentMatch); } if (best == BestMatchIndexUndefined || best < currentMatch) { best = currentMatch; } } return(best); }
private int ComputeBestMatchInGroup(TypeGroupDefinition tgd, PSObject currentObject, MshExpression ex) { int num = -1; int num2 = 0; foreach (TypeReference reference in tgd.typeReferenceList) { int num3 = this.MatchTypeIndex(reference.name, currentObject, ex); if (num3 == 0) { return num3; } if ((num == -1) || (num < num3)) { num = num3; } num2++; } return num; }
private int ComputeBestMatchInGroup(TypeGroupDefinition tgd, PSObject currentObject, MshExpression ex) { int num = -1; int num2 = 0; foreach (TypeReference reference in tgd.typeReferenceList) { int num3 = this.MatchTypeIndex(reference.name, currentObject, ex); if (num3 == 0) { return(num3); } if ((num == -1) || (num < num3)) { num = num3; } num2++; } return(num); }
internal static AppliesTo GetAllApplicableTypes(TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference reference in appliesTo.referenceList) { TypeReference reference2 = reference as TypeReference; if (reference2 != null) { if (!hashtable.ContainsKey(reference2.name)) { hashtable.Add(reference2.name, null); } } else { TypeGroupReference reference3 = reference as TypeGroupReference; if (reference3 != null) { TypeGroupDefinition definition = FindGroupDefinition(db, reference3.name); if (definition != null) { foreach (TypeReference reference4 in definition.typeReferenceList) { if (!hashtable.ContainsKey(reference4.name)) { hashtable.Add(reference4.name, null); } } } } } } AppliesTo to = new AppliesTo(); foreach (DictionaryEntry entry in hashtable) { to.AddAppliesToType(entry.Key as string); } return(to); }
private int ComputeBestMatchInGroup(TypeGroupDefinition tgd, PSObject currentObject, PSPropertyExpression ex) { int best = BestMatchIndexUndefined; int k = 0; foreach (TypeReference tr in tgd.typeReferenceList) { int currentMatch = MatchTypeIndex(tr.name, currentObject, ex); if (currentMatch == BestMatchIndexPerfect) { return(currentMatch); } if (best == BestMatchIndexUndefined || best < currentMatch) { best = currentMatch; } k++; } return(best); }
internal static AppliesTo GetAllApplicableTypes( TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable hashtable = new Hashtable((IEqualityComparer)StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference reference in appliesTo.referenceList) { if (reference is TypeReference typeReference) { if (!hashtable.ContainsKey((object)typeReference.name)) { hashtable.Add((object)typeReference.name, (object)null); } } else if (reference is TypeGroupReference typeGroupReference) { TypeGroupDefinition groupDefinition = DisplayDataQuery.FindGroupDefinition(db, typeGroupReference.name); if (groupDefinition != null) { foreach (TypeReference typeReference in groupDefinition.typeReferenceList) { if (!hashtable.ContainsKey((object)typeReference.name)) { hashtable.Add((object)typeReference.name, (object)null); } } } } } AppliesTo appliesTo1 = new AppliesTo(); foreach (DictionaryEntry dictionaryEntry in hashtable) { appliesTo1.AddAppliesToType(dictionaryEntry.Key as string); } return(appliesTo1); }
private int ComputeBestMatchInGroup( TypeGroupDefinition tgd, PSObject currentObject, MshExpression ex) { int num1 = -1; int num2 = 0; foreach (TypeOrGroupReference typeReference in tgd.typeReferenceList) { int num3 = this.MatchTypeIndex(typeReference.name, currentObject, ex); if (num3 == 0) { return(num3); } if (num1 == -1 || num1 < num3) { num1 = num3; } ++num2; } return(num1); }
private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int num = -1; foreach (TypeOrGroupReference reference in appliesTo.referenceList) { MshExpression ex = null; if (reference.conditionToken != null) { ex = this._expressionFactory.CreateFromExpressionToken(reference.conditionToken); } int num2 = -1; TypeReference reference2 = reference as TypeReference; if (reference2 != null) { num2 = this.MatchTypeIndex(reference2.name, currentObject, ex); } else { TypeGroupReference reference3 = reference as TypeGroupReference; TypeGroupDefinition tgd = DisplayDataQuery.FindGroupDefinition(this._db, reference3.name); if (tgd != null) { num2 = this.ComputeBestMatchInGroup(tgd, currentObject, ex); } } if (num2 == 0) { return(num2); } if ((num == -1) || (num < num2)) { num = num2; } } return(num); }
private void LoadTypeGroupTypeRefs(System.Xml.XmlNode typesNode, TypeGroupDefinition typeGroupDefinition) { using (base.StackFrame(typesNode)) { int num = 0; foreach (System.Xml.XmlNode node in typesNode.ChildNodes) { if (base.MatchNodeName(node, "TypeName")) { using (base.StackFrame(node, num++)) { TypeReference item = new TypeReference { name = base.GetMandatoryInnerText(node) }; typeGroupDefinition.typeReferenceList.Add(item); continue; } } base.ProcessUnknownNode(node); } } }
private void LoadTypeGroup(TypeInfoDataBase db, System.Xml.XmlNode typeGroupNode, int index) { using (base.StackFrame(typeGroupNode, index)) { TypeGroupDefinition typeGroupDefinition = new TypeGroupDefinition(); bool flag = false; foreach (System.Xml.XmlNode node in typeGroupNode.ChildNodes) { if (base.MatchNodeName(node, "Name")) { if (flag) { base.ProcessDuplicateNode(node); } else { flag = true; typeGroupDefinition.name = base.GetMandatoryInnerText(node); } } else if (base.MatchNodeName(node, "Types")) { this.LoadTypeGroupTypeRefs(node, typeGroupDefinition); } else { base.ProcessUnknownNode(node); } } if (!flag) { base.ReportMissingNode("Name"); } db.typeGroupSection.typeGroupDefinitionList.Add(typeGroupDefinition); } }
private void LoadTypeGroupTypeRefs(XmlNode typesNode, TypeGroupDefinition typeGroupDefinition) { using (this.StackFrame(typesNode)) { int typeRefCount = 0; foreach (XmlNode n in typesNode.ChildNodes) { if (MatchNodeName(n, XmlTags.TypeNameNode)) { using (this.StackFrame(n, typeRefCount++)) { TypeReference tr = new TypeReference(); tr.name = GetMandatoryInnerText(n); typeGroupDefinition.typeReferenceList.Add(tr); } // using } else { ProcessUnknownNode(n); } } } }
private void LoadTypeGroup(TypeInfoDataBase db, XmlNode typeGroupNode, int index) { using (this.StackFrame(typeGroupNode, index)) { // create data structure TypeGroupDefinition typeGroupDefinition = new TypeGroupDefinition(); bool nameNodeFound = false; foreach (XmlNode n in typeGroupNode.ChildNodes) { if (MatchNodeName(n, XmlTags.NameNode)) { if (nameNodeFound) { this.ProcessDuplicateNode(n); continue; } nameNodeFound = true; typeGroupDefinition.name = GetMandatoryInnerText(n); } else if (MatchNodeName(n, XmlTags.TypesNode)) { LoadTypeGroupTypeRefs(n, typeGroupDefinition); } else { this.ProcessUnknownNode(n); } } if (!nameNodeFound) { this.ReportMissingNode(XmlTags.NameNode); } // finally add to the list db.typeGroupSection.typeGroupDefinitionList.Add(typeGroupDefinition); } // using }
private int ComputeBestMatchInGroup(TypeGroupDefinition tgd, PSObject currentObject, MshExpression ex) { int best = BestMatchIndexUndefined; int k = 0; foreach (TypeReference tr in tgd.typeReferenceList) { int currentMatch = MatchTypeIndex(tr.name, currentObject, ex); if (currentMatch == BestMatchIndexPerfect) return currentMatch; if (best == BestMatchIndexUndefined || best < currentMatch) { best = currentMatch; } k++; } return best; }