void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("criterionType");
     writer.WriteStringValue(CriterionType.ToString());
     writer.WritePropertyName("name");
     writer.WriteStringValue(Name);
     writer.WritePropertyName("metricName");
     writer.WriteStringValue(MetricName);
     if (Optional.IsDefined(MetricNamespace))
     {
         writer.WritePropertyName("metricNamespace");
         writer.WriteStringValue(MetricNamespace);
     }
     writer.WritePropertyName("timeAggregation");
     writer.WriteStringValue(TimeAggregation.ToSerialString());
     if (Optional.IsCollectionDefined(Dimensions))
     {
         writer.WritePropertyName("dimensions");
         writer.WriteStartArray();
         foreach (var item in Dimensions)
         {
             writer.WriteObjectValue(item);
         }
         writer.WriteEndArray();
     }
     foreach (var item in AdditionalProperties)
     {
         writer.WritePropertyName(item.Key);
         writer.WriteObjectValue(item.Value);
     }
     writer.WriteEndObject();
 }
 internal DynamicMetricCriteria(CriterionType criterionType, string name, string metricName, string metricNamespace, AggregationType timeAggregation, IList <MetricDimension> dimensions, IDictionary <string, object> additionalProperties, DynamicThresholdOperator @operator, DynamicThresholdSensitivity alertSensitivity, DynamicThresholdFailingPeriods failingPeriods, DateTimeOffset?ignoreDataBefore) : base(criterionType, name, metricName, metricNamespace, timeAggregation, dimensions, additionalProperties)
 {
     Operator         = @operator;
     AlertSensitivity = alertSensitivity;
     FailingPeriods   = failingPeriods;
     IgnoreDataBefore = ignoreDataBefore;
     CriterionType    = criterionType;
 }
示例#3
0
 internal MultiMetricCriteria(CriterionType criterionType, string name, string metricName, string metricNamespace, AggregationType timeAggregation, IList <MetricDimension> dimensions, IDictionary <string, object> additionalProperties)
 {
     CriterionType        = criterionType;
     Name                 = name;
     MetricName           = metricName;
     MetricNamespace      = metricNamespace;
     TimeAggregation      = timeAggregation;
     Dimensions           = dimensions;
     AdditionalProperties = additionalProperties;
 }
