Пример #1
0
 internal MetricAlertResource(string id, string name, string type, string location, IDictionary <string, string> tags, string description, int severity, bool enabled, IList <string> scopes, TimeSpan evaluationFrequency, TimeSpan windowSize, string targetResourceType, string targetResourceRegion, MetricAlertCriteria criteria, bool?autoMitigate, IList <MetricAlertAction> actions, DateTimeOffset?lastUpdatedTime) : base(id, name, type, location, tags)
 {
     Description          = description;
     Severity             = severity;
     Enabled              = enabled;
     Scopes               = scopes;
     EvaluationFrequency  = evaluationFrequency;
     WindowSize           = windowSize;
     TargetResourceType   = targetResourceType;
     TargetResourceRegion = targetResourceRegion;
     Criteria             = criteria;
     AutoMitigate         = autoMitigate;
     Actions              = actions;
     LastUpdatedTime      = lastUpdatedTime;
 }
Пример #2
0
        public MetricAlertResource(string location, string description, int severity, bool enabled, TimeSpan evaluationFrequency, TimeSpan windowSize, MetricAlertCriteria criteria) : base(location)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }
            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            Description         = description;
            Severity            = severity;
            Enabled             = enabled;
            Scopes              = new ChangeTrackingList <string>();
            EvaluationFrequency = evaluationFrequency;
            WindowSize          = windowSize;
            Criteria            = criteria;
            Actions             = new ChangeTrackingList <MetricAlertAction>();
        }
Пример #3
0
        internal static MetricAlertResource DeserializeMetricAlertResource(JsonElement element)
        {
            Optional <string> id       = default;
            Optional <string> name     = default;
            Optional <string> type     = default;
            string            location = default;
            Optional <IDictionary <string, string> > tags = default;
            string description = default;
            int    severity    = default;
            bool   enabled     = default;
            Optional <IList <string> > scopes                     = default;
            TimeSpan            evaluationFrequency               = default;
            TimeSpan            windowSize                        = default;
            Optional <string>   targetResourceType                = default;
            Optional <string>   targetResourceRegion              = default;
            MetricAlertCriteria criteria                          = default;
            Optional <bool>     autoMitigate                      = default;
            Optional <IList <MetricAlertAction> > actions         = default;
            Optional <DateTimeOffset>             lastUpdatedTime = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("description"))
                        {
                            description = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("severity"))
                        {
                            severity = property0.Value.GetInt32();
                            continue;
                        }
                        if (property0.NameEquals("enabled"))
                        {
                            enabled = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("scopes"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <string> array = new List <string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            scopes = array;
                            continue;
                        }
                        if (property0.NameEquals("evaluationFrequency"))
                        {
                            evaluationFrequency = property0.Value.GetTimeSpan("P");
                            continue;
                        }
                        if (property0.NameEquals("windowSize"))
                        {
                            windowSize = property0.Value.GetTimeSpan("P");
                            continue;
                        }
                        if (property0.NameEquals("targetResourceType"))
                        {
                            targetResourceType = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("targetResourceRegion"))
                        {
                            targetResourceRegion = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("criteria"))
                        {
                            criteria = MetricAlertCriteria.DeserializeMetricAlertCriteria(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("autoMitigate"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            autoMitigate = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("actions"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <MetricAlertAction> array = new List <MetricAlertAction>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(MetricAlertAction.DeserializeMetricAlertAction(item));
                            }
                            actions = array;
                            continue;
                        }
                        if (property0.NameEquals("lastUpdatedTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            lastUpdatedTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new MetricAlertResource(id.Value, name.Value, type.Value, location, Optional.ToDictionary(tags), description, severity, enabled, Optional.ToList(scopes), evaluationFrequency, windowSize, targetResourceType.Value, targetResourceRegion.Value, criteria, Optional.ToNullable(autoMitigate), Optional.ToList(actions), Optional.ToNullable(lastUpdatedTime)));
        }