protected CounterSetRegistrarBase(
            Guid providerId,
            Guid counterSetId,
            CounterSetInstanceType counterSetInstType,
            CounterInfo[] counterInfoArray,
            string counterSetName = null)
        {
            ProviderId         = providerId;
            CounterSetId       = counterSetId;
            CounterSetInstType = counterSetInstType;
            CounterSetName     = counterSetName;
            if ((counterInfoArray == null) ||
                (counterInfoArray.Length == 0))
            {
                throw new ArgumentNullException("counterInfoArray");
            }

            CounterInfoArray = new CounterInfo[counterInfoArray.Length];

            for (int i = 0; i < counterInfoArray.Length; i++)
            {
                CounterInfoArray[i] =
                    new CounterInfo(
                        counterInfoArray[i].Id,
                        counterInfoArray[i].Type,
                        counterInfoArray[i].Name
                        );
            }
            this._counterSetInstanceBase = null;
        }
예제 #2
0
        public bool SetCounterValue(
            string counterSetName,
            string counterName,
            long counterValue = 1,
            bool isNumerator  = true)
        {
            if (counterSetName == null)
            {
                ArgumentNullException argNullException =
                    new ArgumentNullException("counterSetName");
                _tracer.TraceException(argNullException);
                return(false);
            }

            Guid counterSetId;

            if (this.IsCounterSetRegistered(counterSetName, out counterSetId))
            {
                CounterSetInstanceBase counterSetInst = _CounterSetIdToInstanceMapping[counterSetId];
                return(counterSetInst.SetCounterValue(counterName, counterValue, isNumerator));
            }
            else
            {
                InvalidOperationException invalidOperationException =
                    new InvalidOperationException(
                        String.Format(
                            CultureInfo.InvariantCulture,
                            "No Counter Set Instance with name '{0}' is registered",
                            counterSetName));
                _tracer.TraceException(invalidOperationException);
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// Method to register a counter set with the Performance Counters Manager.
        /// </summary>
        public bool AddCounterSetInstance(CounterSetRegistrarBase counterSetRegistrarInstance)
        {
            if (counterSetRegistrarInstance == null)
            {
                ArgumentNullException argNullException = new ArgumentNullException("counterSetRegistrarInstance");
                _tracer.TraceException(argNullException);
                return(false);
            }

            Guid   counterSetId   = counterSetRegistrarInstance.CounterSetId;
            string counterSetName = counterSetRegistrarInstance.CounterSetName;
            CounterSetInstanceBase counterSetInst = null;

            if (this.IsCounterSetRegistered(counterSetId, out counterSetInst))
            {
                InvalidOperationException invalidOperationException = new InvalidOperationException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "A Counter Set Instance with id '{0}' is already registered",
                        counterSetId));
                _tracer.TraceException(invalidOperationException);
                return(false);
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(counterSetName))
                {
                    Guid retrievedCounterSetId;
                    // verify that there doesn't exist another counter set with the same name
                    if (this.IsCounterSetRegistered(counterSetName, out retrievedCounterSetId))
                    {
                        InvalidOperationException invalidOperationException =
                            new InvalidOperationException(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    "A Counter Set Instance with name '{0}' is already registered",
                                    counterSetName));
                        _tracer.TraceException(invalidOperationException);
                        return(false);
                    }

                    _CounterSetNameToIdMapping.TryAdd(counterSetName, counterSetId);
                }

                _CounterSetIdToInstanceMapping.TryAdd(
                    counterSetId,
                    counterSetRegistrarInstance.CounterSetInstance);
            }
            catch (OverflowException overflowException)
            {
                _tracer.TraceException(overflowException);
                return(false);
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// NOTE: This method is provided solely for testing purposes.
        /// </summary>
        internal void RemoveAllCounterSets()
        {
            ICollection <Guid> counterSetIdKeys = _CounterSetIdToInstanceMapping.Keys;

            foreach (Guid counterSetId in counterSetIdKeys)
            {
                CounterSetInstanceBase currentCounterSetInstance = _CounterSetIdToInstanceMapping[counterSetId];
                currentCounterSetInstance.Dispose();
            }
            _CounterSetIdToInstanceMapping.Clear();
            _CounterSetNameToIdMapping.Clear();
        }
예제 #5
0
        public bool UpdateCounterByValue(Guid counterSetId, string counterName, long stepAmount = 1L, bool isNumerator = true)
        {
            CounterSetInstanceBase counterSetInst = null;

            if (this.IsCounterSetRegistered(counterSetId, out counterSetInst))
            {
                return(counterSetInst.UpdateCounterByValue(counterName, stepAmount, isNumerator));
            }
            InvalidOperationException exception = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No Counter Set Instance with id '{0}' is registered", new object[] { counterSetId }));

            this._tracer.TraceException(exception);
            return(false);
        }
예제 #6
0
 protected CounterSetRegistrarBase(Guid providerId, Guid counterSetId, CounterSetInstanceType counterSetInstType, CounterInfo[] counterInfoArray, string counterSetName = null)
 {
     this._providerId = providerId;
     this._counterSetId = counterSetId;
     this._counterSetInstanceType = counterSetInstType;
     this._counterSetName = counterSetName;
     if ((counterInfoArray == null) || (counterInfoArray.Length == 0))
     {
         throw new ArgumentNullException("counterInfoArray");
     }
     this._counterInfoArray = new CounterInfo[counterInfoArray.Length];
     for (int i = 0; i < counterInfoArray.Length; i++)
     {
         this._counterInfoArray[i] = new CounterInfo(counterInfoArray[i].Id, counterInfoArray[i].Type, counterInfoArray[i].Name);
     }
     this._counterSetInstanceBase = null;
 }
예제 #7
0
        public bool UpdateCounterByValue(string counterSetName, string counterName, long stepAmount = 1L, bool isNumerator = true)
        {
            Guid guid;

            if (counterSetName == null)
            {
                ArgumentNullException exception = new ArgumentNullException("counterSetName");
                this._tracer.TraceException(exception);
                return(false);
            }
            if (this.IsCounterSetRegistered(counterSetName, out guid))
            {
                CounterSetInstanceBase base2 = this._CounterSetIdToInstanceMapping[guid];
                return(base2.UpdateCounterByValue(counterName, stepAmount, isNumerator));
            }
            InvalidOperationException exception2 = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No Counter Set Instance with name {0} is registered", new object[] { counterSetName }));

            this._tracer.TraceException(exception2);
            return(false);
        }
예제 #8
0
        public bool AddCounterSetInstance(CounterSetRegistrarBase counterSetRegistrarInstance)
        {
            if (counterSetRegistrarInstance == null)
            {
                ArgumentNullException exception = new ArgumentNullException("counterSetRegistrarInstance");
                this._tracer.TraceException(exception);
                return(false);
            }
            Guid   counterSetId   = counterSetRegistrarInstance.CounterSetId;
            string counterSetName = counterSetRegistrarInstance.CounterSetName;
            CounterSetInstanceBase counterSetInst = null;

            if (this.IsCounterSetRegistered(counterSetId, out counterSetInst))
            {
                InvalidOperationException exception2 = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "A Counter Set Instance with id '{0}' is already registered", new object[] { counterSetId }));
                this._tracer.TraceException(exception2);
                return(false);
            }
            try
            {
                if (!string.IsNullOrWhiteSpace(counterSetName))
                {
                    Guid guid2;
                    if (this.IsCounterSetRegistered(counterSetName, out guid2))
                    {
                        InvalidOperationException exception3 = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "A Counter Set Instance with name '{0}' is already registered", new object[] { counterSetName }));
                        this._tracer.TraceException(exception3);
                        return(false);
                    }
                    this._CounterSetNameToIdMapping.TryAdd(counterSetName, counterSetId);
                }
                this._CounterSetIdToInstanceMapping.TryAdd(counterSetId, counterSetRegistrarInstance.CounterSetInstance);
            }
            catch (OverflowException exception4)
            {
                this._tracer.TraceException(exception4);
                return(false);
            }
            return(true);
        }
