Пример #1
0
        /// <summary>Return a registered event metric instance for the provided event metric definition.</summary>
        /// <remarks><para>If the provided event metric definition is an unregistered raw definition, it will be registered
        /// as a completed definition (or a matching registered event metric definition will be used in place of it), but
        /// an inability to successfully register the definition will result in an ArgumentException, as with calling
        /// the Register() method in EventMetricDefinition.  Using a properly-registered definition is preferred.</para>
        /// <para>If an event metric with that instance name already exists for that registered definition, it will be
        /// returned.  Otherwise, one will be created from that definition and returned.</para></remarks>
        /// <param name="definition">The metric definition for the desired metric instance.</param>
        /// <param name="instanceName">The desired instance name (may be null for the default instance).</param>
        /// <returns>The EventMetric object for the requested event metric instance.</returns>
        /// <example>
        /// See the <see cref="EventMetric">EventMetric Class Overview</see> for an example.
        /// </example>
        public static EventMetric Register(EventMetricDefinition definition, string instanceName)
        {
            if (definition == null)
            {
                // Uh-oh. They gave us a non-EventMetricDefinition?
                return(null);
            }

            EventMetricDefinition metricDefinition;

            lock (definition.Lock)
            {
                if (definition.IsReadOnly == false)
                {
                    // Uh-oh.  They gave us a raw event metric definition which wasn't registered.
                    // But they're calling Register(), so they'd expect us to complete registration for them in this call.
                    metricDefinition = definition.Register();
                }
                else
                {
                    // Assume this is a registered definition. ToDo: Make sure they only get IsReadOnly when actually registered.
                    metricDefinition = definition;
                }
            }

            EventMetric           eventMetric;
            EventMetricCollection metrics = metricDefinition.Metrics;

            lock (metrics.Lock)
            {
                if (metrics.TryGetValue(instanceName, out eventMetric) == false)
                {
                    eventMetric = metrics.Add(instanceName);
                }
            }
            return(eventMetric);
        }
Пример #2
0
 public Enumerator(EventMetricCollection collection, IEnumerator <Monitor.EventMetric> enumerator)
 {
     m_Collection = collection;
     m_Enumerator = enumerator;
 }