예제 #1
0
        /// <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 InternalNumberOfItemsCounter(counterName, counterDescription);
                break;

            case CounterTypes.Delta:
                res = new InternalDeltaCounter(counterName, counterDescription);
                break;

            case CounterTypes.AverageTime:
                res = new InternalAverageTimeCounter(counterName, counterDescription);
                break;

            case CounterTypes.AverageCount:
                res = new InternalAverageCountCounter(counterName, counterDescription);
                break;

            case CounterTypes.OperationsPerSecond:
                res = new InternalOperationsPerSecondCounter(counterName, counterDescription);
                break;

            case CounterTypes.ElapsedTime:
                res = new InternalElapsedTimeCounter(counterName, counterDescription);
                break;

            case CounterTypes.MomentTime:
                res = new InternalMomentTimeCounter(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);
            }

            _isCountersChanged = true;
            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);
            }


            InternalCounterDescriptor res = null;

            switch (type)
            {
            case CounterTypes.NumberOfItems:
                res = InternalNumberOfItemsCounter.CreateDescriptor(counterName, counterDescription);
                break;

            case CounterTypes.Delta:
                res = InternalDeltaCounter.CreateDescriptor(counterName, counterDescription);
                break;

            case CounterTypes.AverageTime:
                res = InternalAverageTimeCounter.CreateDescriptor(counterName, counterDescription);
                break;

            case CounterTypes.AverageCount:
                res = InternalAverageCountCounter.CreateDescriptor(counterName, counterDescription);
                break;

            case CounterTypes.OperationsPerSecond:
                res = InternalOperationsPerSecondCounter.CreateDescriptor(counterName, counterDescription);
                break;

            case CounterTypes.ElapsedTime:
                res = InternalElapsedTimeCounter.CreateDescriptor(counterName, counterDescription);
                break;

            case CounterTypes.MomentTime:
                res = InternalMomentTimeCounter.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);
            }
        }