internal static ConnectivityInformation DeserializeConnectivityInformation(JsonElement element)
        {
            Optional <IReadOnlyList <ConnectivityHop> > hops = default;
            Optional <ConnectionStatus> connectionStatus     = default;
            Optional <int> avgLatencyInMs = default;
            Optional <int> minLatencyInMs = default;
            Optional <int> maxLatencyInMs = default;
            Optional <int> probesSent     = default;
            Optional <int> probesFailed   = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("hops"))
                {
                    List <ConnectivityHop> array = new List <ConnectivityHop>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ConnectivityHop.DeserializeConnectivityHop(item));
                    }
                    hops = array;
                    continue;
                }
                if (property.NameEquals("connectionStatus"))
                {
                    connectionStatus = new ConnectionStatus(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("avgLatencyInMs"))
                {
                    avgLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("minLatencyInMs"))
                {
                    minLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("maxLatencyInMs"))
                {
                    maxLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesSent"))
                {
                    probesSent = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesFailed"))
                {
                    probesFailed = property.Value.GetInt32();
                    continue;
                }
            }
            return(new ConnectivityInformation(Optional.ToList(hops), Optional.ToNullable(connectionStatus), Optional.ToNullable(avgLatencyInMs), Optional.ToNullable(minLatencyInMs), Optional.ToNullable(maxLatencyInMs), Optional.ToNullable(probesSent), Optional.ToNullable(probesFailed)));
        }
        internal static ConnectionStateSnapshot DeserializeConnectionStateSnapshot(JsonElement element)
        {
            Optional <ConnectionState> connectionState       = default;
            Optional <DateTimeOffset>  startTime             = default;
            Optional <DateTimeOffset>  endTime               = default;
            Optional <EvaluationState> evaluationState       = default;
            Optional <int>             avgLatencyInMs        = default;
            Optional <int>             minLatencyInMs        = default;
            Optional <int>             maxLatencyInMs        = default;
            Optional <int>             probesSent            = default;
            Optional <int>             probesFailed          = default;
            Optional <IReadOnlyList <ConnectivityHop> > hops = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("connectionState"))
                {
                    connectionState = new ConnectionState(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("evaluationState"))
                {
                    evaluationState = new EvaluationState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("avgLatencyInMs"))
                {
                    avgLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("minLatencyInMs"))
                {
                    minLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("maxLatencyInMs"))
                {
                    maxLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesSent"))
                {
                    probesSent = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesFailed"))
                {
                    probesFailed = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("hops"))
                {
                    List <ConnectivityHop> array = new List <ConnectivityHop>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ConnectivityHop.DeserializeConnectivityHop(item));
                    }
                    hops = array;
                    continue;
                }
            }
            return(new ConnectionStateSnapshot(Optional.ToNullable(connectionState), Optional.ToNullable(startTime), Optional.ToNullable(endTime), Optional.ToNullable(evaluationState), Optional.ToNullable(avgLatencyInMs), Optional.ToNullable(minLatencyInMs), Optional.ToNullable(maxLatencyInMs), Optional.ToNullable(probesSent), Optional.ToNullable(probesFailed), Optional.ToList(hops)));
        }
Exemplo n.º 3
0
        internal static ConnectionStateSnapshot DeserializeConnectionStateSnapshot(JsonElement element)
        {
            ConnectionState?connectionState      = default;
            DateTimeOffset? startTime            = default;
            DateTimeOffset? endTime              = default;
            EvaluationState?evaluationState      = default;
            int?            avgLatencyInMs       = default;
            int?            minLatencyInMs       = default;
            int?            maxLatencyInMs       = default;
            int?            probesSent           = default;
            int?            probesFailed         = default;
            IReadOnlyList <ConnectivityHop> hops = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("connectionState"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    connectionState = new ConnectionState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("startTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    startTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("endTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    endTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("evaluationState"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    evaluationState = new EvaluationState(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("avgLatencyInMs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    avgLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("minLatencyInMs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    minLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("maxLatencyInMs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    maxLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesSent"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    probesSent = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesFailed"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    probesFailed = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("hops"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ConnectivityHop> array = new List <ConnectivityHop>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ConnectivityHop.DeserializeConnectivityHop(item));
                        }
                    }
                    hops = array;
                    continue;
                }
            }
            return(new ConnectionStateSnapshot(connectionState, startTime, endTime, evaluationState, avgLatencyInMs, minLatencyInMs, maxLatencyInMs, probesSent, probesFailed, hops));
        }
        internal static ConnectivityInformation DeserializeConnectivityInformation(JsonElement element)
        {
            IReadOnlyList <ConnectivityHop> hops = default;
            ConnectionStatus?connectionStatus    = default;
            int?avgLatencyInMs = default;
            int?minLatencyInMs = default;
            int?maxLatencyInMs = default;
            int?probesSent     = default;
            int?probesFailed   = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("hops"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ConnectivityHop> array = new List <ConnectivityHop>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ConnectivityHop.DeserializeConnectivityHop(item));
                        }
                    }
                    hops = array;
                    continue;
                }
                if (property.NameEquals("connectionStatus"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    connectionStatus = new ConnectionStatus(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("avgLatencyInMs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    avgLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("minLatencyInMs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    minLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("maxLatencyInMs"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    maxLatencyInMs = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesSent"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    probesSent = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("probesFailed"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    probesFailed = property.Value.GetInt32();
                    continue;
                }
            }
            return(new ConnectivityInformation(hops, connectionStatus, avgLatencyInMs, minLatencyInMs, maxLatencyInMs, probesSent, probesFailed));
        }