Beispiel #1
0
        internal MetricResult(string id, string type, LocalizableString localizedName, MetricUnit unit, IEnumerable <TimeSeriesElement> timeSeries)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (localizedName == null)
            {
                throw new ArgumentNullException(nameof(localizedName));
            }
            if (timeSeries == null)
            {
                throw new ArgumentNullException(nameof(timeSeries));
            }

            Id            = id;
            Type          = type;
            LocalizedName = localizedName;
            Unit          = unit;
            TimeSeries    = timeSeries.ToList();
        }
Beispiel #2
0
 internal Metric(string id, string type, LocalizableString localizedName, MetricUnit unit, IReadOnlyList <TimeSeriesElement> timeSeries)
 {
     Id            = id;
     Type          = type;
     LocalizedName = localizedName;
     Unit          = unit;
     TimeSeries    = timeSeries;
 }
Beispiel #3
0
 internal MetricResult(string id, string type, LocalizableString localizedName, string displayDescription, string errorCode, string errorMessage, MetricUnit unit, IReadOnlyList <TimeSeriesElement> timeSeries)
 {
     Id                 = id;
     Type               = type;
     LocalizedName      = localizedName;
     DisplayDescription = displayDescription;
     ErrorCode          = errorCode;
     ErrorMessage       = errorMessage;
     Unit               = unit;
     TimeSeries         = timeSeries;
 }
        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 = 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 Metric(id, type, name, unit, timeseries));
        }
        internal static MetricResult DeserializeMetricResult(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 <MetricTimeSeriesElement> 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 <MetricTimeSeriesElement> array = new List <MetricTimeSeriesElement>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricTimeSeriesElement.DeserializeMetricTimeSeriesElement(item));
                    }
                    timeseries = array;
                    continue;
                }
            }
            return(new MetricResult(id, type, name, displayDescription.Value, errorCode.Value, errorMessage.Value, unit, timeseries));
        }
        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 <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("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().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, displayDescription.Value, category.Value, Optional.ToNullable(metricClass), Optional.ToNullable(unit), Optional.ToNullable(primaryAggregationType), Optional.ToList(supportedAggregationTypes), Optional.ToList(metricAvailabilities), id.Value, Optional.ToList(dimensions)));
        }
Beispiel #7
0
 /// <summary>
 /// Enables the user to create an instance of a <see cref="MetricResult"/>.
 /// </summary>
 /// <param name="id"> The metric ID. </param>
 /// <param name="resourceType"> The resource type of the metric resource. </param>
 /// <param name="name"> The name of the metric. </param>
 /// <param name="unit"> The unit of the metric. </param>
 /// <param name="timeSeries"> The time series returned when a data query is performed. </param>
 public static MetricResult MetricResult(string id, string resourceType, string name, MetricUnit unit, IEnumerable <MetricTimeSeriesElement> timeSeries)
 {
     return(new MetricResult(id, resourceType, new LocalizableString(name), unit, timeSeries));
 }
 public static string ToSerialString(this MetricUnit value) => value switch
 {