コード例 #1
0
        private void AnalyzeObjectProperties(PSObject inObj)
        {
            MeasureObjectDictionary <object> dictionary = new MeasureObjectDictionary <object>();

            foreach (string str in this.Property)
            {
                MshExpression        expression = new MshExpression(str);
                List <MshExpression> list       = expression.ResolveNames(inObj);
                if ((list == null) || (list.Count == 0))
                {
                    if (!expression.HasWildCardCharacters)
                    {
                        string key = expression.ToString();
                        this.statistics.EnsureEntry(key);
                    }
                }
                else
                {
                    foreach (MshExpression expression2 in list)
                    {
                        string str3 = expression2.ToString();
                        if (!dictionary.ContainsKey(str3))
                        {
                            List <MshExpressionResult> values = expression2.GetValues(inObj);
                            if ((values != null) && (values.Count != 0))
                            {
                                this.AnalyzeValue(str3, values[0].Result);
                                dictionary[str3] = null;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Analyze an object on a property-by-property basis instead
        /// of as a simple value.
        /// Side effects: Updates statistics.
        /// <param name="inObj">The object to analyze.</param>
        /// </summary>
        private void AnalyzeObjectProperties(PSObject inObj)
        {
            // Keep track of which properties are counted for an
            // input object so that repeated properties won't be
            // counted twice.
            MeasureObjectDictionary <object> countedProperties = new MeasureObjectDictionary <object>();

            // First iterate over the user-specified list of
            // properties...
            foreach (string p in Property)
            {
                MshExpression        expression    = new MshExpression(p);
                List <MshExpression> resolvedNames = expression.ResolveNames(inObj);
                if (resolvedNames == null || resolvedNames.Count == 0)
                {
                    // Insert a blank entry so we can track
                    // property misses in EndProcessing.
                    if (!expression.HasWildCardCharacters)
                    {
                        string propertyName = expression.ToString();
                        _statistics.EnsureEntry(propertyName);
                    }

                    continue;
                }

                // Each property value can potentially refer
                // to multiple properties via globbing. Iterate over
                // the actual property names.
                foreach (MshExpression resolvedName in resolvedNames)
                {
                    string propertyName = resolvedName.ToString();
                    // skip duplicated properties
                    if (countedProperties.ContainsKey(propertyName))
                    {
                        continue;
                    }

                    List <MshExpressionResult> tempExprRes = resolvedName.GetValues(inObj);
                    if (tempExprRes == null || tempExprRes.Count == 0)
                    {
                        // Shouldn't happen - would somehow mean
                        // that the property went away between when
                        // we resolved it and when we tried to get its
                        // value.
                        continue;
                    }

                    AnalyzeValue(propertyName, tempExprRes[0].Result);

                    // Remember resolved propertyNames that have been counted
                    countedProperties[propertyName] = null;
                }
            }
        }