예제 #1
0
        //
        // ProcessListSetPerMachine() helper lists counter sets on a machine.
        // NOTE: machine argument should be NULL for the local machine
        //
        private void ProcessListSetPerMachine(string machine)
        {
            StringCollection counterSets = new StringCollection();
            uint res = _pdhHelper.EnumObjects(machine, ref counterSets);
            if (res != 0)
            {
                //add an error message
                string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoCounterSetsOnComputer"), machine, res);
                Exception exc = new Exception(msg);
                WriteError(new ErrorRecord(exc, "NoCounterSetsOnComputer", ErrorCategory.InvalidResult, machine));
                return;
            }

            CultureInfo culture = Thread.CurrentThread.CurrentUICulture;
            List<Tuple<char, char>> characterReplacementList = null;
            StringCollection validPaths = new StringCollection();

            _cultureAndSpecialCharacterMap.TryGetValue(culture.LCID, out characterReplacementList);

            foreach (string pattern in _listSet)
            {
                bool bMatched = false;
                string normalizedPattern = pattern;

                if (characterReplacementList != null)
                {
                    foreach (Tuple<char, char> pair in characterReplacementList)
                    {
                        normalizedPattern = normalizedPattern.Replace(pair.Item1, pair.Item2);
                    }
                }

                WildcardPattern wildLogPattern = new WildcardPattern(normalizedPattern, WildcardOptions.IgnoreCase);

                foreach (string counterSet in counterSets)
                {
                    if (!wildLogPattern.IsMatch(counterSet))
                    {
                        continue;
                    }

                    StringCollection counterSetCounters = new StringCollection();
                    StringCollection counterSetInstances = new StringCollection();

                    res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances);
                    if (res == PdhResults.PDH_ACCESS_DENIED)
                    {
                        string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterSetEnumAccessDenied"), counterSet);
                        Exception exc = new Exception(msg);
                        WriteError(new ErrorRecord(exc, "CounterSetEnumAccessDenied", ErrorCategory.InvalidResult, null));
                        continue;
                    }
                    else if (res != 0)
                    {
                        ReportPdhError(res, false);
                        continue;
                    }

                    string[] instanceArray = new string[counterSetInstances.Count];
                    int i = 0;
                    foreach (string instance in counterSetInstances)
                    {
                        instanceArray[i++] = instance;
                    }

                    //
                    // Special case: no instances present: change to * to create a valid paths
                    //
                    if (instanceArray.Length == 1 &&
                        instanceArray[0].Length == 0)
                    {
                        instanceArray[0] = "*";
                    }

                    Dictionary<string, string[]> counterInstanceMapping = new Dictionary<string, string[]>();
                    foreach (string counter in counterSetCounters)
                    {
                        if (!counterInstanceMapping.ContainsKey(counter))
                        {
                            counterInstanceMapping.Add(counter, instanceArray);
                        }
                    }

                    PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.Unknown;
                    if (counterSetInstances.Count > 1)
                    {
                        categoryType = PerformanceCounterCategoryType.MultiInstance;
                    }
                    else //if (counterSetInstances.Count == 1) //???
                    {
                        categoryType = PerformanceCounterCategoryType.SingleInstance;
                    }

                    string setHelp = _pdhHelper.GetCounterSetHelp(machine, counterSet);

                    CounterSet setObj = new CounterSet(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping);
                    WriteObject(setObj);
                    bMatched = true;
                }

                if (!bMatched)
                {
                    string msg = _resourceMgr.GetString("NoMatchingCounterSetsFound");
                    Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg,
                      machine ?? "localhost", normalizedPattern));
                    WriteError(new ErrorRecord(exc, "NoMatchingCounterSetsFound", ErrorCategory.ObjectNotFound, null));
                }
            }
        }
