internal TwinConfiguration(string id, string schemaVersion, IDictionary <string, string> labels, ConfigurationContent content, string targetCondition, DateTimeOffset?createdTimeUtc, DateTimeOffset?lastUpdatedTimeUtc, int?priority, ConfigurationMetrics systemMetrics, ConfigurationMetrics metrics, string etag)
 {
     Id                 = id;
     SchemaVersion      = schemaVersion;
     Labels             = labels;
     Content            = content;
     TargetCondition    = targetCondition;
     CreatedTimeUtc     = createdTimeUtc;
     LastUpdatedTimeUtc = lastUpdatedTimeUtc;
     Priority           = priority;
     SystemMetrics      = systemMetrics;
     Metrics            = metrics;
     Etag               = etag;
 }
        internal static TwinConfiguration DeserializeTwinConfiguration(JsonElement element)
        {
            Optional <string> id            = default;
            Optional <string> schemaVersion = default;
            Optional <IDictionary <string, string> > labels    = default;
            Optional <ConfigurationContent>          content   = default;
            Optional <string>               targetCondition    = default;
            Optional <DateTimeOffset>       createdTimeUtc     = default;
            Optional <DateTimeOffset>       lastUpdatedTimeUtc = default;
            Optional <int>                  priority           = default;
            Optional <ConfigurationMetrics> systemMetrics      = default;
            Optional <ConfigurationMetrics> metrics            = default;
            Optional <string>               etag = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("schemaVersion"))
                {
                    schemaVersion = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("labels"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    labels = dictionary;
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    content = ConfigurationContent.DeserializeConfigurationContent(property.Value);
                    continue;
                }
                if (property.NameEquals("targetCondition"))
                {
                    targetCondition = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("createdTimeUtc"))
                {
                    createdTimeUtc = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lastUpdatedTimeUtc"))
                {
                    lastUpdatedTimeUtc = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("priority"))
                {
                    priority = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("systemMetrics"))
                {
                    systemMetrics = ConfigurationMetrics.DeserializeConfigurationMetrics(property.Value);
                    continue;
                }
                if (property.NameEquals("metrics"))
                {
                    metrics = ConfigurationMetrics.DeserializeConfigurationMetrics(property.Value);
                    continue;
                }
                if (property.NameEquals("etag"))
                {
                    etag = property.Value.GetString();
                    continue;
                }
            }
            return(new TwinConfiguration(id.Value, schemaVersion.Value, Optional.ToDictionary(labels), content.Value, targetCondition.Value, Optional.ToNullable(createdTimeUtc), Optional.ToNullable(lastUpdatedTimeUtc), Optional.ToNullable(priority), systemMetrics.Value, metrics.Value, etag.Value));
        }
Ejemplo n.º 3
0
        internal static TwinConfiguration DeserializeTwinConfiguration(JsonElement element)
        {
            string id            = default;
            string schemaVersion = default;
            IDictionary <string, string> labels     = default;
            ConfigurationContent         content    = default;
            string               targetCondition    = default;
            DateTimeOffset?      createdTimeUtc     = default;
            DateTimeOffset?      lastUpdatedTimeUtc = default;
            int?                 priority           = default;
            ConfigurationMetrics systemMetrics      = default;
            ConfigurationMetrics metrics            = default;
            string               etag = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("schemaVersion"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    schemaVersion = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("labels"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.Value.ValueKind == JsonValueKind.Null)
                        {
                            dictionary.Add(property0.Name, null);
                        }
                        else
                        {
                            dictionary.Add(property0.Name, property0.Value.GetString());
                        }
                    }
                    labels = dictionary;
                    continue;
                }
                if (property.NameEquals("content"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    content = ConfigurationContent.DeserializeConfigurationContent(property.Value);
                    continue;
                }
                if (property.NameEquals("targetCondition"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    targetCondition = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("createdTimeUtc"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    createdTimeUtc = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lastUpdatedTimeUtc"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    lastUpdatedTimeUtc = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("priority"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    priority = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("systemMetrics"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    systemMetrics = ConfigurationMetrics.DeserializeConfigurationMetrics(property.Value);
                    continue;
                }
                if (property.NameEquals("metrics"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    metrics = ConfigurationMetrics.DeserializeConfigurationMetrics(property.Value);
                    continue;
                }
                if (property.NameEquals("etag"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    etag = property.Value.GetString();
                    continue;
                }
            }
            return(new TwinConfiguration(id, schemaVersion, labels, content, targetCondition, createdTimeUtc, lastUpdatedTimeUtc, priority, systemMetrics, metrics, etag));
        }