/// <summary>
        /// Create a new API event metric sample object for the provided metric and internal event metric sample.
        /// </summary>
        /// <remarks>The metric sample is NOT? automatically added to the samples collection of the provided metric object.</remarks>
        /// <param name="metric">The metric object this sample applies to.</param>
        /// <param name="metricSample">The internal metric sample.</param>
        internal EventMetricSample(EventMetric metric, Monitor.EventMetricSample metricSample)
        {
            //and now that we've been created, make sure our metric definition set is locked.
            //metric.Definition.IsReadOnly = true; // ToDo: Double-check that this is set within internal sample.

            // Cache the Event-typed objects we passed to our general metric sample base, so we don't have to cast them.
            m_Metric        = metric;
            m_WrappedSample = metricSample;
        }
Beispiel #2
0
        internal void Internalize(EventMetric metric)
        {
            lock (m_Lock)
            {
                Monitor.EventMetric internalMetric = metric.WrappedMetric;

                m_Externalized[internalMetric] = metric;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Create a new metric object with the provided instance name and add it to the collection
        /// </summary>
        /// <param name="instanceName">The instance name to use, or blank or null for the default metric.</param>
        /// <returns>The new metric object that was added to the collection</returns>
        public EventMetric Add(string instanceName)
        {
            lock (m_Lock)
            {
                //Create a new metric object with the provided instance name (it will get added to us automatically)
                EventMetric newMetric = new EventMetric(m_MetricDefinition, instanceName);

                //finally, return the newly created metric object to our caller
                return(newMetric);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Retrieve an item from the collection by its key if present.  If not present, the default value of the object is returned.
        /// </summary>
        /// <param name="key">The metric name to locate in the collection</param>
        /// <param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
        /// <returns>true if the collection contains an element with the specified key; otherwise false.</returns>
        public bool TryGetValue(string key, out EventMetric value)
        {
            lock (m_Lock)
            {
                //We are playing a few games to get native typing here.
                //Because it's an out value, we have to swap types around ourselves so we can cast.
                Monitor.EventMetric innerValue;

                //gateway to our internal collection try get value
                bool result = m_WrappedCollection.TryGetValue(key, out innerValue);

                value = result ? Externalize(innerValue) : null;

                return(result);
            }
        }
Beispiel #5
0
        internal EventMetric Externalize(Monitor.EventMetric eventMetric)
        {
            if (eventMetric == null)
            {
                return(null);
            }

            lock (m_Lock)
            {
                EventMetric externalDefinition;
                if (m_Externalized.TryGetValue(eventMetric, out externalDefinition) == false)
                {
                    externalDefinition          = new EventMetric(m_MetricDefinition, eventMetric);
                    m_Externalized[eventMetric] = externalDefinition;
                }

                return(externalDefinition);
            }
        }