예제 #2
0
 private void ProcessListSetPerMachine(string machine)
 {
     StringCollection objectNames = new StringCollection();
     long res = this._pdhHelper.EnumObjects(machine, ref objectNames);
     if (res != 0)
     {
         Exception exception = new Exception(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("NoCounterSetsOnComputer"), new object[] { machine, res }));
         base.WriteError(new ErrorRecord(exception, "NoCounterSetsOnComputer", ErrorCategory.InvalidResult, machine));
     }
     else
     {
         new StringCollection();
         foreach (string str2 in this._listSet)
         {
             bool flag = false;
             WildcardPattern pattern = new WildcardPattern(str2, WildcardOptions.IgnoreCase);
             foreach (string str3 in objectNames)
             {
                 if (pattern.IsMatch(str3))
                 {
                     StringCollection counterNames = new StringCollection();
                     StringCollection instanceNames = new StringCollection();
                     res = this._pdhHelper.EnumObjectItems(machine, str3, ref counterNames, ref instanceNames);
                     if (res == 0xc0000bdbL)
                     {
                         Exception exception2 = new Exception(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("CounterSetEnumAccessDenied"), new object[] { str3 }));
                         base.WriteError(new ErrorRecord(exception2, "CounterSetEnumAccessDenied", ErrorCategory.InvalidResult, null));
                     }
                     else if (res != 0)
                     {
                         this.ReportPdhError(res, false);
                     }
                     else
                     {
                         string[] strArray = new string[instanceNames.Count];
                         int num2 = 0;
                         foreach (string str5 in instanceNames)
                         {
                             strArray[num2++] = str5;
                         }
                         if ((strArray.Length == 1) && (strArray[0].Length == 0))
                         {
                             strArray[0] = "*";
                         }
                         Dictionary<string, string[]> counterInstanceMapping = new Dictionary<string, string[]>();
                         foreach (string str6 in counterNames)
                         {
                             if (!counterInstanceMapping.ContainsKey(str6))
                             {
                                 counterInstanceMapping.Add(str6, strArray);
                             }
                         }
                         PerformanceCounterCategoryType unknown = PerformanceCounterCategoryType.Unknown;
                         if (instanceNames.Count > 1)
                         {
                             unknown = PerformanceCounterCategoryType.MultiInstance;
                         }
                         else
                         {
                             unknown = PerformanceCounterCategoryType.SingleInstance;
                         }
                         string counterSetHelp = this._pdhHelper.GetCounterSetHelp(machine, str3);
                         CounterSet sendToPipeline = new CounterSet(str3, machine, unknown, counterSetHelp, ref counterInstanceMapping);
                         base.WriteObject(sendToPipeline);
                         flag = true;
                     }
                 }
             }
             if (!flag)
             {
                 string format = this._resourceMgr.GetString("NoMatchingCounterSetsFound");
                 Exception exception3 = new Exception(string.Format(CultureInfo.InvariantCulture, format, new object[] { (machine == null) ? "localhost" : machine, str2 }));
                 base.WriteError(new ErrorRecord(exception3, "NoMatchingCounterSetsFound", ErrorCategory.ObjectNotFound, null));
             }
         }
     }
 }
예제 #3
0
 private void ProcessListSet()
 {
     long res = this._pdhHelper.ConnectToDataSource(this._resolvedPaths);
     if (res != 0)
     {
         this.ReportPdhError(res, true);
     }
     else
     {
         StringCollection machineNames = new StringCollection();
         res = this._pdhHelper.EnumBlgFilesMachines(ref machineNames);
         if (res != 0)
         {
             this.ReportPdhError(res, true);
         }
         else
         {
             foreach (string str in machineNames)
             {
                 StringCollection objectNames = new StringCollection();
                 if (this._pdhHelper.EnumObjects(str, ref objectNames) != 0)
                 {
                     break;
                 }
                 new StringCollection();
                 foreach (string str2 in this._listSet)
                 {
                     bool flag = false;
                     WildcardPattern pattern = new WildcardPattern(str2, WildcardOptions.IgnoreCase);
                     foreach (string str3 in objectNames)
                     {
                         if (pattern.IsMatch(str3))
                         {
                             StringCollection counterNames = new StringCollection();
                             StringCollection instanceNames = new StringCollection();
                             res = this._pdhHelper.EnumObjectItems(str, str3, ref counterNames, ref instanceNames);
                             if (res != 0)
                             {
                                 this.ReportPdhError(res, false);
                             }
                             else
                             {
                                 string[] strArray = new string[instanceNames.Count];
                                 int num2 = 0;
                                 foreach (string str4 in instanceNames)
                                 {
                                     strArray[num2++] = str4;
                                 }
                                 Dictionary<string, string[]> counterInstanceMapping = new Dictionary<string, string[]>();
                                 foreach (string str5 in counterNames)
                                 {
                                     counterInstanceMapping.Add(str5, strArray);
                                 }
                                 PerformanceCounterCategoryType unknown = PerformanceCounterCategoryType.Unknown;
                                 if (instanceNames.Count > 1)
                                 {
                                     unknown = PerformanceCounterCategoryType.MultiInstance;
                                 }
                                 else
                                 {
                                     unknown = PerformanceCounterCategoryType.SingleInstance;
                                 }
                                 string counterSetHelp = this._pdhHelper.GetCounterSetHelp(str, str3);
                                 CounterSet sendToPipeline = new CounterSet(str3, str, unknown, counterSetHelp, ref counterInstanceMapping);
                                 base.WriteObject(sendToPipeline);
                                 flag = true;
                             }
                         }
                     }
                     if (!flag)
                     {
                         string format = this._resourceMgr.GetString("NoMatchingCounterSetsInFile");
                         Exception exception = new Exception(string.Format(CultureInfo.InvariantCulture, format, new object[] { CommonUtilities.StringArrayToString(this._resolvedPaths), str2 }));
                         base.WriteError(new ErrorRecord(exception, "NoMatchingCounterSetsInFile", ErrorCategory.ObjectNotFound, null));
                     }
                 }
             }
         }
     }
 }
예제 #4
0
        //
        // ProcessListSet().
        // Does the work to process ListSet parameter set.
        //       
        private void ProcessListSet()
        {
            uint res = _pdhHelper.ConnectToDataSource(_resolvedPaths);
            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }

            StringCollection machineNames = new StringCollection();
            res = _pdhHelper.EnumBlgFilesMachines(ref machineNames);
            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }

            foreach (string machine in machineNames)
            {
                StringCollection counterSets = new StringCollection();
                res = _pdhHelper.EnumObjects(machine, ref counterSets);
                if (res != 0)
                {
                    return;
                }

                StringCollection validPaths = new StringCollection();

                foreach (string pattern in _listSet)
                {
                    bool bMatched = false;

                    WildcardPattern wildLogPattern = new WildcardPattern(pattern, WildcardOptions.IgnoreCase);

                    foreach (string counterSet in counterSets)
                    {
                        if (!wildLogPattern.IsMatch(counterSet))
                        {
                            continue;
                        }


                        StringCollection counterSetCounters = new StringCollection();
                        StringCollection counterSetInstances = new StringCollection();

                        res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances);
                        if (res != 0)
                        {
                            ReportPdhError(res, false);
                            continue;
                        }

                        string[] instanceArray = new string[counterSetInstances.Count];
                        int i = 0;
                        foreach (string instance in counterSetInstances)
                        {
                            instanceArray[i++] = instance;
                        }

                        Dictionary<string, string[]> counterInstanceMapping = new Dictionary<string, string[]>();
                        foreach (string counter in counterSetCounters)
                        {
                            counterInstanceMapping.Add(counter, instanceArray);
                        }

                        PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.Unknown;
                        if (counterSetInstances.Count > 1)
                        {
                            categoryType = PerformanceCounterCategoryType.MultiInstance;
                        }
                        else //if (counterSetInstances.Count == 1) //???
                        {
                            categoryType = PerformanceCounterCategoryType.SingleInstance;
                        }

                        string setHelp = _pdhHelper.GetCounterSetHelp(machine, counterSet);

                        CounterSet setObj = new CounterSet(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping);
                        WriteObject(setObj);
                        bMatched = true;
                    }
                    if (!bMatched)
                    {
                        string msg = _resourceMgr.GetString("NoMatchingCounterSetsInFile");
                        Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg,
                        CommonUtilities.StringArrayToString(_resolvedPaths),
                        pattern));
                        WriteError(new ErrorRecord(exc, "NoMatchingCounterSetsInFile", ErrorCategory.ObjectNotFound, null));
                    }
                }
            }
        }