Skip to content

Commit

Permalink
samples(adt): Update component property to be an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
abhipsaMisra committed Jun 4, 2020
1 parent d07dcc5 commit 3a45987
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)

// Then we create models
Response<IReadOnlyList<Models.ModelData>> createModelsResponse = await client
.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload })
;
.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload });
Console.WriteLine($"Successfully created models Ids {componentModelId} and {modelId} with response {createModelsResponse.GetRawResponse().Status}.");

#region Snippet:DigitalTwinsSampleCreateBasicTwin
Expand All @@ -56,7 +55,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
var componentMetadata = new ModelProperties();
componentMetadata.Metadata.ModelId = componentModelId;
componentMetadata.CustomProperties.Add("ComponentProp1", "ComponentValue1");
componentMetadata.CustomProperties.Add("ComponentProp2", "ComponentValue2");
componentMetadata.CustomProperties.Add("ComponentProp2", 123);

basicDigitalTwin.CustomProperties.Add("Component1", componentMetadata);

Expand All @@ -82,9 +81,9 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
string component1RawText = ((JsonElement)basicDt.CustomProperties["Component1"]).GetRawText();
var component1 = JsonSerializer.Deserialize<IDictionary<string, object>>(component1RawText);

Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id} with ETag {basicDt.ETag} " +
$"and Prop1 '{basicDt.CustomProperties["Prop1"]}', Prop2 '{basicDt.CustomProperties["Prop2"]}', " +
$"ComponentProp1 '{component1["ComponentProp1"]}', ComponentProp2 '{component1["ComponentProp2"]}'");
Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id} with ETag {basicDt.ETag} " +
$"and Prop1: '{basicDt.CustomProperties["Prop1"]}', Prop2: '{basicDt.CustomProperties["Prop2"]}'," +
$"ComponentProp1: '{component1["ComponentProp1"]}', ComponentProp2: {component1["ComponentProp2"]}");
}

#endregion Snippet:DigitalTwinsSampleGetBasicDigitalTwin
Expand All @@ -106,7 +105,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
{
Metadata = new Component1Metadata { ModelId = componentModelId },
ComponentProp1 = "Component prop1 val",
ComponentProp2 = "Component prop2 val",
ComponentProp2 = 123,
}
};
string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
Expand All @@ -126,8 +125,8 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
{
CustomDigitalTwin customDt = JsonSerializer.Deserialize<CustomDigitalTwin>(getCustomDtResponse.Value);
Console.WriteLine($"Retrieved and deserialized digital twin {customDt.Id} with ETag {customDt.ETag} " +
$"and Prop1 '{customDt.Prop1}', Prop2 '{customDt.Prop2}', " +
$"ComponentProp1 '{customDt.Component1.ComponentProp1}, ComponentProp2 '{customDt.Component1.ComponentProp2}'");
$"and Prop1: '{customDt.Prop1}', Prop2: '{customDt.Prop2}'," +
$"ComponentProp1: '{customDt.Component1.ComponentProp1}', ComponentProp2: {customDt.Component1.ComponentProp2}");
}

#endregion Snippet:DigitalTwinsSampleGetCustomDigitalTwin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class Component1
public string ComponentProp1 { get; set; }

[JsonPropertyName("ComponentProp2")]
public string ComponentProp2 { get; set; }
public int ComponentProp2 { get; set; }
}

internal class Metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class Options
[Option('s', "clientSecret", Required = false, HelpText = "Application client secret. Only applicable when using LoginMethod of AppId.")]
public string ClientSecret { get; set; }

[Option('e', "eventHubName", Required = true, HelpText = "Event Hub Name linked to digital twins instance")]
public string EventHubName { get; set; }
[Option('e', "eventHubEndpointName", Required = true, HelpText = "Event Hub endpoint linked to digital twins instance")]
public string EventHubEndpointName { get; set; }

internal LoginMethod GetLoginMethod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static async Task Main(string[] args)

// Run the samples

var dtLifecycleSamples = new DigitalTwinsLifecycleSamples(dtClient, options.EventHubName);
var dtLifecycleSamples = new DigitalTwinsLifecycleSamples(dtClient, options.EventHubEndpointName);
await dtLifecycleSamples.RunSamplesAsync();

var modelLifecycleSamples = new ModelLifecycleSamples();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)

// Then we create the models.
await client
.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload })
;
.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload });

Console.WriteLine($"Successfully created models with Ids: {componentModelId}, {modelId}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static class SamplesConstants
{
""@type"": ""Property"",
""name"": ""ComponentProp2"",
""schema"": ""string""
""schema"": ""integer""
},
{
""@type"": ""Telemetry"",
Expand Down Expand Up @@ -136,7 +136,7 @@ public static class SamplesConstants
""$model"": ""COMPONENT_ID""
},
""ComponentProp1"": ""Value"",
""ComponentProp2"": ""Value""
""ComponentProp2"": 123
}
}";
}
Expand Down
12 changes: 6 additions & 6 deletions sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ basicDigitalTwin.CustomProperties.Add("Prop2", "Value2");
var componentMetadata = new ModelProperties();
componentMetadata.Metadata.ModelId = componentModelId;
componentMetadata.CustomProperties.Add("ComponentProp1", "ComponentValue1");
componentMetadata.CustomProperties.Add("ComponentProp2", "ComponentValue2");
componentMetadata.CustomProperties.Add("ComponentProp2", 123);

basicDigitalTwin.CustomProperties.Add("Component1", componentMetadata);

