/// <summary> /// Создать счётчик определённого типа /// </summary> /// <param name="type">Тип счётчика</param> /// <param name="counterName">Имя счётчика</param> /// <param name="counterDescription">Описание счётчика</param> /// <returns>Счётчик</returns> public override Counter CreateCounter(CounterTypes type, string counterName, string counterDescription) { if (counterName == null) { throw new ArgumentNullException("counterName"); } if (counterDescription == null) { throw new ArgumentNullException("counterDescription"); } if (_counters.ContainsKey(counterName)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } Counter res = null; switch (type) { case CounterTypes.NumberOfItems: res = new CompositeNumberOfItemsCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateNumberOfItemsCounter(counterName, counterDescription))); break; case CounterTypes.Delta: res = new CompositeDeltaCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateDeltaCounter(counterName, counterDescription))); break; case CounterTypes.AverageTime: res = new CompositeAverageTimeCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateAverageTimeCounter(counterName, counterDescription))); break; case CounterTypes.AverageCount: res = new CompositeAverageCountCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateAverageCountCounter(counterName, counterDescription))); break; case CounterTypes.OperationsPerSecond: res = new CompositeOperationsPerSecondCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateOperationsPerSecondCounter(counterName, counterDescription))); break; case CounterTypes.ElapsedTime: res = new CompositeElapsedTimeCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateElapsedTimeCounter(counterName, counterDescription))); break; case CounterTypes.MomentTime: res = new CompositeMomentTimeCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateMomentTimeCounter(counterName, counterDescription))); break; default: throw new InvalidOperationException("Unknown CounterTypes value: " + type.ToString()); } if (!_counters.TryAdd(counterName, res)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } return(res); }
/// <summary> /// Создать счётчик определённого типа /// </summary> /// <param name="type">Тип счётчика</param> /// <param name="counterName">Имя счетчика</param> /// <param name="counterDescription">Описание счетчика</param> public override void CreateCounter(CounterTypes type, string counterName, string counterDescription) { if (counterName == null) { throw new ArgumentNullException("counterName"); } if (counterDescription == null) { throw new ArgumentNullException("counterDescription"); } if (_instances.Count != 0) { throw new PerformanceCounterCreationException( string.Format("Can't create counter in multiInstanceCategory ({0}) when it has created instances", this.Name)); } if (_counters.ContainsKey(counterName)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } CompositeCounterDescriptor res = null; switch (type) { case CounterTypes.NumberOfItems: res = CompositeNumberOfItemsCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.Delta: res = CompositeDeltaCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.AverageTime: res = CompositeAverageTimeCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.AverageCount: res = CompositeAverageCountCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.OperationsPerSecond: res = CompositeOperationsPerSecondCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.ElapsedTime: res = CompositeElapsedTimeCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.MomentTime: res = CompositeMomentTimeCounter.CreateDescriptor(counterName, counterDescription); break; default: throw new InvalidOperationException("Unknown CounterTypes value: " + type.ToString()); } if (!_counters.TryAdd(counterName, res)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } foreach (var wrappedCat in _wrappedCategories) { wrappedCat.CreateCounter(type, counterName, counterDescription); } }