internal static MetricSeriesList DeserializeMetricSeriesList(JsonElement element) { Optional <string> nextLink = default; Optional <IReadOnlyList <MetricSeriesDefinition> > value = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("@nextLink")) { nextLink = property.Value.GetString(); continue; } if (property.NameEquals("value")) { List <MetricSeriesDefinition> array = new List <MetricSeriesDefinition>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(MetricSeriesDefinition.DeserializeMetricSeriesDefinition(item)); } value = array; continue; } } return(new MetricSeriesList(nextLink.Value, Optional.ToList(value))); }
/// <summary> /// Initializes a new instance of <see cref="Models.MetricSeriesData"/> for mocking purposes. /// </summary> /// <param name="metricId">Sets the <see cref="MetricSeriesData.MetricId"/> property.</param> /// <param name="seriesKey">Sets the <see cref="MetricSeriesData.SeriesKey"/> property.</param> /// <param name="timestamps">Sets the <see cref="MetricSeriesData.Timestamps"/> property.</param> /// <param name="metricValues">Sets the <see cref="MetricSeriesData.MetricValues"/> property.</param> /// <returns>A new instance of <see cref="Models.MetricSeriesData"/> for mocking purposes.</returns> public static MetricSeriesData MetricSeriesData(string metricId = null, DimensionKey seriesKey = null, IEnumerable <DateTimeOffset> timestamps = null, IEnumerable <double> metricValues = null) { timestamps ??= new List <DateTimeOffset>(); metricValues ??= new List <double>(); Dictionary <string, string> dimensions = seriesKey?.ToDictionary(key => key.Key, key => key.Value); MetricSeriesDefinition definition = new MetricSeriesDefinition(metricId, dimensions); return(new MetricSeriesData(definition, timestamps?.ToList(), metricValues?.ToList())); }
internal static MetricSeriesData DeserializeMetricSeriesData(JsonElement element) { Optional <MetricSeriesDefinition> id = default; Optional <IReadOnlyList <DateTimeOffset> > timestampList = default; Optional <IReadOnlyList <double> > valueList = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } id = MetricSeriesDefinition.DeserializeMetricSeriesDefinition(property.Value); continue; } if (property.NameEquals("timestampList")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <DateTimeOffset> array = new List <DateTimeOffset>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetDateTimeOffset("O")); } timestampList = array; continue; } if (property.NameEquals("valueList")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <double> array = new List <double>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetDouble()); } valueList = array; continue; } } return(new MetricSeriesData(id.Value, Optional.ToList(timestampList), Optional.ToList(valueList))); }
internal MetricSeriesData(MetricSeriesDefinition definition, IEnumerable <DateTimeOffset> timestamps, IEnumerable <double> metricValues) { if (definition == null) { throw new ArgumentNullException(nameof(definition)); } if (timestamps == null) { throw new ArgumentNullException(nameof(timestamps)); } if (metricValues == null) { throw new ArgumentNullException(nameof(metricValues)); } Definition = definition; Timestamps = timestamps.ToList(); MetricValues = metricValues.ToList(); }
internal static MetricSeriesData DeserializeMetricSeriesData(JsonElement element) { MetricSeriesDefinition id = default; IReadOnlyList <DateTimeOffset> timestampList = default; IReadOnlyList <double> valueList = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) { id = MetricSeriesDefinition.DeserializeMetricSeriesDefinition(property.Value); continue; } if (property.NameEquals("timestampList")) { List <DateTimeOffset> array = new List <DateTimeOffset>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetDateTimeOffset("O")); } timestampList = array; continue; } if (property.NameEquals("valueList")) { List <double> array = new List <double>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetDouble()); } valueList = array; continue; } } return(new MetricSeriesData(id, timestampList, valueList)); }
internal MetricSeriesData(MetricSeriesDefinition definition, IReadOnlyList <DateTimeOffset> timestamps, IReadOnlyList <double> metricValues) { Definition = definition; Timestamps = timestamps; MetricValues = metricValues; }