| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using System.Text.Json; |
| | 11 | | using Azure.Core; |
| | 12 | |
|
| | 13 | | namespace Azure.Iot.Hub.Service.Models |
| | 14 | | { |
| | 15 | | public partial class TwinData : IUtf8JsonSerializable |
| | 16 | | { |
| | 17 | | void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | 18 | | { |
| 16 | 19 | | writer.WriteStartObject(); |
| 16 | 20 | | if (Optional.IsDefined(DeviceId)) |
| | 21 | | { |
| 16 | 22 | | writer.WritePropertyName("deviceId"); |
| 16 | 23 | | writer.WriteStringValue(DeviceId); |
| | 24 | | } |
| 16 | 25 | | if (Optional.IsDefined(ModuleId)) |
| | 26 | | { |
| 12 | 27 | | writer.WritePropertyName("moduleId"); |
| 12 | 28 | | writer.WriteStringValue(ModuleId); |
| | 29 | | } |
| 16 | 30 | | if (Optional.IsCollectionDefined(Tags)) |
| | 31 | | { |
| 0 | 32 | | writer.WritePropertyName("tags"); |
| 0 | 33 | | writer.WriteStartObject(); |
| 0 | 34 | | foreach (var item in Tags) |
| | 35 | | { |
| 0 | 36 | | writer.WritePropertyName(item.Key); |
| 0 | 37 | | writer.WriteObjectValue(item.Value); |
| | 38 | | } |
| 0 | 39 | | writer.WriteEndObject(); |
| | 40 | | } |
| 16 | 41 | | if (Optional.IsDefined(Properties)) |
| | 42 | | { |
| 16 | 43 | | writer.WritePropertyName("properties"); |
| 16 | 44 | | writer.WriteObjectValue(Properties); |
| | 45 | | } |
| 16 | 46 | | if (Optional.IsDefined(Etag)) |
| | 47 | | { |
| 16 | 48 | | writer.WritePropertyName("etag"); |
| 16 | 49 | | writer.WriteStringValue(Etag); |
| | 50 | | } |
| 16 | 51 | | if (Optional.IsDefined(Version)) |
| | 52 | | { |
| 16 | 53 | | writer.WritePropertyName("version"); |
| 16 | 54 | | writer.WriteNumberValue(Version.Value); |
| | 55 | | } |
| 16 | 56 | | if (Optional.IsDefined(DeviceEtag)) |
| | 57 | | { |
| 16 | 58 | | writer.WritePropertyName("deviceEtag"); |
| 16 | 59 | | writer.WriteStringValue(DeviceEtag); |
| | 60 | | } |
| 16 | 61 | | if (Optional.IsDefined(Status)) |
| | 62 | | { |
| 16 | 63 | | writer.WritePropertyName("status"); |
| 16 | 64 | | writer.WriteStringValue(Status.Value.ToString()); |
| | 65 | | } |
| 16 | 66 | | if (Optional.IsDefined(StatusReason)) |
| | 67 | | { |
| 0 | 68 | | writer.WritePropertyName("statusReason"); |
| 0 | 69 | | writer.WriteStringValue(StatusReason); |
| | 70 | | } |
| 16 | 71 | | if (Optional.IsDefined(StatusUpdateTime)) |
| | 72 | | { |
| 16 | 73 | | writer.WritePropertyName("statusUpdateTime"); |
| 16 | 74 | | writer.WriteStringValue(StatusUpdateTime.Value, "O"); |
| | 75 | | } |
| 16 | 76 | | if (Optional.IsDefined(ConnectionState)) |
| | 77 | | { |
| 16 | 78 | | writer.WritePropertyName("connectionState"); |
| 16 | 79 | | writer.WriteStringValue(ConnectionState.Value.ToString()); |
| | 80 | | } |
| 16 | 81 | | if (Optional.IsDefined(LastActivityTime)) |
| | 82 | | { |
| 16 | 83 | | writer.WritePropertyName("lastActivityTime"); |
| 16 | 84 | | writer.WriteStringValue(LastActivityTime.Value, "O"); |
| | 85 | | } |
| 16 | 86 | | if (Optional.IsDefined(CloudToDeviceMessageCount)) |
| | 87 | | { |
| 16 | 88 | | writer.WritePropertyName("cloudToDeviceMessageCount"); |
| 16 | 89 | | writer.WriteNumberValue(CloudToDeviceMessageCount.Value); |
| | 90 | | } |
| 16 | 91 | | if (Optional.IsDefined(AuthenticationType)) |
| | 92 | | { |
| 16 | 93 | | writer.WritePropertyName("authenticationType"); |
| 16 | 94 | | writer.WriteStringValue(AuthenticationType.Value.ToString()); |
| | 95 | | } |
| 16 | 96 | | if (Optional.IsDefined(X509Thumbprint)) |
| | 97 | | { |
| 16 | 98 | | writer.WritePropertyName("x509Thumbprint"); |
| 16 | 99 | | writer.WriteObjectValue(X509Thumbprint); |
| | 100 | | } |
| 16 | 101 | | if (Optional.IsDefined(Capabilities)) |
| | 102 | | { |
| 4 | 103 | | writer.WritePropertyName("capabilities"); |
| 4 | 104 | | writer.WriteObjectValue(Capabilities); |
| | 105 | | } |
| 16 | 106 | | if (Optional.IsDefined(DeviceScope)) |
| | 107 | | { |
| 0 | 108 | | writer.WritePropertyName("deviceScope"); |
| 0 | 109 | | writer.WriteStringValue(DeviceScope); |
| | 110 | | } |
| 16 | 111 | | if (Optional.IsCollectionDefined(ParentScopes)) |
| | 112 | | { |
| 0 | 113 | | writer.WritePropertyName("parentScopes"); |
| 0 | 114 | | writer.WriteStartArray(); |
| 0 | 115 | | foreach (var item in ParentScopes) |
| | 116 | | { |
| 0 | 117 | | writer.WriteStringValue(item); |
| | 118 | | } |
| 0 | 119 | | writer.WriteEndArray(); |
| | 120 | | } |
| 16 | 121 | | writer.WriteEndObject(); |
| 16 | 122 | | } |
| | 123 | |
|
| | 124 | | internal static TwinData DeserializeTwinData(JsonElement element) |
| | 125 | | { |
| 250 | 126 | | Optional<string> deviceId = default; |
| 250 | 127 | | Optional<string> moduleId = default; |
| 250 | 128 | | Optional<IDictionary<string, object>> tags = default; |
| 250 | 129 | | Optional<TwinProperties> properties = default; |
| 250 | 130 | | Optional<string> etag = default; |
| 250 | 131 | | Optional<long> version = default; |
| 250 | 132 | | Optional<string> deviceEtag = default; |
| 250 | 133 | | Optional<TwinStatus> status = default; |
| 250 | 134 | | Optional<string> statusReason = default; |
| 250 | 135 | | Optional<DateTimeOffset> statusUpdateTime = default; |
| 250 | 136 | | Optional<TwinConnectionState> connectionState = default; |
| 250 | 137 | | Optional<DateTimeOffset> lastActivityTime = default; |
| 250 | 138 | | Optional<int> cloudToDeviceMessageCount = default; |
| 250 | 139 | | Optional<TwinAuthenticationType> authenticationType = default; |
| 250 | 140 | | Optional<X509Thumbprint> x509Thumbprint = default; |
| 250 | 141 | | Optional<DeviceCapabilities> capabilities = default; |
| 250 | 142 | | Optional<string> deviceScope = default; |
| 250 | 143 | | Optional<IList<string>> parentScopes = default; |
| 7224 | 144 | | foreach (var property in element.EnumerateObject()) |
| | 145 | | { |
| 3362 | 146 | | if (property.NameEquals("deviceId")) |
| | 147 | | { |
| 250 | 148 | | deviceId = property.Value.GetString(); |
| 250 | 149 | | continue; |
| | 150 | | } |
| 3112 | 151 | | if (property.NameEquals("moduleId")) |
| | 152 | | { |
| 132 | 153 | | moduleId = property.Value.GetString(); |
| 132 | 154 | | continue; |
| | 155 | | } |
| 2980 | 156 | | if (property.NameEquals("tags")) |
| | 157 | | { |
| 0 | 158 | | Dictionary<string, object> dictionary = new Dictionary<string, object>(); |
| 0 | 159 | | foreach (var property0 in property.Value.EnumerateObject()) |
| | 160 | | { |
| 0 | 161 | | dictionary.Add(property0.Name, property0.Value.GetObject()); |
| | 162 | | } |
| 0 | 163 | | tags = dictionary; |
| 0 | 164 | | continue; |
| | 165 | | } |
| 2980 | 166 | | if (property.NameEquals("properties")) |
| | 167 | | { |
| 250 | 168 | | properties = TwinProperties.DeserializeTwinProperties(property.Value); |
| 250 | 169 | | continue; |
| | 170 | | } |
| 2730 | 171 | | if (property.NameEquals("etag")) |
| | 172 | | { |
| 250 | 173 | | etag = property.Value.GetString(); |
| 250 | 174 | | continue; |
| | 175 | | } |
| 2480 | 176 | | if (property.NameEquals("version")) |
| | 177 | | { |
| 250 | 178 | | version = property.Value.GetInt64(); |
| 250 | 179 | | continue; |
| | 180 | | } |
| 2230 | 181 | | if (property.NameEquals("deviceEtag")) |
| | 182 | | { |
| 250 | 183 | | deviceEtag = property.Value.GetString(); |
| 250 | 184 | | continue; |
| | 185 | | } |
| 1980 | 186 | | if (property.NameEquals("status")) |
| | 187 | | { |
| 250 | 188 | | status = new TwinStatus(property.Value.GetString()); |
| 250 | 189 | | continue; |
| | 190 | | } |
| 1730 | 191 | | if (property.NameEquals("statusReason")) |
| | 192 | | { |
| 0 | 193 | | statusReason = property.Value.GetString(); |
| 0 | 194 | | continue; |
| | 195 | | } |
| 1730 | 196 | | if (property.NameEquals("statusUpdateTime")) |
| | 197 | | { |
| 250 | 198 | | statusUpdateTime = property.Value.GetDateTimeOffset("O"); |
| 250 | 199 | | continue; |
| | 200 | | } |
| 1480 | 201 | | if (property.NameEquals("connectionState")) |
| | 202 | | { |
| 250 | 203 | | connectionState = new TwinConnectionState(property.Value.GetString()); |
| 250 | 204 | | continue; |
| | 205 | | } |
| 1230 | 206 | | if (property.NameEquals("lastActivityTime")) |
| | 207 | | { |
| 250 | 208 | | lastActivityTime = property.Value.GetDateTimeOffset("O"); |
| 250 | 209 | | continue; |
| | 210 | | } |
| 980 | 211 | | if (property.NameEquals("cloudToDeviceMessageCount")) |
| | 212 | | { |
| 250 | 213 | | cloudToDeviceMessageCount = property.Value.GetInt32(); |
| 250 | 214 | | continue; |
| | 215 | | } |
| 730 | 216 | | if (property.NameEquals("authenticationType")) |
| | 217 | | { |
| 250 | 218 | | authenticationType = new TwinAuthenticationType(property.Value.GetString()); |
| 250 | 219 | | continue; |
| | 220 | | } |
| 480 | 221 | | if (property.NameEquals("x509Thumbprint")) |
| | 222 | | { |
| 250 | 223 | | x509Thumbprint = X509Thumbprint.DeserializeX509Thumbprint(property.Value); |
| 250 | 224 | | continue; |
| | 225 | | } |
| 230 | 226 | | if (property.NameEquals("capabilities")) |
| | 227 | | { |
| 230 | 228 | | capabilities = DeviceCapabilities.DeserializeDeviceCapabilities(property.Value); |
| 230 | 229 | | continue; |
| | 230 | | } |
| 0 | 231 | | if (property.NameEquals("deviceScope")) |
| | 232 | | { |
| 0 | 233 | | deviceScope = property.Value.GetString(); |
| 0 | 234 | | continue; |
| | 235 | | } |
| 0 | 236 | | if (property.NameEquals("parentScopes")) |
| | 237 | | { |
| 0 | 238 | | List<string> array = new List<string>(); |
| 0 | 239 | | foreach (var item in property.Value.EnumerateArray()) |
| | 240 | | { |
| 0 | 241 | | array.Add(item.GetString()); |
| | 242 | | } |
| 0 | 243 | | parentScopes = array; |
| | 244 | | continue; |
| | 245 | | } |
| | 246 | | } |
| 250 | 247 | | return new TwinData(deviceId.Value, moduleId.Value, Optional.ToDictionary(tags), properties.Value, etag.Valu |
| | 248 | | } |
| | 249 | | } |
| | 250 | | } |