/// <summary> /// Internal Constructor for named instances (multi-instance counters) /// </summary> /// <param name="instanceName">name for this instance</param> /// <param name="categoryInfo">information about this category</param> /// <param name="enumCounterAttributes">enumerator attributes</param> /// <exception cref="System.NotSupportedException" /> internal CounterHelperImpl(string instanceName, PerformanceCounterCategoryAttribute categoryInfo, Dictionary <T, PerformanceCounterAttribute> enumCounterAttributes) : this(enumCounterAttributes.Count, instanceName) { if ((categoryInfo.InstanceType == PerformanceCounterCategoryType.MultiInstance) && (string.IsNullOrEmpty(instanceName))) { throw new NotSupportedException(Properties.Resources.CounterHelper_MultiInstanceNoInstanceNameErrorMessage); } PerformanceCounter performanceCounter, performanceCounterBase = null; Dictionary <T, PerformanceCounterAttribute> .Enumerator enumerator = enumCounterAttributes.GetEnumerator(); while (enumerator.MoveNext()) { if (categoryInfo.InstanceType == PerformanceCounterCategoryType.MultiInstance) { performanceCounter = new PerformanceCounter(categoryInfo.Name, enumerator.Current.Value.Name, this._instanceName, false); } else { performanceCounter = new PerformanceCounter(categoryInfo.Name, enumerator.Current.Value.Name, false); } PerformanceCounterType?baseType = PerformanceHelper.GetBaseType(performanceCounter.CounterType); if (baseType != null) { if (categoryInfo.InstanceType == PerformanceCounterCategoryType.MultiInstance) { performanceCounterBase = new PerformanceCounter(categoryInfo.Name, PerformanceHelper.GetCounterNameForBaseType(enumerator.Current.Value.Name), instanceName, false); } else { performanceCounterBase = new PerformanceCounter(categoryInfo.Name, PerformanceHelper.GetCounterNameForBaseType(enumerator.Current.Value.Name), false); } performanceCounterBase.RawValue = PerformanceHelper.getInitialValue(performanceCounter.CounterType); } else { performanceCounterBase = null; } PerformanceCounterContainer performanceCounterContainer = new PerformanceCounterContainer(performanceCounter, performanceCounterBase, enumerator.Current.Value.IsBaseAutoIncreased); this._counters.Add(enumerator.Current.Key, performanceCounterContainer); } }
/// <summary> /// Internal Constructor for not named instances /// </summary> /// <param name="categoryInfo">information about this category</param> /// <param name="enumCounterAttributes">enumerator attributes</param> /// <exception cref="System.NotSupportedException" /> internal CounterHelperImpl(PerformanceCounterCategoryAttribute categoryInfo, Dictionary <T, PerformanceCounterAttribute> enumCounterAttributes) : this(null, categoryInfo, enumCounterAttributes) { }
/// <summary> /// Create a CounterHelper instance to work for non-instantiated performance counter /// </summary> /// <typeparam name="T">the enum type holding counter information</typeparam> /// <param name="categoryInfo">information about the category for this counter</param> /// <param name="enumCounterAttributes">attributes for the enum category</param> /// <returns>a created instance of CounterHelper interface to work with the counter</returns> public static CounterHelper <T> Create <T>(PerformanceCounterCategoryAttribute categoryInfo, Dictionary <T, PerformanceCounterAttribute> enumCounterAttributes) { return(new CounterHelperImpl <T>(categoryInfo, enumCounterAttributes)); }