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

fix(tests,samples)do not send modelid in component metadata #12573

Merged
merged 3 commits into from
Jun 8, 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 @@ -122,13 +122,17 @@ public static partial class QueryChargeHelper
}
namespace Azure.DigitalTwins.Core.Serialization
{
public partial class BasicDigitalTwin : Azure.DigitalTwins.Core.Serialization.ModelProperties
public partial class BasicDigitalTwin
{
public BasicDigitalTwin() { }
[System.Text.Json.Serialization.JsonExtensionDataAttribute]
public System.Collections.Generic.IDictionary<string, object> CustomProperties { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("$etag")]
public string ETag { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("$dtId")]
public string Id { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("$metadata")]
public Azure.DigitalTwins.Core.Serialization.DigitalTwinMetadata Metadata { get { throw null; } set { } }
}
public partial class BasicRelationship
{
Expand All @@ -144,6 +148,12 @@ public BasicRelationship() { }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("$targetId")]
public string TargetId { get { throw null; } set { } }
}
public partial class ComponentMetadata
{
public ComponentMetadata() { }
[System.Text.Json.Serialization.JsonExtensionDataAttribute]
public System.Collections.Generic.IDictionary<string, object> WriteableProperties { get { throw null; } }
}
public partial class DigitalTwinMetadata
{
public DigitalTwinMetadata() { }
Expand All @@ -158,7 +168,7 @@ public ModelProperties() { }
[System.Text.Json.Serialization.JsonExtensionDataAttribute]
public System.Collections.Generic.IDictionary<string, object> CustomProperties { get { throw null; } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("$metadata")]
public Azure.DigitalTwins.Core.Serialization.DigitalTwinMetadata Metadata { get { throw null; } }
public Azure.DigitalTwins.Core.Serialization.ComponentMetadata Metadata { get { throw null; } }
}
public partial class UpdateOperationsUtility
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
"Component1",
new ModelProperties
{
// model Id of component
Metadata = { ModelId = componentModelId },
Metadata = { },
barustum marked this conversation as resolved.
Show resolved Hide resolved
// component properties
CustomProperties =
{
Expand Down Expand Up @@ -96,7 +95,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)

// Must cast Component1 as a JsonElement and get its raw text in order to deserialize it as a dictionary
string component1RawText = ((JsonElement)basicDt.CustomProperties["Component1"]).GetRawText();
var component1 = JsonSerializer.Deserialize<IDictionary<string, object>>(component1RawText);
IDictionary<string, object> component1 = JsonSerializer.Deserialize<IDictionary<string, object>>(component1RawText);

Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id}:\n\t" +
$"ETag: {basicDt.ETag}\n\t" +
Expand Down Expand Up @@ -124,7 +123,7 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)
Prop2 = 987,
Component1 = new Component1
{
Metadata = new Component1Metadata { ModelId = componentModelId },
Metadata = new Component1Metadata { },
barustum marked this conversation as resolved.
Show resolved Hide resolved
ComponentProp1 = "Component prop1 val",
ComponentProp2 = 123,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal class CustomDigitalTwinMetadata : Metadata
public WritableProperty Prop2 { get; set; }
}

