Exemplo n.º 1
0
        public static DataRetrievalResult TryGetData(EventData eventData, EventMetadata metricMetadata, out MetricData metric)
        {
            Requires.NotNull(eventData, nameof(eventData));
            Requires.NotNull(metricMetadata, nameof(metricMetadata));
            metric = null;

            string metricName = metricMetadata[MetricNameMoniker];

            if (string.IsNullOrEmpty(metricName))
            {
                return(DataRetrievalResult.MissingMetadataProperty(MetricNameMoniker));
            }

            double value = 0.0;

            string metricValueProperty = metricMetadata[MetricValuePropertyMoniker];

            if (string.IsNullOrEmpty(metricValueProperty))
            {
                string rawValue = metricMetadata[MetricValueMoniker];
                if (string.IsNullOrEmpty(rawValue))
                {
                    return(DataRetrievalResult.MissingMetadataProperty(MetricValueMoniker));
                }

                if (!double.TryParse(rawValue, out value))
                {
                    return(DataRetrievalResult.InvalidMetadataPropertyValue(MetricValueMoniker, rawValue));
                }
            }
            else
            {
                if (!eventData.GetValueFromPayload <double>(metricValueProperty, (v) => value = v))
                {
                    return(DataRetrievalResult.DataMissingOrInvalid(metricValueProperty));
                }
            }

            metric            = new MetricData();
            metric.MetricName = metricName;
            metric.Value      = value;
            return(DataRetrievalResult.Success());
        }
        public static DataRetrievalResult TryGetData(EventData eventData, EventMetadata metricMetadata, out MetricData metric)
        {
            Requires.NotNull(eventData, nameof(eventData));
            Requires.NotNull(metricMetadata, nameof(metricMetadata));
            metric = null;

            if (!MetricMetadataKind.Equals(metricMetadata.MetadataType, System.StringComparison.OrdinalIgnoreCase))
            {
                return(DataRetrievalResult.InvalidMetadataType(metricMetadata.MetadataType, MetricMetadataKind));
            }

            string metricName = string.Empty;

            string metricNameProperty = metricMetadata[MetricNamePropertyMoniker];

            if (string.IsNullOrEmpty(metricNameProperty))
            {
                metricName = metricMetadata[MetricNameMoniker];
                if (string.IsNullOrEmpty(metricName))
                {
                    return(DataRetrievalResult.MissingMetadataProperty(MetricNameMoniker));
                }
            }
            else
            {
                if (!eventData.GetValueFromPayload(metricNameProperty, (v) => metricName = v))
                {
                    return(DataRetrievalResult.DataMissingOrInvalid(metricNameProperty));
                }
            }

            double value = 0.0;

            string metricValueProperty = metricMetadata[MetricValuePropertyMoniker];

            if (string.IsNullOrEmpty(metricValueProperty))
            {
                string rawValue = metricMetadata[MetricValueMoniker];
                if (string.IsNullOrEmpty(rawValue))
                {
                    return(DataRetrievalResult.MissingMetadataProperty(MetricValueMoniker));
                }

                if (!double.TryParse(rawValue, out value))
                {
                    return(DataRetrievalResult.InvalidMetadataPropertyValue(MetricValueMoniker, rawValue));
                }
            }
            else
            {
                if (!eventData.GetValueFromPayload(metricValueProperty, (double v) => value = v))
                {
                    return(DataRetrievalResult.DataMissingOrInvalid(metricValueProperty));
                }
            }

            metric            = new MetricData();
            metric.MetricName = metricName;
            metric.Value      = value;

            return(DataRetrievalResult.Success);
        }