Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples(adt): Update component property to be an integer #12515

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -51,12 +50,12 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
};
basicDigitalTwin.Metadata.ModelId = modelId;
basicDigitalTwin.CustomProperties.Add("Prop1", "Value1");
basicDigitalTwin.CustomProperties.Add("Prop2", "Value2");
basicDigitalTwin.CustomProperties.Add("Prop2", 987);

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 @@ -101,12 +100,12 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
Id = customDtId,
Metadata = new CustomDigitalTwinMetadata { ModelId = modelId },
Prop1 = "Prop1 val",
Prop2 = "Prop2 val",
Prop2 = 987,
Component1 = new Component1
{
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 @@ -25,7 +25,7 @@ internal class CustomDigitalTwin
public string Prop1 { get; set; }

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

[JsonPropertyName("Component1")]
public Component1 Component1 { get; set; }
Expand All @@ -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 @@ -68,7 +68,7 @@ public static class SamplesConstants
{
""@type"": ""Property"",
""name"": ""Prop2"",
""schema"": ""string""
""schema"": ""integer""
},
{
""@type"": ""Component"",
Expand Down Expand Up @@ -106,7 +106,7 @@ public static class SamplesConstants
{
""@type"": ""Property"",
""name"": ""ComponentProp2"",
""schema"": ""string""
""schema"": ""integer""
},
{
""@type"": ""Telemetry"",
Expand All @@ -130,13 +130,13 @@ public static class SamplesConstants
""$model"": ""MODEL_ID""
},
""Prop1"": ""Value"",
""Prop2"": ""Value"",
""Prop2"": 987,
""Component1"":{
""$metadata"":{
""$model"": ""COMPONENT_ID""
},
""ComponentProp1"": ""Value"",
""ComponentProp2"": ""Value""
""ComponentProp2"": 123
}
}";
}
Expand Down
18 changes: 9 additions & 9 deletions sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ var basicDigitalTwin = new BasicDigitalTwin
};
basicDigitalTwin.Metadata.ModelId = modelId;
basicDigitalTwin.CustomProperties.Add("Prop1", "Value1");
basicDigitalTwin.CustomProperties.Add("Prop2", "Value2");
basicDigitalTwin.CustomProperties.Add("Prop2", 987);

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 @@ -145,12 +145,12 @@ var customDigitalTwin = new CustomDigitalTwin
Id = customDtId,
Metadata = new CustomDigitalTwinMetadata { ModelId = modelId },
Prop1 = "Prop1 val",
Prop2 = "Prop2 val",
Prop2 = 987,
Component1 = new Component1
{
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 @@ -191,12 +191,12 @@ var customDigitalTwin = new CustomDigitalTwin
Id = customDtId,
Metadata = new CustomDigitalTwinMetadata { ModelId = modelId },
Prop1 = "Prop1 val",
Prop2 = "Prop2 val",
Prop2 = 987,
Component1 = new Component1
{
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: {customDt.Prop2},&quot; +
/// $&quot;ComponentProp1: &apos;{customDt.Component1.ComponentProp1}&apos;, ComponentProp2: {customDt.Component1.ComponentProp2}&quot;);
/// }
/// </code>
/// </example>
Expand Down Expand Up @@ -194,12 +194,12 @@ public virtual Response<string> GetDigitalTwin(string digitalTwinId, Cancellatio
/// Id = customDtId,
/// Metadata = new CustomDigitalTwinMetadata { ModelId = modelId },
/// Prop1 = &quot;Prop1 val&quot;,
/// Prop2 = &quot;Prop2 val&quot;,
/// Prop2 = 987,
/// Component1 = new Component1
/// {
/// 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 @@ -20,12 +20,12 @@ namespace Azure.DigitalTwins.Core.Serialization
/// };
/// basicDigitalTwin.Metadata.ModelId = modelId;
/// basicDigitalTwin.CustomProperties.Add(&quot;Prop1&quot;, &quot;Value1&quot;);
/// basicDigitalTwin.CustomProperties.Add(&quot;Prop2&quot;, &quot;Value2&quot;);
/// basicDigitalTwin.CustomProperties.Add(&quot;Prop2&quot;, 987);
///
/// 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: {basicDt.CustomProperties[&quot;Prop2&quot;]},&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.