internal static LocationThresholdRuleCondition DeserializeLocationThresholdRuleCondition(JsonElement element) { Optional <TimeSpan> windowSize = default; int failedLocationCount = default; string odataType = default; Optional <RuleDataSource> dataSource = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("windowSize")) { windowSize = property.Value.GetTimeSpan("P"); continue; } if (property.NameEquals("failedLocationCount")) { failedLocationCount = property.Value.GetInt32(); continue; } if (property.NameEquals("odata.type")) { odataType = property.Value.GetString(); continue; } if (property.NameEquals("dataSource")) { dataSource = RuleDataSource.DeserializeRuleDataSource(property.Value); continue; } } return(new LocationThresholdRuleCondition(odataType, dataSource.Value, Optional.ToNullable(windowSize), failedLocationCount)); }
internal static RuleCondition DeserializeRuleCondition(JsonElement element) { if (element.TryGetProperty("odata.type", out JsonElement discriminator)) { switch (discriminator.GetString()) { case "Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition": return(LocationThresholdRuleCondition.DeserializeLocationThresholdRuleCondition(element)); case "Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition": return(ManagementEventRuleCondition.DeserializeManagementEventRuleCondition(element)); case "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition": return(ThresholdRuleCondition.DeserializeThresholdRuleCondition(element)); } } string odataType = default; Optional <RuleDataSource> dataSource = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("odata.type")) { odataType = property.Value.GetString(); continue; } if (property.NameEquals("dataSource")) { dataSource = RuleDataSource.DeserializeRuleDataSource(property.Value); continue; } } return(new RuleCondition(odataType, dataSource.Value)); }
internal static ManagementEventRuleCondition DeserializeManagementEventRuleCondition(JsonElement element) { Optional <ManagementEventAggregationCondition> aggregation = default; string odataType = default; Optional <RuleDataSource> dataSource = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("aggregation")) { aggregation = ManagementEventAggregationCondition.DeserializeManagementEventAggregationCondition(property.Value); continue; } if (property.NameEquals("odata.type")) { odataType = property.Value.GetString(); continue; } if (property.NameEquals("dataSource")) { dataSource = RuleDataSource.DeserializeRuleDataSource(property.Value); continue; } } return(new ManagementEventRuleCondition(odataType, dataSource.Value, aggregation.Value)); }
internal static ThresholdRuleCondition DeserializeThresholdRuleCondition(JsonElement element) { ConditionOperator @operator = default; double threshold = default; Optional <TimeSpan> windowSize = default; Optional <TimeAggregationOperator> timeAggregation = default; string odataType = default; Optional <RuleDataSource> dataSource = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("operator")) { @operator = property.Value.GetString().ToConditionOperator(); continue; } if (property.NameEquals("threshold")) { threshold = property.Value.GetDouble(); continue; } if (property.NameEquals("windowSize")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } windowSize = property.Value.GetTimeSpan("P"); continue; } if (property.NameEquals("timeAggregation")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } timeAggregation = property.Value.GetString().ToTimeAggregationOperator(); continue; } if (property.NameEquals("odata.type")) { odataType = property.Value.GetString(); continue; } if (property.NameEquals("dataSource")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } dataSource = RuleDataSource.DeserializeRuleDataSource(property.Value); continue; } } return(new ThresholdRuleCondition(odataType, dataSource.Value, @operator, threshold, Optional.ToNullable(windowSize), Optional.ToNullable(timeAggregation))); }