Пример #1
0
        /// <summary>
        /// Enables the user to create an instance of a <see cref="MetricTimeSeriesElement"/>.
        /// <param name="metadataValues"> A dictionary comprised of metric metadata values. </param>
        /// <param name="values"> A list of <see cref="Models.MetricValue"/> elements. </param>
        /// </summary>
        public static MetricTimeSeriesElement MetricTimeSeriesElement(IReadOnlyDictionary <string, string> metadataValues, IEnumerable <MetricValue> values)
        {
            var metadataValueList = new List <MetadataValue>();

            foreach (var value in metadataValues)
            {
                var metadataValue = new MetadataValue(new LocalizableString(value.Key), value.Value);
                metadataValueList.Add(metadataValue);
            }
            return(new MetricTimeSeriesElement(metadataValueList, values.ToList()));
        }
Пример #2
0
        internal static MetricTimeSeriesElement DeserializeMetricTimeSeriesElement(JsonElement element)
        {
            Optional <IReadOnlyList <MetadataValue> > metadatavalues = default;
            Optional <IReadOnlyList <MetricValue> >   data           = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("metadatavalues"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <MetadataValue> array = new List <MetadataValue>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetadataValue.DeserializeMetadataValue(item));
                    }
                    metadatavalues = array;
                    continue;
                }
                if (property.NameEquals("data"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <MetricValue> array = new List <MetricValue>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricValue.DeserializeMetricValue(item));
                    }
                    data = array;
                    continue;
                }
            }
            return(new MetricTimeSeriesElement(Optional.ToList(metadatavalues), Optional.ToList(data)));
        }