예제 #9
0
        public bool SetCounterValue(
            Guid counterSetId,
            string counterName,
            long counterValue = 1,
            bool isNumerator  = true)
        {
            CounterSetInstanceBase counterSetInst = null;

            if (this.IsCounterSetRegistered(counterSetId, out counterSetInst))
            {
                return(counterSetInst.SetCounterValue(counterName, counterValue, isNumerator));
            }
            else
            {
                InvalidOperationException invalidOperationException =
                    new InvalidOperationException(
                        String.Format(
                            CultureInfo.InvariantCulture,
                            "No Counter Set Instance with id '{0}' is registered",
                            counterSetId));
                _tracer.TraceException(invalidOperationException);
                return(false);
            }
        }
예제 #10
0
 /// <summary>
 /// Method to determine whether the counter set given by 'counterSetId' is
 /// registered with the system. If true, then CounterSetInstance is populated.
 /// </summary>
 public bool IsCounterSetRegistered(Guid counterSetId, out CounterSetInstanceBase counterSetInst)
 {
     return(_CounterSetIdToInstanceMapping.TryGetValue(counterSetId, out counterSetInst));
 }
예제 #11
0
 public bool IsCounterSetRegistered(Guid counterSetId, out CounterSetInstanceBase counterSetInst)
 {
     return this._CounterSetIdToInstanceMapping.TryGetValue(counterSetId, out counterSetInst);
 }