Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }