Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System;5using System.Collections.Generic;6using System.Collections.Specialized;7using System.Diagnostics;8 9namespace Microsoft.PowerShell.Commands.GetCounter10{11    public class CounterSet12    {13        internal CounterSet(string setName,14                            string machineName,15                            PerformanceCounterCategoryType categoryType,16                            string setHelp,17                            ref Dictionary<string, string[]> counterInstanceMapping)18        {19            CounterSetName = setName;20            if (machineName == null || machineName.Length == 0)21            {22                machineName = ".";23            }24            else25            {26                MachineName = machineName;27                if (!MachineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase))28                {29                    MachineName = @"\\" + MachineName;30                }31            }32 33            CounterSetType = categoryType;34            Description = setHelp;35            CounterInstanceMapping = counterInstanceMapping;36        }37 38        public string CounterSetName { get; } = string.Empty;39 40        public string MachineName { get; } = ".";41 42        public PerformanceCounterCategoryType CounterSetType { get; }43 44        public string Description { get; } = string.Empty;45 46        internal Dictionary<string, string[]> CounterInstanceMapping { get; }47 48        public StringCollection Paths49        {50            get51            {52                StringCollection retColl = new();53                foreach (string counterName in this.CounterInstanceMapping.Keys)54                {55                    string path;56                    if (CounterInstanceMapping[counterName].Length != 0)57                    {58                        path = (MachineName == ".") ?59                          ("\\" + CounterSetName + "(*)\\" + counterName) :60                          (MachineName + "\\" + CounterSetName + "(*)\\" + counterName);61                    }62                    else63                    {64                        path = (MachineName == ".") ?65                         ("\\" + CounterSetName + "\\" + counterName) :66                         (MachineName + "\\" + CounterSetName + "\\" + counterName);67                    }68 69                    retColl.Add(path);70                }71 72                return retColl;73            }74        }75 76        public StringCollection PathsWithInstances77        {78            get79            {80                StringCollection retColl = new();81                foreach (string counterName in CounterInstanceMapping.Keys)82                {83                    foreach (string instanceName in CounterInstanceMapping[counterName])84                    {85                        string path = (MachineName == ".") ?86                          ("\\" + CounterSetName + "(" + instanceName + ")\\" + counterName) :87                          (MachineName + "\\" + CounterSetName + "(" + instanceName + ")\\" + counterName);88                        retColl.Add(path);89                    }90                }91 92                return retColl;93            }94        }95    }96}97