internal MonitorMetric(string id, string monitorMetricType, LocalizableString name, MetricUnit unit, IEnumerable <TimeSeriesElement> timeseries)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (monitorMetricType == null)
            {
                throw new ArgumentNullException(nameof(monitorMetricType));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (timeseries == null)
            {
                throw new ArgumentNullException(nameof(timeseries));
            }

            Id = id;
            MonitorMetricType = monitorMetricType;
            Name       = name;
            Unit       = unit;
            Timeseries = timeseries.ToList();
        }
 internal MonitorMetric(string id, string monitorMetricType, LocalizableString name, string displayDescription, string errorCode, string errorMessage, MetricUnit unit, IReadOnlyList <TimeSeriesElement> timeseries)
 {
     Id = id;
     MonitorMetricType = monitorMetricType;
     Name = name;
     DisplayDescription = displayDescription;
     ErrorCode          = errorCode;
     ErrorMessage       = errorMessage;
     Unit       = unit;
     Timeseries = timeseries;
 }
Beispiel #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 <string>            displayDescription = default;
            Optional <string>            category           = default;
            Optional <MetricClass>       metricClass        = default;
            Optional <MetricUnit>        unit = default;
            Optional <AggregationType>   primaryAggregationType = default;
            Optional <IReadOnlyList <AggregationType> >    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("displayDescription"))
                {
                    displayDescription = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("category"))
                {
                    category = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricClass"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    metricClass = new MetricClass(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    unit = new MetricUnit(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("primaryAggregationType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    primaryAggregationType = property.Value.GetString().ToAggregationType();
                    continue;
                }
                if (property.NameEquals("supportedAggregationTypes"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <AggregationType> array = new List <AggregationType>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString().ToAggregationType());
                    }
                    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, displayDescription.Value, category.Value, Optional.ToNullable(metricClass), Optional.ToNullable(unit), Optional.ToNullable(primaryAggregationType), Optional.ToList(supportedAggregationTypes), Optional.ToList(metricAvailabilities), id.Value, Optional.ToList(dimensions)));
        }
        internal static MonitorMetric DeserializeMonitorMetric(JsonElement element)
        {
            string            id   = default;
            string            type = default;
            LocalizableString name = default;
            Optional <string> displayDescription = default;
            Optional <string> errorCode          = default;
            Optional <string> errorMessage       = 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("displayDescription"))
                {
                    displayDescription = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("errorCode"))
                {
                    errorCode = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("errorMessage"))
                {
                    errorMessage = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("unit"))
                {
                    unit = new MetricUnit(property.Value.GetString());
                    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 MonitorMetric(id, type, name, displayDescription.Value, errorCode.Value, errorMessage.Value, unit, timeseries));
        }