コード例 #1
0
        /// <summary>
        /// Records a value to the values array of this sample given the zero-based index of the value definition to be used.
        /// </summary>
        /// <remarks>The value must be defined as part of the event metric definition associated with this sample
        /// or an exception will be thrown.  The data type must also be compatible with the data type configured
        /// on the event metric definition or no data will be recorded.
        /// If called more than once for the same value, the prior value will be replaced.</remarks>
        /// <param name="valueIndex">The zero-based index within the value definition of the value to be recorded.</param>
        /// <param name="value">Optional.  The value to be recorded.</param>
        public void SetValue(int valueIndex, object value)
        {
            EventMetricValueDefinitionCollection valueDefinitions = Metric.Definition.ValueCollection;

            //we don't have to check that the value index isn't null, but it does have to be in range
            if ((valueIndex < 0) || (valueIndex >= valueDefinitions.Count))
            {
#if DEBUG
                //if we're compiled in debug mode, tell the user they blew it.
                throw new ArgumentOutOfRangeException(nameof(valueIndex), valueIndex.ToString(CultureInfo.CurrentCulture));
#else
                //trace log and return, nothing we can do.
                Log.Warning("Unable to add metric value because the value definition could not be found.",
                            "There is no value definition at index {1} for metric definition {0}",
                            Metric.Definition.Key, valueIndex);
                return;
#endif
            }

            //look up the value in the definition so we can process it
            EventMetricValueDefinition curValueDefinition = valueDefinitions[valueIndex];

            //and now we can use our one true method to add the value
            SetValue(curValueDefinition, value);
        }
コード例 #2
0
        /// <summary>
        /// Records a value to the values array of this sample given its value definition.
        /// </summary>
        /// <remarks>The value must be defined as part of the event metric definition associated with this sample
        /// or an exception will be thrown.  The data type must also be compatible with the data type configured
        /// on the event metric definition or no data will be recorded.
        /// If called more than once for the same value, the prior value will be replaced.</remarks>
        /// <param name="valueDefinition">The metric value definition object of the value to be recorded.</param>
        /// <param name="value">Optional. The value to be recorded.</param>
        /// <exception cref="ArgumentNullException">Throw if the valueDefinition is null.</exception>
        public void SetValue(EventMetricValueDefinition valueDefinition, object value)
        {
            //make sure we got a value definition
            if (valueDefinition == null)
            {
                throw new ArgumentNullException(nameof(valueDefinition));
            }

            m_WrappedSample.SetValue(valueDefinition.WrappedValueDefinition, value);
        }