From 3a4598770b0c0feb6c49eab674c147a5c4188bf4 Mon Sep 17 00:00:00 2001 From: Abhipsa Misra Date: Thu, 4 Jun 2020 13:14:36 -0700 Subject: [PATCH] samples(adt): Update component property to be an integer --- .../ComponentSamples.cs | 17 ++++++++--------- .../CustomDigitalTwin.cs | 2 +- .../samples/DigitalTwinsClientSample/Options.cs | 4 ++-- .../samples/DigitalTwinsClientSample/Program.cs | 2 +- .../PublishTelemetrySamples.cs | 3 +-- .../SamplesConstants.cs | 4 ++-- .../Azure.DigitalTwins.Core/samples/Readme.md | 12 ++++++------ .../src/DigitalTwinsClient.cs | 6 +++--- .../src/Serialization/BasicDigitalTwin.cs | 8 ++++---- .../tests/prerequisites/prerequisite readme.md | 2 +- 10 files changed, 29 insertions(+), 31 deletions(-) diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs index 518c6b919bc49..745a0a474d3ac 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs @@ -37,8 +37,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client) // Then we create models Response> 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 @@ -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); @@ -82,9 +81,9 @@ public async Task RunSamplesAsync(DigitalTwinsClient client) string component1RawText = ((JsonElement)basicDt.CustomProperties["Component1"]).GetRawText(); var component1 = JsonSerializer.Deserialize>(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 @@ -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); @@ -126,8 +125,8 @@ public async Task RunSamplesAsync(DigitalTwinsClient client) { CustomDigitalTwin customDt = JsonSerializer.Deserialize(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 diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/CustomDigitalTwin.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/CustomDigitalTwin.cs index ff7386b9ee35b..c964100b94866 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/CustomDigitalTwin.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/CustomDigitalTwin.cs @@ -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 diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Options.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Options.cs index 5f3dafe64c069..97a960352ece5 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Options.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Options.cs @@ -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() { diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs index 708999fecebb6..92b4e67f66bde 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs @@ -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(); diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs index 57ad195a833a6..6e0beccf30996 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs @@ -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}"); diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/SamplesConstants.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/SamplesConstants.cs index 9f8b42ff6e925..b17336a016b19 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/SamplesConstants.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/SamplesConstants.cs @@ -106,7 +106,7 @@ public static class SamplesConstants { ""@type"": ""Property"", ""name"": ""ComponentProp2"", - ""schema"": ""string"" + ""schema"": ""integer"" }, { ""@type"": ""Telemetry"", @@ -136,7 +136,7 @@ public static class SamplesConstants ""$model"": ""COMPONENT_ID"" }, ""ComponentProp1"": ""Value"", - ""ComponentProp2"": ""Value"" + ""ComponentProp2"": 123 } }"; } diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md index 270cac9f52f2d..464814c800f6f 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md @@ -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); @@ -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); @@ -175,9 +175,9 @@ if (getBasicDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK) string component1RawText = ((JsonElement)basicDt.CustomProperties["Component1"]).GetRawText(); var component1 = JsonSerializer.Deserialize>(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"]}"); } ``` @@ -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); diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs index e6c685f4708e8..ab62a020e52ed 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs @@ -141,8 +141,8 @@ protected DigitalTwinsClient() /// { /// 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}"); /// } /// /// @@ -199,7 +199,7 @@ public virtual Response GetDigitalTwin(string digitalTwinId, Cancellatio /// { /// Metadata = new Component1Metadata { ModelId = componentModelId }, /// ComponentProp1 = "Component prop1 val", - /// ComponentProp2 = "Component prop2 val", + /// ComponentProp2 = 123, /// } /// }; /// string dt2Payload = JsonSerializer.Serialize(customDigitalTwin); diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs index 82bf7324ee279..38cad0b433a50 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs @@ -25,7 +25,7 @@ namespace Azure.DigitalTwins.Core.Serialization /// 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); /// @@ -47,9 +47,9 @@ namespace Azure.DigitalTwins.Core.Serialization /// 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"]}"); /// } /// /// diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/prerequisites/prerequisite readme.md b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/prerequisites/prerequisite readme.md index 71ec90302bb6a..38fd0bc8eaa23 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/prerequisites/prerequisite readme.md +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/prerequisites/prerequisite readme.md @@ -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.