Пример #1
0
        internal static MetricFeedback DeserializeMetricFeedback(JsonElement element)
        {
            if (element.TryGetProperty("feedbackType", out JsonElement discriminator))
            {
                var discriminatorString = discriminator.GetString();

                switch (discriminatorString)
                {
                case "Anomaly":
                    return(MetricAnomalyFeedback.DeserializeMetricAnomalyFeedback(element));

                case "ChangePoint":
                    return(MetricChangePointFeedback.DeserializeMetricChangePointFeedback(element));

                case "Comment":
                    return(MetricCommentFeedback.DeserializeMetricCommentFeedback(element));

                case "Period":
                    return(MetricPeriodFeedback.DeserializeMetricPeriodFeedback(element));

                default:
                    throw new ArgumentException($"Unknown feedback type returned by the service: {discriminatorString}");
                }
            }
            else
            {
                throw new ArgumentException("The feedback type was not returned by the service");
            }
        }
Пример #2
0
        internal static MetricFeedback DeserializeMetricFeedback(JsonElement element)
        {
            if (element.TryGetProperty("feedbackType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Anomaly":
                    return(MetricAnomalyFeedback.DeserializeMetricAnomalyFeedback(element));

                case "ChangePoint":
                    return(MetricChangePointFeedback.DeserializeMetricChangePointFeedback(element));

                case "Comment":
                    return(MetricCommentFeedback.DeserializeMetricCommentFeedback(element));

                case "Period":
                    return(MetricPeriodFeedback.DeserializeMetricPeriodFeedback(element));
                }
            }
            MetricFeedbackKind        feedbackType  = default;
            Optional <string>         feedbackId    = default;
            Optional <DateTimeOffset> createdTime   = default;
            Optional <string>         userPrincipal = default;
            string         metricId        = default;
            FeedbackFilter dimensionFilter = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("feedbackType"))
                {
                    feedbackType = new MetricFeedbackKind(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("feedbackId"))
                {
                    feedbackId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("createdTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    createdTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("userPrincipal"))
                {
                    userPrincipal = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricId"))
                {
                    metricId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("dimensionFilter"))
                {
                    dimensionFilter = FeedbackFilter.DeserializeFeedbackFilter(property.Value);
                    continue;
                }
            }
            return(new UnknownMetricFeedback(feedbackType, feedbackId.Value, Optional.ToNullable(createdTime), userPrincipal.Value, metricId, dimensionFilter));
        }