Expand All @@ -150,7 +150,7 @@ var customDigitalTwin = new CustomDigitalTwin
{
Metadata = new Component1Metadata { ModelId = componentModelId },
ComponentProp1 = "Component prop1 val",
ComponentProp2 = "Component prop2 val",
ComponentProp2 = 123,
}
};
string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
Expand All @@ -175,9 +175,9 @@ if (getBasicDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
string component1RawText = ((JsonElement)basicDt.CustomProperties["Component1"]).GetRawText();
var component1 = JsonSerializer.Deserialize<IDictionary<string, object>>(component1RawText);

Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id} with ETag {basicDt.ETag} " +
$"and Prop1 '{basicDt.CustomProperties["Prop1"]}', Prop2 '{basicDt.CustomProperties["Prop2"]}', " +
$"ComponentProp1 '{component1["ComponentProp1"]}', ComponentProp2 '{component1["ComponentProp2"]}'");
Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id} with ETag {basicDt.ETag} " +
$"and Prop1: '{basicDt.CustomProperties["Prop1"]}', Prop2: '{basicDt.CustomProperties["Prop2"]}'," +
$"ComponentProp1: '{component1["ComponentProp1"]}', ComponentProp2: {component1["ComponentProp2"]}");
}
```

Expand All @@ -196,7 +196,7 @@ var customDigitalTwin = new CustomDigitalTwin
{
Metadata = new Component1Metadata { ModelId = componentModelId },
ComponentProp1 = "Component prop1 val",
ComponentProp2 = "Component prop2 val",
ComponentProp2 = 123,
}
};
string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ protected DigitalTwinsClient()
/// {
/// CustomDigitalTwin customDt = JsonSerializer.Deserialize&lt;CustomDigitalTwin&gt;(getCustomDtResponse.Value);
/// Console.WriteLine($&quot;Retrieved and deserialized digital twin {customDt.Id} with ETag {customDt.ETag} &quot; +
/// $&quot;and Prop1 &apos;{customDt.Prop1}&apos;, Prop2 &apos;{customDt.Prop2}&apos;, &quot; +
/// $&quot;ComponentProp1 &apos;{customDt.Component1.ComponentProp1}, ComponentProp2 &apos;{customDt.Component1.ComponentProp2}&apos;&quot;);
/// $&quot;and Prop1: &apos;{customDt.Prop1}&apos;, Prop2: &apos;{customDt.Prop2}&apos;,&quot; +
/// $&quot;ComponentProp1: &apos;{customDt.Component1.ComponentProp1}&apos;, ComponentProp2: {customDt.Component1.ComponentProp2}&quot;);
/// }
/// </code>
/// </example>
Expand Down Expand Up @@ -199,7 +199,7 @@ public virtual Response<string> GetDigitalTwin(string digitalTwinId, Cancellatio
/// {
/// Metadata = new Component1Metadata { ModelId = componentModelId },
/// ComponentProp1 = &quot;Component prop1 val&quot;,
/// ComponentProp2 = &quot;Component prop2 val&quot;,
/// ComponentProp2 = 123,
/// }
/// };
/// string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Azure.DigitalTwins.Core.Serialization
/// var componentMetadata = new ModelProperties();
/// componentMetadata.Metadata.ModelId = componentModelId;
/// componentMetadata.CustomProperties.Add(&quot;ComponentProp1&quot;, &quot;ComponentValue1&quot;);
/// componentMetadata.CustomProperties.Add(&quot;ComponentProp2&quot;, &quot;ComponentValue2&quot;);
/// componentMetadata.CustomProperties.Add(&quot;ComponentProp2&quot;, 123);
///
/// basicDigitalTwin.CustomProperties.Add(&quot;Component1&quot;, componentMetadata);
///
Expand All @@ -47,9 +47,9 @@ namespace Azure.DigitalTwins.Core.Serialization
/// string component1RawText = ((JsonElement)basicDt.CustomProperties[&quot;Component1&quot;]).GetRawText();
/// var component1 = JsonSerializer.Deserialize&lt;IDictionary&lt;string, object&gt;&gt;(component1RawText);
///
/// Console.WriteLine($&quot;Retrieved and deserialized digital twin {basicDt.Id} with ETag {basicDt.ETag} &quot; +
/// $&quot;and Prop1 &apos;{basicDt.CustomProperties[&quot;Prop1&quot;]}&apos;, Prop2 &apos;{basicDt.CustomProperties[&quot;Prop2&quot;]}&apos;, &quot; +
/// $&quot;ComponentProp1 &apos;{component1[&quot;ComponentProp1&quot;]}&apos;, ComponentProp2 &apos;{component1[&quot;ComponentProp2&quot;]}&apos;&quot;);
/// Console.WriteLine($&quot;Retrieved and deserialized digital twin {basicDt.Id} with ETag {basicDt.ETag} &quot; +
/// $&quot;and Prop1: &apos;{basicDt.CustomProperties[&quot;Prop1&quot;]}&apos;, Prop2: &apos;{basicDt.CustomProperties[&quot;Prop2&quot;]}&apos;,&quot; +
/// $&quot;ComponentProp1: &apos;{component1[&quot;ComponentProp1&quot;]}&apos;, ComponentProp2: {component1[&quot;ComponentProp2&quot;]}&quot;);
/// }
/// </code>
/// </example>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ To delete the digital twins instance, you need to first delete the endpoint adde

In order to maintain the functionality of the Setup.ps1 file, make sure this document stays updated with all the required changes if you run/alter this script.

Currently, this script works with version 0.0.1.dev8.
Currently, this script works with version 0.0.1.dev9.

0 comments on commit 3a45987

Please sign in to comment.