internal class Component1Metadata : Metadata
internal class Component1Metadata
{
[JsonPropertyName("ComponentProp1")]
public WritableProperty ComponentProp1 { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"EmployeeId": "Employee1",
"wifiAccessPoint": {
"$metadata": {
"$model": "dtmi:samples:Wifi;1"
},
"RouterName": "Cisco1",
"Network": "Room1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ await client

// Create digital twin with Component payload.
string twinPayload = SamplesConstants.TemporaryTwinPayload
.Replace(SamplesConstants.ModelId, modelId)
.Replace(SamplesConstants.ComponentId, componentModelId);
.Replace(SamplesConstants.ModelId, modelId);

await client.CreateDigitalTwinAsync(twinId, twinPayload);
Console.WriteLine($"Created digital twin {twinId}.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static class SamplesConstants
""Prop2"": 987,
""Component1"":{
""$metadata"":{
""$model"": ""COMPONENT_ID""
},
""ComponentProp1"": ""Value"",
""ComponentProp2"": 123
Expand Down
9 changes: 4 additions & 5 deletions sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ var basicTwin = new BasicDigitalTwin
"Component1",
new ModelProperties
{
// model Id of component
Metadata = { ModelId = componentModelId },
Metadata = { },
// component properties
CustomProperties =
{
Expand Down Expand Up @@ -170,7 +169,7 @@ var customTwin = new CustomDigitalTwin
Prop2 = 987,
Component1 = new Component1
{
Metadata = new Component1Metadata { ModelId = componentModelId },
Metadata = new Component1Metadata { },
ComponentProp1 = "Component prop1 val",
ComponentProp2 = 123,
}
Expand All @@ -195,7 +194,7 @@ if (getBasicDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)

// Must cast Component1 as a JsonElement and get its raw text in order to deserialize it as a dictionary
string component1RawText = ((JsonElement)basicDt.CustomProperties["Component1"]).GetRawText();
var component1 = JsonSerializer.Deserialize<IDictionary<string, object>>(component1RawText);
IDictionary<string, object> component1 = JsonSerializer.Deserialize<IDictionary<string, object>>(component1RawText);

Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id}:\n\t" +
$"ETag: {basicDt.ETag}\n\t" +
Expand All @@ -218,7 +217,7 @@ var customTwin = new CustomDigitalTwin
Prop2 = 987,
Component1 = new Component1
{
Metadata = new Component1Metadata { ModelId = componentModelId },
Metadata = new Component1Metadata { },
ComponentProp1 = "Component prop1 val",
ComponentProp2 = 123,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public virtual Response<string> GetDigitalTwin(string digitalTwinId, Cancellatio
/// Prop2 = 987,
/// Component1 = new Component1
/// {
/// Metadata = new Component1Metadata { ModelId = componentModelId },
/// Metadata = new Component1Metadata { },
/// ComponentProp1 = &quot;Component prop1 val&quot;,
/// ComponentProp2 = 123,
/// }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Azure.DigitalTwins.Core.Serialization
Expand Down Expand Up @@ -32,8 +33,7 @@ namespace Azure.DigitalTwins.Core.Serialization
/// &quot;Component1&quot;,
/// new ModelProperties
/// {
/// // model Id of component
/// Metadata = { ModelId = componentModelId },
/// Metadata = { },
/// // component properties
/// CustomProperties =
/// {
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace Azure.DigitalTwins.Core.Serialization
///
/// // Must cast Component1 as a JsonElement and get its raw text in order to deserialize it as a dictionary
/// string component1RawText = ((JsonElement)basicDt.CustomProperties[&quot;Component1&quot;]).GetRawText();
/// var component1 = JsonSerializer.Deserialize&lt;IDictionary&lt;string, object&gt;&gt;(component1RawText);
/// IDictionary&lt;string, object&gt; component1 = JsonSerializer.Deserialize&lt;IDictionary&lt;string, object&gt;&gt;(component1RawText);
///
/// Console.WriteLine($&quot;Retrieved and deserialized digital twin {basicDt.Id}:\n\t&quot; +
/// $&quot;ETag: {basicDt.ETag}\n\t&quot; +
Expand All @@ -72,7 +72,7 @@ namespace Azure.DigitalTwins.Core.Serialization
/// }
/// </code>
/// </example>
public class BasicDigitalTwin : ModelProperties
public class BasicDigitalTwin
{
/// <summary>
/// The unique Id of the digital twin in a digital twins instance. This field is present on every digital twin.
Expand All @@ -85,5 +85,17 @@ public class BasicDigitalTwin : ModelProperties
/// </summary>
[JsonPropertyName("$etag")]
public string ETag { get; set; }

/// <summary>
/// Information about the model a digital twin conforms to. This field is present on every digital twin.
/// </summary>
[JsonPropertyName("$metadata")]
public DigitalTwinMetadata Metadata { get; set; } = new DigitalTwinMetadata();

/// <summary>
/// Additional properties of the digital twin. This field will contain any properties of the digital twin that are not already defined by the other strong types of this class.
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> CustomProperties { get; set; } = new Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Azure.DigitalTwins.Core.Serialization
{
/// <summary>
/// An optional, helper class for deserializing a digital twin.
/// The $metadata class on a <see cref="BasicDigitalTwin"/> and <see cref="ModelProperties"/>.
/// </summary>
/// <remarks>
/// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azure.DigitalTwins.Core/samples">our repo samples</see>.
/// </remarks>
public class ComponentMetadata
{
/// <summary>
/// Model-defined writable properties' request state.
/// </summary>
/// <remarks>For your convenience, the value of each dictionary object can be turned into an instance of <see cref="WritableProperty"/>.</remarks>
[JsonExtensionData]
public IDictionary<string, object> WriteableProperties { get; } = new Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
namespace Azure.DigitalTwins.Core.Serialization
{
/// <summary>
/// Properties on a digital twin that adhere to a specific model.
/// Properties on a component that adhere to a specific model.
/// </summary>
/// <remarks>
/// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azure.DigitalTwins.Core/samples">our repo samples</see>.
/// </remarks>
public class ModelProperties
{
/// <summary>
/// Information about the model a digital twin conforms to. This field is present on every digital twin.
/// Information about the model a component conforms to. This field is present on every digital twin.
/// </summary>
[JsonPropertyName("$metadata")]
public DigitalTwinMetadata Metadata { get; } = new DigitalTwinMetadata();
public ComponentMetadata Metadata { get; } = new ComponentMetadata();

/// <summary>
/// Additional properties of the digital twin. This field will contain any properties of the digital twin that are not already defined by the other strong types of this class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Azure.DigitalTwins.Core.Serialization
{
/// <summary>
/// An optional, helper class for deserializing a digital twin.
/// The ModelProperties dictionary on <see cref="DigitalTwinMetadata"/>.
/// The ModelProperties dictionary on <see cref="ComponentMetadata"/>.
/// </summary>
/// <remarks>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task Component_Lifecycle()
await client.CreateModelsAsync(new List<string> { roomWithWifiModel, wifiModel }).ConfigureAwait(false);

// create room digital twin
string roomWithWifiTwin = TestAssetsHelper.GetRoomWithWifiTwinPayload(roomWithWifiModelId, wifiModelId, wifiComponentName);
string roomWithWifiTwin = TestAssetsHelper.GetRoomWithWifiTwinPayload(roomWithWifiModelId, wifiComponentName);

await client.CreateDigitalTwinAsync(roomWithWifiTwinId, roomWithWifiTwin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task Relationships_Lifecycle()
string floorTwinCoolsRelationshipPayload = TestAssetsHelper.GetRelationshipPayload(floorTwinId, CoolsRelationship);
string floorTwinContainedInRelationshipPayload = TestAssetsHelper.GetRelationshipPayload(floorTwinId, ContainedInRelationship);
string floorCooledByHvacPayload = TestAssetsHelper.GetRelationshipPayload(hvacTwinId, CooledByRelationship);
string floorContainsRoomUpdatePayload = TestAssetsHelper.GetRelationshipUpdatePayload("isAccessRestricted", false);
string floorContainsRoomUpdatePayload = TestAssetsHelper.GetRelationshipUpdatePayload("/isAccessRestricted", false);

// CREATE relationships

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private async Task CreateModelsAndTwins(DigitalTwinsClient client, string wifiMo
await client.CreateModelsAsync(new List<string> { roomWithWifiModel, wifiModel }).ConfigureAwait(false);

// Generate the payload needed to create the room with wifi twin.
string roomWithWifiTwin = TestAssetsHelper.GetRoomWithWifiTwinPayload(roomWithWifiModelId, wifiModelId, wifiComponentName);
string roomWithWifiTwin = TestAssetsHelper.GetRoomWithWifiTwinPayload(roomWithWifiModelId, wifiComponentName);

// Create the room with wifi component digital twin.
await client.CreateDigitalTwinAsync(roomWithWifiTwinId, roomWithWifiTwin).ConfigureAwait(false);
Expand Down
Loading