Esempio n. 1
0
        internal static MetadataValue DeserializeMetadataValue(JsonElement element)
        {
            Optional <LocalizableString> name  = default;
            Optional <string>            value = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    name = LocalizableString.DeserializeLocalizableString(property.Value);
                    continue;
                }
                if (property.NameEquals("value"))
                {
                    value = property.Value.GetString();
                    continue;
                }
            }
            return(new MetadataValue(name.Value, value.Value));
        }
Esempio n. 2
0
        internal static Metric DeserializeMetric(JsonElement element)
        {
            string            id   = default;
            string            type = default;
            LocalizableString name = default;
            MetricUnit        unit = default;
            IReadOnlyList <TimeSeriesElement> timeseries = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = LocalizableString.DeserializeLocalizableString(property.Value);
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    unit = property.Value.GetString().ToMetricUnit();
                    continue;
                }
                if (property.NameEquals("timeseries"))
                {
                    List <TimeSeriesElement> array = new List <TimeSeriesElement>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(TimeSeriesElement.DeserializeTimeSeriesElement(item));
                    }
                    timeseries = array;
                    continue;
                }
            }
            return(new Metric(id, type, name, unit, timeseries));
        }
Esempio n. 3
0
        internal static MetricDefinition DeserializeMetricDefinition(JsonElement element)
        {
            Optional <bool>                  isDimensionRequired = default;
            Optional <string>                resourceId          = default;
            Optional <string>                @namespace          = default;
            Optional <LocalizableString>     name = default;
            Optional <MetricUnit>            unit = default;
            Optional <MetricAggregationType> primaryAggregationType = default;
            Optional <IReadOnlyList <MetricAggregationType> > supportedAggregationTypes = default;
            Optional <IReadOnlyList <MetricAvailability> >    metricAvailabilities      = default;
            Optional <string> id = default;
            Optional <IReadOnlyList <LocalizableString> > dimensions = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("isDimensionRequired"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    isDimensionRequired = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("resourceId"))
                {
                    resourceId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("namespace"))
                {
                    @namespace = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    name = LocalizableString.DeserializeLocalizableString(property.Value);
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    unit = property.Value.GetString().ToMetricUnit();
                    continue;
                }
                if (property.NameEquals("primaryAggregationType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    primaryAggregationType = property.Value.GetString().ToMetricAggregationType();
                    continue;
                }
                if (property.NameEquals("supportedAggregationTypes"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <MetricAggregationType> array = new List <MetricAggregationType>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString().ToMetricAggregationType());
                    }
                    supportedAggregationTypes = array;
                    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;
                }
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("dimensions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <LocalizableString> array = new List <LocalizableString>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(LocalizableString.DeserializeLocalizableString(item));
                    }
                    dimensions = array;
                    continue;
                }
            }
            return(new MetricDefinition(Optional.ToNullable(isDimensionRequired), resourceId.Value, @namespace.Value, name.Value, Optional.ToNullable(unit), Optional.ToNullable(primaryAggregationType), Optional.ToList(supportedAggregationTypes), Optional.ToList(metricAvailabilities), id.Value, Optional.ToList(dimensions)));
        }