internal static SqlMetric DeserializeSqlMetric(JsonElement element)
        {
            Optional <DateTimeOffset> startTime = default;
            Optional <DateTimeOffset> endTime   = default;
            Optional <string>         timeGrain = default;
            Optional <UnitType>       unit      = default;
            Optional <MetricName>     name      = default;
            Optional <IReadOnlyList <MetricValue> > metricValues = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("startTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    startTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("endTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    endTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("timeGrain"))
                {
                    timeGrain = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    unit = new UnitType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    name = MetricName.DeserializeMetricName(property.Value);
                    continue;
                }
                if (property.NameEquals("metricValues"))
                {
                    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));
                    }
                    metricValues = array;
                    continue;
                }
            }
            return(new SqlMetric(Optional.ToNullable(startTime), Optional.ToNullable(endTime), timeGrain.Value, Optional.ToNullable(unit), name.Value, Optional.ToList(metricValues)));
        }
        internal static MetricDefinition DeserializeMetricDefinition(JsonElement element)
        {
            Optional <MetricName>             name = default;
            Optional <PrimaryAggregationType> primaryAggregationType = default;
            Optional <Uri> resourceUri         = default;
            Optional <UnitDefinitionType> unit = default;
            Optional <IReadOnlyList <MetricAvailability> > metricAvailabilities = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    name = MetricName.DeserializeMetricName(property.Value);
                    continue;
                }
                if (property.NameEquals("primaryAggregationType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    primaryAggregationType = new PrimaryAggregationType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("resourceUri"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        resourceUri = null;
                        continue;
                    }
                    resourceUri = new Uri(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    unit = new UnitDefinitionType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("metricAvailabilities"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <MetricAvailability> array = new List <MetricAvailability>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricAvailability.DeserializeMetricAvailability(item));
                    }
                    metricAvailabilities = array;
                    continue;
                }
            }
            return(new MetricDefinition(name.Value, Optional.ToNullable(primaryAggregationType), resourceUri.Value, Optional.ToNullable(unit), Optional.ToList(metricAvailabilities)));
        }
예제 #3
0
 internal Metric(DateTimeOffset?startTime, DateTimeOffset?endTime, string timeGrain, UnitType?unit, MetricName name, IReadOnlyList <MetricValue> metricValues)
 {
     StartTime    = startTime;
     EndTime      = endTime;
     TimeGrain    = timeGrain;
     Unit         = unit;
     Name         = name;
     MetricValues = metricValues;
 }