예제 #1
0
 internal ModelInfo(int?slidingWindow, AlignPolicy alignPolicy, string source, DateTimeOffset startTime, DateTimeOffset endTime, string displayName, ModelStatus?status, IReadOnlyList <ErrorResponse> errors, DiagnosticsInfo diagnosticsInfo)
 {
     SlidingWindow   = slidingWindow;
     AlignPolicy     = alignPolicy;
     Source          = source;
     StartTime       = startTime;
     EndTime         = endTime;
     DisplayName     = displayName;
     Status          = status;
     Errors          = errors;
     DiagnosticsInfo = diagnosticsInfo;
 }
        internal static ModelInfo DeserializeModelInfo(JsonElement element)
        {
            Optional <int>         slidingWindow             = default;
            Optional <AlignPolicy> alignPolicy               = default;
            string                 source                    = default;
            DateTimeOffset         startTime                 = default;
            DateTimeOffset         endTime                   = default;
            Optional <string>      displayName               = default;
            Optional <ModelStatus> status                    = default;
            Optional <IReadOnlyList <ErrorResponse> > errors = default;
            Optional <DiagnosticsInfo> diagnosticsInfo       = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("slidingWindow"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    slidingWindow = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("alignPolicy"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    alignPolicy = AlignPolicy.DeserializeAlignPolicy(property.Value);
                    continue;
                }
                if (property.NameEquals("source"))
                {
                    source = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("startTime"))
                {
                    startTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("endTime"))
                {
                    endTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("displayName"))
                {
                    displayName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("status"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    status = property.Value.GetString().ToModelStatus();
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ErrorResponse> array = new List <ErrorResponse>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ErrorResponse.DeserializeErrorResponse(item));
                    }
                    errors = array;
                    continue;
                }
                if (property.NameEquals("diagnosticsInfo"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    diagnosticsInfo = DiagnosticsInfo.DeserializeDiagnosticsInfo(property.Value);
                    continue;
                }
            }
            return(new ModelInfo(Optional.ToNullable(slidingWindow), alignPolicy.Value, source, startTime, endTime, displayName.Value, Optional.ToNullable(status), Optional.ToList(errors), diagnosticsInfo.Value));
        }
        public static ModelInfo ModelInfo(int?slidingWindow = null, AlignPolicy alignPolicy = null, string source = null, DateTimeOffset startTime = default, DateTimeOffset endTime = default, string displayName = null, ModelStatus?status = null, IEnumerable <ErrorResponse> errors = null, DiagnosticsInfo diagnosticsInfo = null)
        {
            errors ??= new List <ErrorResponse>();

            return(new ModelInfo(slidingWindow, alignPolicy, source, startTime, endTime, displayName, status, errors?.ToList(), diagnosticsInfo));
        }