internal static BaseUsage DeserializeBaseUsage(JsonElement element)
        {
            Optional <UnitType>   unit         = default;
            Optional <MetricName> name         = default;
            Optional <string>     quotaPeriod  = default;
            Optional <long>       limit        = default;
            Optional <long>       currentValue = default;

            foreach (var property in element.EnumerateObject())
            {
                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("quotaPeriod"))
                {
                    quotaPeriod = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("limit"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    limit = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("currentValue"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    currentValue = property.Value.GetInt64();
                    continue;
                }
            }
            return(new BaseUsage(Optional.ToNullable(unit), name.Value, quotaPeriod.Value, Optional.ToNullable(limit), Optional.ToNullable(currentValue)));
        }
예제 #2
0
        internal static PartitionUsage DeserializePartitionUsage(JsonElement element)
        {
            Optional <string>     partitionId         = default;
            Optional <string>     partitionKeyRangeId = default;
            Optional <UnitType>   unit         = default;
            Optional <MetricName> name         = default;
            Optional <string>     quotaPeriod  = default;
            Optional <long>       limit        = default;
            Optional <long>       currentValue = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("partitionId"))
                {
                    partitionId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("partitionKeyRangeId"))
                {
                    partitionKeyRangeId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    unit = new UnitType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = MetricName.DeserializeMetricName(property.Value);
                    continue;
                }
                if (property.NameEquals("quotaPeriod"))
                {
                    quotaPeriod = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("limit"))
                {
                    limit = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("currentValue"))
                {
                    currentValue = property.Value.GetInt64();
                    continue;
                }
            }
            return(new PartitionUsage(Optional.ToNullable(unit), name.Value, quotaPeriod.Value, Optional.ToNullable(limit), Optional.ToNullable(currentValue), partitionId.Value, partitionKeyRangeId.Value));
        }
        internal static Metric DeserializeMetric(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"))
                {
                    startTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("endTime"))
                {
                    endTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("timeGrain"))
                {
                    timeGrain = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    unit = new UnitType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = MetricName.DeserializeMetricName(property.Value);
                    continue;
                }
                if (property.NameEquals("metricValues"))
                {
                    List <MetricValue> array = new List <MetricValue>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricValue.DeserializeMetricValue(item));
                    }
                    metricValues = array;
                    continue;
                }
            }
            return(new Metric(Optional.ToNullable(startTime), Optional.ToNullable(endTime), timeGrain.Value, Optional.ToNullable(unit), name.Value, Optional.ToList(metricValues)));
        }
예제 #4
0
        internal static MetricDefinition DeserializeMetricDefinition(JsonElement element)
        {
            Optional <IReadOnlyList <MetricAvailability> > metricAvailabilities = default;
            Optional <PrimaryAggregationType> primaryAggregationType            = default;
            Optional <UnitType>   unit        = default;
            Optional <string>     resourceUri = default;
            Optional <MetricName> name        = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("metricAvailabilities"))
                {
                    List <MetricAvailability> array = new List <MetricAvailability>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricAvailability.DeserializeMetricAvailability(item));
                    }
                    metricAvailabilities = array;
                    continue;
                }
                if (property.NameEquals("primaryAggregationType"))
                {
                    primaryAggregationType = new PrimaryAggregationType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    unit = new UnitType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("resourceUri"))
                {
                    resourceUri = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = MetricName.DeserializeMetricName(property.Value);
                    continue;
                }
            }
            return(new MetricDefinition(Optional.ToList(metricAvailabilities), Optional.ToNullable(primaryAggregationType), Optional.ToNullable(unit), resourceUri.Value, name.Value));
        }
        internal static PartitionMetric DeserializePartitionMetric(JsonElement element)
        {
            Optional <string>         partitionId         = default;
            Optional <string>         partitionKeyRangeId = default;
            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("partitionId"))
                {
                    partitionId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("partitionKeyRangeId"))
                {
                    partitionKeyRangeId = property.Value.GetString();
                    continue;
                }
                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 PartitionMetric(Optional.ToNullable(startTime), Optional.ToNullable(endTime), timeGrain.Value, Optional.ToNullable(unit), name.Value, Optional.ToList(metricValues), partitionId.Value, partitionKeyRangeId.Value));
        }