internal void AddAppliesToTypeGroup(string typeGroupName)
        {
            TypeGroupReference tgr = new TypeGroupReference();

            tgr.name = typeGroupName;
            this.referenceList.Add(tgr);
        }
        internal void AddAppliesToTypeGroup (string typeGroupName)
        {
            TypeGroupReference tgr = new TypeGroupReference ();

            tgr.name = typeGroupName;
            this.referenceList.Add (tgr);
        }
Beispiel #3
0
        private static void TraceHelper(ViewDefinition vd, bool isMatched)
        {
            if ((ActiveTracer.Options & PSTraceSourceOptions.WriteLine) != 0)
            {
                foreach (TypeOrGroupReference togr in vd.appliesTo.referenceList)
                {
                    StringBuilder sb = new StringBuilder();
                    TypeReference tr = togr as TypeReference;
                    sb.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
                    if (tr != null)
                    {
                        sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}",
                                        ControlBase.GetControlShapeName(vd.mainControl), vd.name, tr.name);
                    }
                    else
                    {
                        TypeGroupReference tgr = togr as TypeGroupReference;
                        sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}",
                                        ControlBase.GetControlShapeName(vd.mainControl), vd.name, tgr.name);
                    }

                    ActiveTracer.WriteLine(sb.ToString());
                }
            }
        }
        /// <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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 private static void TraceHelper(ViewDefinition vd, bool isMatched)
 {
     if ((ActiveTracer.Options & PSTraceSourceOptions.WriteLine) != PSTraceSourceOptions.None)
     {
         foreach (TypeOrGroupReference reference in vd.appliesTo.referenceList)
         {
             StringBuilder builder    = new StringBuilder();
             TypeReference reference2 = reference as TypeReference;
             builder.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
             if (reference2 != null)
             {
                 builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference2.name });
             }
             else
             {
                 TypeGroupReference reference3 = reference as TypeGroupReference;
                 builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference3.name });
             }
             ActiveTracer.WriteLine(builder.ToString(), new object[0]);
         }
     }
 }
 private static void TraceHelper(ViewDefinition vd, bool isMatched)
 {
     if ((DisplayDataQuery.ActiveTracer.Options & PSTraceSourceOptions.WriteLine) == PSTraceSourceOptions.None)
     {
         return;
     }
     foreach (TypeOrGroupReference reference in vd.appliesTo.referenceList)
     {
         StringBuilder stringBuilder = new StringBuilder();
         TypeReference typeReference = reference as TypeReference;
         stringBuilder.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
         if (typeReference != null)
         {
             stringBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}", (object)ControlBase.GetControlShapeName(vd.mainControl), (object)vd.name, (object)typeReference.name);
         }
         else
         {
             TypeGroupReference typeGroupReference = reference as TypeGroupReference;
             stringBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}", (object)ControlBase.GetControlShapeName(vd.mainControl), (object)vd.name, (object)typeGroupReference.name);
         }
         DisplayDataQuery.ActiveTracer.WriteLine(stringBuilder.ToString(), new object[0]);
     }
 }
Beispiel #9
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);
        }
Beispiel #10
0
        private TypeGroupReference LoadTypeGroupReference(XmlNode n)
        {
            string val = GetMandatoryInnerText(n);

            if (val != null)
            {
                TypeGroupReference tgr = new TypeGroupReference();
                tgr.name = val;
                return tgr;
            }
            return null;
        }