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;
 }
Esempio n. 2
0
        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"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    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"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    content = ConfigurationContent.DeserializeConfigurationContent(property.Value);
                    continue;
                }
                if (property.NameEquals("targetCondition"))
                {
                    targetCondition = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("createdTimeUtc"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    createdTimeUtc = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lastUpdatedTimeUtc"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    lastUpdatedTimeUtc = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("priority"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    priority = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("systemMetrics"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    systemMetrics = ConfigurationMetrics.DeserializeConfigurationMetrics(property.Value);
                    continue;
                }
                if (property.NameEquals("metrics"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    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));
        }