-
Notifications
You must be signed in to change notification settings - Fork 259
/
BasicDigitalTwin.xml
302 lines (293 loc) · 17 KB
/
BasicDigitalTwin.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<Type Name="BasicDigitalTwin" FullName="Azure.DigitalTwins.Core.BasicDigitalTwin">
<TypeSignature Language="C#" Value="public class BasicDigitalTwin" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit BasicDigitalTwin extends System.Object" />
<TypeSignature Language="DocId" Value="T:Azure.DigitalTwins.Core.BasicDigitalTwin" />
<TypeSignature Language="VB.NET" Value="Public Class BasicDigitalTwin" />
<TypeSignature Language="F#" Value="type BasicDigitalTwin = class" />
<AssemblyInfo>
<AssemblyName>Azure.DigitalTwins.Core</AssemblyName>
<AssemblyVersion>1.2.2.0</AssemblyVersion>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Text.Json.Serialization.JsonConverter(typeof(Azure.DigitalTwins.Core.BasicDigitalTwinJsonConverter))]</AttributeName>
<AttributeName Language="F#">[<System.Text.Json.Serialization.JsonConverter(typeof(Azure.DigitalTwins.Core.BasicDigitalTwinJsonConverter))>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>
An optional, helper class for deserializing a digital twin.
</summary>
<remarks>
<para>
This helper class will only work with <see cref="N:System.Text.Json" />. When used with the <see cref="T:Azure.Core.Serialization.ObjectSerializer" />,
parameter to <see cref="T:Azure.DigitalTwins.Core.DigitalTwinsClientOptions" /> it will only work with the default (<see cref="T:Azure.Core.Serialization.JsonObjectSerializer" />).
</para>
For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/digitaltwins/Azure.DigitalTwins.Core/samples">our repo samples</see>.
</remarks>
<example>
Here's an example of how to use the BasicDigitalTwin helper class to serialize and create a digital twin.
<code snippet="Snippet:DigitalTwinsSampleCreateBasicTwin" language="csharp">
// Create digital twin with component payload using the BasicDigitalTwin serialization helper
var basicTwin = new BasicDigitalTwin
{
Id = basicDtId,
// model Id of digital twin
Metadata =
{
ModelId = modelId,
PropertyMetadata = new Dictionary<string, DigitalTwinPropertyMetadata>
{
{
"Prop2",
new DigitalTwinPropertyMetadata
{
// must always be serialized as ISO 8601
SourceTime = DateTimeOffset.UtcNow,
}
}
},
},
Contents =
{
// digital twin properties
{ "Prop1", "Value1" },
{ "Prop2", 987 },
// component
{
"Component1",
new BasicDigitalTwinComponent
{
// writeable component metadata
Metadata = new Dictionary<string, DigitalTwinPropertyMetadata>
{
{
"ComponentProp2",
new DigitalTwinPropertyMetadata
{
// must always be serialized as ISO 8601
SourceTime = DateTimeOffset.UtcNow,
}
}
},
// component properties
Contents =
{
{ "ComponentProp1", "Component value 1" },
{ "ComponentProp2", 123 },
},
}
},
},
};
Response<BasicDigitalTwin> createDigitalTwinResponse = await client.CreateOrReplaceDigitalTwinAsync(basicDtId, basicTwin);
Console.WriteLine($"Created digital twin '{createDigitalTwinResponse.Value.Id}'.");
</code>
Here's an example of how to use the BasicDigitalTwin helper class to get and deserialize a digital twin.
<code snippet="Snippet:DigitalTwinsSampleGetBasicDigitalTwin" language="csharp">
Response<BasicDigitalTwin> getBasicDtResponse = await client.GetDigitalTwinAsync<BasicDigitalTwin>(basicDtId);
BasicDigitalTwin basicDt = getBasicDtResponse.Value;
// Must cast Component1 as a JsonElement and get its raw text in order to deserialize it as a dictionary
string component1RawText = ((JsonElement)basicDt.Contents["Component1"]).GetRawText();
var component1 = JsonSerializer.Deserialize<BasicDigitalTwinComponent>(component1RawText);
Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id}:\n\t" +
$"ETag: {basicDt.ETag}\n\t" +
$"ModelId: {basicDt.Metadata.ModelId}\n\t" +
$"LastUpdatedOn: {basicDt.LastUpdatedOn}\n\t" +
$"Prop1: {basicDt.Contents["Prop1"]}, last updated on {basicDt.Metadata.PropertyMetadata["Prop1"].LastUpdatedOn}\n\t" +
$"Prop2: {basicDt.Contents["Prop2"]}, last updated on {basicDt.Metadata.PropertyMetadata["Prop2"].LastUpdatedOn} and sourced at {basicDt.Metadata.PropertyMetadata["Prop2"].SourceTime}\n\t" +
$"Component1.LastUpdatedOn: {component1.LastUpdatedOn}\n\t" +
$"Component1.Prop1: {component1.Contents["ComponentProp1"]}, last updated on: {component1.Metadata["ComponentProp1"].LastUpdatedOn}\n\t" +
$"Component1.Prop2: {component1.Contents["ComponentProp2"]}, last updated on: {component1.Metadata["ComponentProp2"].LastUpdatedOn} and sourced at: {component1.Metadata["ComponentProp2"].SourceTime}");
</code></example>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public BasicDigitalTwin ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:Azure.DigitalTwins.Core.BasicDigitalTwin.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.DigitalTwins.Core</AssemblyName>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Contents">
<MemberSignature Language="C#" Value="public System.Collections.Generic.IDictionary<string,object> Contents { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Collections.Generic.IDictionary`2<string, object> Contents" />
<MemberSignature Language="DocId" Value="P:Azure.DigitalTwins.Core.BasicDigitalTwin.Contents" />
<MemberSignature Language="VB.NET" Value="Public Property Contents As IDictionary(Of String, Object)" />
<MemberSignature Language="F#" Value="member this.Contents : System.Collections.Generic.IDictionary<string, obj> with get, set" Usage="Azure.DigitalTwins.Core.BasicDigitalTwin.Contents" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.DigitalTwins.Core</AssemblyName>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Text.Json.Serialization.JsonExtensionData]</AttributeName>
<AttributeName Language="F#">[<System.Text.Json.Serialization.JsonExtensionData>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Collections.Generic.IDictionary<System.String,System.Object></ReturnType>
</ReturnValue>
<Docs>
<summary>
This field will contain properties and components as defined in the contents section of the DTDL definition of the twin.
</summary>
<value>To be added.</value>
<remarks>
If the property is a component, use the <see cref="T:Azure.DigitalTwins.Core.BasicDigitalTwinComponent" /> class to deserialize the payload.
</remarks>
<example>
<code snippet="Snippet:DigitalTwinsSampleGetBasicDigitalTwin" language="csharp">
Response<BasicDigitalTwin> getBasicDtResponse = await client.GetDigitalTwinAsync<BasicDigitalTwin>(basicDtId);
BasicDigitalTwin basicDt = getBasicDtResponse.Value;
// Must cast Component1 as a JsonElement and get its raw text in order to deserialize it as a dictionary
string component1RawText = ((JsonElement)basicDt.Contents["Component1"]).GetRawText();
var component1 = JsonSerializer.Deserialize<BasicDigitalTwinComponent>(component1RawText);
Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id}:\n\t" +
$"ETag: {basicDt.ETag}\n\t" +
$"ModelId: {basicDt.Metadata.ModelId}\n\t" +
$"LastUpdatedOn: {basicDt.LastUpdatedOn}\n\t" +
$"Prop1: {basicDt.Contents["Prop1"]}, last updated on {basicDt.Metadata.PropertyMetadata["Prop1"].LastUpdatedOn}\n\t" +
$"Prop2: {basicDt.Contents["Prop2"]}, last updated on {basicDt.Metadata.PropertyMetadata["Prop2"].LastUpdatedOn} and sourced at {basicDt.Metadata.PropertyMetadata["Prop2"].SourceTime}\n\t" +
$"Component1.LastUpdatedOn: {component1.LastUpdatedOn}\n\t" +
$"Component1.Prop1: {component1.Contents["ComponentProp1"]}, last updated on: {component1.Metadata["ComponentProp1"].LastUpdatedOn}\n\t" +
$"Component1.Prop2: {component1.Contents["ComponentProp2"]}, last updated on: {component1.Metadata["ComponentProp2"].LastUpdatedOn} and sourced at: {component1.Metadata["ComponentProp2"].SourceTime}");
</code>
</example>
</Docs>
</Member>
<Member MemberName="ETag">
<MemberSignature Language="C#" Value="public Azure.ETag? ETag { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Nullable`1<valuetype Azure.ETag> ETag" />
<MemberSignature Language="DocId" Value="P:Azure.DigitalTwins.Core.BasicDigitalTwin.ETag" />
<MemberSignature Language="VB.NET" Value="Public Property ETag As Nullable(Of ETag)" />
<MemberSignature Language="F#" Value="member this.ETag : Nullable<Azure.ETag> with get, set" Usage="Azure.DigitalTwins.Core.BasicDigitalTwin.ETag" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.DigitalTwins.Core</AssemblyName>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Text.Json.Serialization.JsonConverter(typeof(Azure.DigitalTwins.Core.Serialization.OptionalETagConverter))]</AttributeName>
<AttributeName Language="F#">[<System.Text.Json.Serialization.JsonConverter(typeof(Azure.DigitalTwins.Core.Serialization.OptionalETagConverter))>]</AttributeName>
</Attribute>
<Attribute>
<AttributeName Language="C#">[System.Text.Json.Serialization.JsonPropertyName("$etag")]</AttributeName>
<AttributeName Language="F#">[<System.Text.Json.Serialization.JsonPropertyName("$etag")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Nullable<Azure.ETag></ReturnType>
</ReturnValue>
<Docs>
<summary>
A string representing a weak ETag for the entity that this request performs an operation against, as per RFC7232.
</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Id">
<MemberSignature Language="C#" Value="public string Id { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Id" />
<MemberSignature Language="DocId" Value="P:Azure.DigitalTwins.Core.BasicDigitalTwin.Id" />
<MemberSignature Language="VB.NET" Value="Public Property Id As String" />
<MemberSignature Language="F#" Value="member this.Id : string with get, set" Usage="Azure.DigitalTwins.Core.BasicDigitalTwin.Id" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.DigitalTwins.Core</AssemblyName>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Text.Json.Serialization.JsonPropertyName("$dtId")]</AttributeName>
<AttributeName Language="F#">[<System.Text.Json.Serialization.JsonPropertyName("$dtId")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>
The unique Id of the digital twin in a digital twins instance. This field is present on every digital twin.
</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="LastUpdatedOn">
<MemberSignature Language="C#" Value="public DateTimeOffset? LastUpdatedOn { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Nullable`1<valuetype System.DateTimeOffset> LastUpdatedOn" />
<MemberSignature Language="DocId" Value="P:Azure.DigitalTwins.Core.BasicDigitalTwin.LastUpdatedOn" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property LastUpdatedOn As Nullable(Of DateTimeOffset)" />
<MemberSignature Language="F#" Value="member this.LastUpdatedOn : Nullable<DateTimeOffset>" Usage="Azure.DigitalTwins.Core.BasicDigitalTwin.LastUpdatedOn" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.DigitalTwins.Core</AssemblyName>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Text.Json.Serialization.JsonPropertyName("$lastUpdateTime")]</AttributeName>
<AttributeName Language="F#">[<System.Text.Json.Serialization.JsonPropertyName("$lastUpdateTime")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Nullable<System.DateTimeOffset></ReturnType>
</ReturnValue>
<Docs>
<summary>
The date and time the twin was last updated.
</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Metadata">
<MemberSignature Language="C#" Value="public Azure.DigitalTwins.Core.DigitalTwinMetadata Metadata { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class Azure.DigitalTwins.Core.DigitalTwinMetadata Metadata" />
<MemberSignature Language="DocId" Value="P:Azure.DigitalTwins.Core.BasicDigitalTwin.Metadata" />
<MemberSignature Language="VB.NET" Value="Public Property Metadata As DigitalTwinMetadata" />
<MemberSignature Language="F#" Value="member this.Metadata : Azure.DigitalTwins.Core.DigitalTwinMetadata with get, set" Usage="Azure.DigitalTwins.Core.BasicDigitalTwin.Metadata" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Azure.DigitalTwins.Core</AssemblyName>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Text.Json.Serialization.JsonPropertyName("$metadata")]</AttributeName>
<AttributeName Language="F#">[<System.Text.Json.Serialization.JsonPropertyName("$metadata")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>Azure.DigitalTwins.Core.DigitalTwinMetadata</ReturnType>
</ReturnValue>
<Docs>
<summary>
Information about the model a digital twin conforms to.
This field is present on every digital twin.
</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>