示例#4
0
        public MultiMetricCriteria(string name, string metricName, AggregationType timeAggregation)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (metricName == null)
            {
                throw new ArgumentNullException(nameof(metricName));
            }

            Name                 = name;
            MetricName           = metricName;
            TimeAggregation      = timeAggregation;
            Dimensions           = new ChangeTrackingList <MetricDimension>();
            AdditionalProperties = new ChangeTrackingDictionary <string, object>();
            CriterionType        = new CriterionType("MultiMetricCriteria");
        }
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("operator");
     writer.WriteStringValue(Operator.ToString());
     writer.WritePropertyName("alertSensitivity");
     writer.WriteStringValue(AlertSensitivity.ToString());
     writer.WritePropertyName("failingPeriods");
     writer.WriteObjectValue(FailingPeriods);
     if (Optional.IsDefined(IgnoreDataBefore))
     {
         writer.WritePropertyName("ignoreDataBefore");
         writer.WriteStringValue(IgnoreDataBefore.Value, "O");
     }
     writer.WritePropertyName("criterionType");
     writer.WriteStringValue(CriterionType.ToString());
     writer.WritePropertyName("name");
     writer.WriteStringValue(Name);
     writer.WritePropertyName("metricName");
     writer.WriteStringValue(MetricName);
     if (Optional.IsDefined(MetricNamespace))
     {
         writer.WritePropertyName("metricNamespace");
         writer.WriteStringValue(MetricNamespace);
     }
     writer.WritePropertyName("timeAggregation");
     writer.WriteStringValue(TimeAggregation.ToSerialString());
     if (Optional.IsCollectionDefined(Dimensions))
     {
         writer.WritePropertyName("dimensions");
         writer.WriteStartArray();
         foreach (var item in Dimensions)
         {
             writer.WriteObjectValue(item);
         }
         writer.WriteEndArray();
     }
     foreach (var item in AdditionalProperties)
     {
         writer.WritePropertyName(item.Key);
         writer.WriteObjectValue(item.Value);
     }
     writer.WriteEndObject();
 }
        internal static DynamicMetricCriteria DeserializeDynamicMetricCriteria(JsonElement element)
        {
            DynamicThresholdOperator       @operator        = default;
            DynamicThresholdSensitivity    alertSensitivity = default;
            DynamicThresholdFailingPeriods failingPeriods   = default;
            Optional <DateTimeOffset>      ignoreDataBefore = default;
            CriterionType     criterionType   = default;
            string            name            = default;
            string            metricName      = default;
            Optional <string> metricNamespace = default;
            AggregationType   timeAggregation = default;
            Optional <IList <MetricDimension> > dimensions                     = default;
            IDictionary <string, object>        additionalProperties           = default;
            Dictionary <string, object>         additionalPropertiesDictionary = new Dictionary <string, object>();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("operator"))
                {
                    @operator = new DynamicThresholdOperator(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("alertSensitivity"))
                {
                    alertSensitivity = new DynamicThresholdSensitivity(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("failingPeriods"))
                {
                    failingPeriods = DynamicThresholdFailingPeriods.DeserializeDynamicThresholdFailingPeriods(property.Value);
                    continue;
                }
                if (property.NameEquals("ignoreDataBefore"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    ignoreDataBefore = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("criterionType"))
                {
                    criterionType = new CriterionType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricName"))
                {
                    metricName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricNamespace"))
                {
                    metricNamespace = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("timeAggregation"))
                {
                    timeAggregation = property.Value.GetString().ToAggregationType();
                    continue;
                }
                if (property.NameEquals("dimensions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <MetricDimension> array = new List <MetricDimension>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricDimension.DeserializeMetricDimension(item));
                    }
                    dimensions = array;
                    continue;
                }
                additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
            }
            additionalProperties = additionalPropertiesDictionary;
            return(new DynamicMetricCriteria(criterionType, name, metricName, metricNamespace.Value, timeAggregation, Optional.ToList(dimensions), additionalProperties, @operator, alertSensitivity, failingPeriods, Optional.ToNullable(ignoreDataBefore)));
        }
        internal static MetricCriteria DeserializeMetricCriteria(JsonElement element)
        {
            Operator          @operator       = default;
            double            threshold       = default;
            CriterionType     criterionType   = default;
            string            name            = default;
            string            metricName      = default;
            Optional <string> metricNamespace = default;
            AggregationType   timeAggregation = default;
            Optional <IList <MetricDimension> > dimensions                     = default;
            IDictionary <string, object>        additionalProperties           = default;
            Dictionary <string, object>         additionalPropertiesDictionary = new Dictionary <string, object>();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("operator"))
                {
                    @operator = new Operator(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("threshold"))
                {
                    threshold = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("criterionType"))
                {
                    criterionType = new CriterionType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricName"))
                {
                    metricName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricNamespace"))
                {
                    metricNamespace = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("timeAggregation"))
                {
                    timeAggregation = property.Value.GetString().ToAggregationType();
                    continue;
                }
                if (property.NameEquals("dimensions"))
                {
                    List <MetricDimension> array = new List <MetricDimension>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricDimension.DeserializeMetricDimension(item));
                    }
                    dimensions = array;
                    continue;
                }
                additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
            }
            additionalProperties = additionalPropertiesDictionary;
            return(new MetricCriteria(criterionType, name, metricName, metricNamespace.Value, timeAggregation, Optional.ToList(dimensions), additionalProperties, @operator, threshold));
        }
        internal static MultiMetricCriteria DeserializeMultiMetricCriteria(JsonElement element)
        {
            if (element.TryGetProperty("criterionType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "DynamicThresholdCriterion": return(DynamicMetricCriteria.DeserializeDynamicMetricCriteria(element));

                case "StaticThresholdCriterion": return(MetricCriteria.DeserializeMetricCriteria(element));
                }
            }
            CriterionType     criterionType   = default;
            string            name            = default;
            string            metricName      = default;
            Optional <string> metricNamespace = default;
            AggregationType   timeAggregation = default;
            Optional <IList <MetricDimension> > dimensions                     = default;
            IDictionary <string, object>        additionalProperties           = default;
            Dictionary <string, object>         additionalPropertiesDictionary = new Dictionary <string, object>();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("criterionType"))
                {
                    criterionType = new CriterionType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricName"))
                {
                    metricName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricNamespace"))
                {
                    metricNamespace = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("timeAggregation"))
                {
                    timeAggregation = property.Value.GetString().ToAggregationType();
                    continue;
                }
                if (property.NameEquals("dimensions"))
                {
                    List <MetricDimension> array = new List <MetricDimension>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(MetricDimension.DeserializeMetricDimension(item));
                    }
                    dimensions = array;
                    continue;
                }
                additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
            }
            additionalProperties = additionalPropertiesDictionary;
            return(new MultiMetricCriteria(criterionType, name, metricName, metricNamespace.Value, timeAggregation, Optional.ToList(dimensions), additionalProperties));
        }
 internal MetricCriteria(CriterionType criterionType, string name, string metricName, string metricNamespace, AggregationType timeAggregation, IList <MetricDimension> dimensions, IDictionary <string, object> additionalProperties, Operator @operator, double threshold) : base(criterionType, name, metricName, metricNamespace, timeAggregation, dimensions, additionalProperties)
 {
     Operator      = @operator;
     Threshold     = threshold;
     CriterionType = criterionType;
 }