diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs
index 345841b10913f..518c6b919bc49 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs
@@ -14,26 +14,19 @@ namespace Azure.DigitalTwins.Core.Samples
{
internal class ComponentSamples
{
- private DigitalTwinsClient DigitalTwinsClient { get; }
-
- public ComponentSamples(DigitalTwinsClient dtClient)
- {
- DigitalTwinsClient = dtClient;
- }
-
///
/// Creates a digital twin with Component and upates Component
///
- public async Task RunSamplesAsync()
+ public async Task RunSamplesAsync(DigitalTwinsClient client)
{
PrintHeader("COMPONENT SAMPLE");
// For the purpose of this example we will create temporary models using a random model Ids.
// We have to make sure these model Ids are unique within the DT instance.
- string componentModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryComponentModelPrefix, DigitalTwinsClient).ConfigureAwait(false);
- string modelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryModelPrefix, DigitalTwinsClient).ConfigureAwait(false);
- string basicDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, DigitalTwinsClient).ConfigureAwait(false);
+ string componentModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryComponentModelPrefix, client);
+ string modelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryModelPrefix, client);
+ string basicDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, client);
string newComponentModelPayload = SamplesConstants.TemporaryComponentModelPayload
.Replace(SamplesConstants.ComponentId, componentModelId);
@@ -43,9 +36,9 @@ public async Task RunSamplesAsync()
.Replace(SamplesConstants.ComponentId, componentModelId);
// Then we create models
- Response> createModelsResponse = await DigitalTwinsClient
+ Response> createModelsResponse = await client
.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload })
- .ConfigureAwait(false);
+ ;
Console.WriteLine($"Successfully created models Ids {componentModelId} and {modelId} with response {createModelsResponse.GetRawResponse().Status}.");
#region Snippet:DigitalTwinsSampleCreateBasicTwin
@@ -69,7 +62,7 @@ public async Task RunSamplesAsync()
string basicDtPayload = JsonSerializer.Serialize(basicDigitalTwin);
- Response createBasicDtResponse = await DigitalTwinsClient.CreateDigitalTwinAsync(basicDtId, basicDtPayload).ConfigureAwait(false);
+ Response createBasicDtResponse = await client.CreateDigitalTwinAsync(basicDtId, basicDtPayload);
Console.WriteLine($"Created digital twin {basicDtId} with response {createBasicDtResponse.GetRawResponse().Status}.");
#endregion Snippet:DigitalTwinsSampleCreateBasicTwin
@@ -80,7 +73,7 @@ public async Task RunSamplesAsync()
#region Snippet:DigitalTwinsSampleGetBasicDigitalTwin
- Response getBasicDtResponse = await DigitalTwinsClient.GetDigitalTwinAsync(basicDtId).ConfigureAwait(false);
+ Response getBasicDtResponse = await client.GetDigitalTwinAsync(basicDtId);
if (getBasicDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
{
BasicDigitalTwin basicDt = JsonSerializer.Deserialize(getBasicDtResponse.Value);
@@ -102,7 +95,7 @@ public async Task RunSamplesAsync()
#region Snippet:DigitalTwinsSampleCreateCustomTwin
- string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, DigitalTwinsClient).ConfigureAwait(false);
+ string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, client);
var customDigitalTwin = new CustomDigitalTwin
{
Id = customDtId,
@@ -118,7 +111,7 @@ public async Task RunSamplesAsync()
};
string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
- Response createCustomDtResponse = await DigitalTwinsClient.CreateDigitalTwinAsync(customDtId, dt2Payload).ConfigureAwait(false);
+ Response createCustomDtResponse = await client.CreateDigitalTwinAsync(customDtId, dt2Payload);
Console.WriteLine($"Created digital twin {customDtId} with response {createCustomDtResponse.GetRawResponse().Status}.");
#endregion Snippet:DigitalTwinsSampleCreateCustomTwin
@@ -128,7 +121,7 @@ public async Task RunSamplesAsync()
#region Snippet:DigitalTwinsSampleGetCustomDigitalTwin
- Response getCustomDtResponse = await DigitalTwinsClient.GetDigitalTwinAsync(customDtId).ConfigureAwait(false);
+ Response getCustomDtResponse = await client.GetDigitalTwinAsync(customDtId);
if (getCustomDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
{
CustomDigitalTwin customDt = JsonSerializer.Deserialize(getCustomDtResponse.Value);
@@ -146,7 +139,7 @@ public async Task RunSamplesAsync()
componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value");
string updatePayload = componentUpdateUtility.Serialize();
- Response response = await DigitalTwinsClient.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
+ Response response = await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
Console.WriteLine($"Updated component for digital twin {basicDtId}. Update response status: {response.GetRawResponse().Status}");
@@ -156,7 +149,7 @@ public async Task RunSamplesAsync()
#region Snippet:DigitalTwinsSampleGetComponent
- response = await DigitalTwinsClient.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath).ConfigureAwait(false);
+ response = await client.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath);
Console.WriteLine($"Get component for digital twin: \n{response.Value}. Get response status: {response.GetRawResponse().Status}");
@@ -166,8 +159,8 @@ public async Task RunSamplesAsync()
try
{
- await DigitalTwinsClient.DeleteDigitalTwinAsync(basicDtId).ConfigureAwait(false);
- await DigitalTwinsClient.DeleteDigitalTwinAsync(customDtId).ConfigureAwait(false);
+ await client.DeleteDigitalTwinAsync(basicDtId);
+ await client.DeleteDigitalTwinAsync(customDtId);
}
catch (RequestFailedException ex)
{
@@ -176,8 +169,8 @@ public async Task RunSamplesAsync()
try
{
- await DigitalTwinsClient.DeleteModelAsync(modelId).ConfigureAwait(false);
- await DigitalTwinsClient.DeleteModelAsync(componentModelId).ConfigureAwait(false);
+ await client.DeleteModelAsync(modelId);
+ await client.DeleteModelAsync(componentModelId);
}
catch (RequestFailedException ex)
{
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/DigitalTwinsLifecycleSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/DigitalTwinsLifecycleSamples.cs
index 6f42947f0149f..c1febb41259ab 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/DigitalTwinsLifecycleSamples.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/DigitalTwinsLifecycleSamples.cs
@@ -14,7 +14,6 @@
using Azure.DigitalTwins.Core.Queries;
using Azure.DigitalTwins.Core.Serialization;
using static Azure.DigitalTwins.Core.Samples.SampleLogger;
-using static Azure.DigitalTwins.Core.Samples.UniqueIdHelper;
namespace Azure.DigitalTwins.Core.Samples
{
@@ -50,15 +49,15 @@ internal class DigitalTwinsLifecycleSamples
private static readonly string s_twinsPath = Path.Combine(s_dtdlDirectoryPath, "DigitalTwins");
private static readonly string s_relationshipsPath = Path.Combine(s_dtdlDirectoryPath, "Relationships");
- private readonly string _eventhubEndpointName;
private readonly string _eventRouteId = $"sampleEventRouteId-{Guid.NewGuid()}";
- private DigitalTwinsClient DigitalTwinsClient { get; }
+ private readonly string eventhubEndpointName;
+ private readonly DigitalTwinsClient client;
public DigitalTwinsLifecycleSamples(DigitalTwinsClient dtClient, string eventhubEndpointName)
{
- _eventhubEndpointName = eventhubEndpointName;
- DigitalTwinsClient = dtClient;
+ this.eventhubEndpointName = eventhubEndpointName;
+ client = dtClient;
}
///
@@ -69,34 +68,34 @@ public DigitalTwinsLifecycleSamples(DigitalTwinsClient dtClient, string eventhub
public async Task RunSamplesAsync()
{
// Ensure existing twins with the same name are deleted first
- await DeleteTwinsAsync().ConfigureAwait(false);
+ await DeleteTwinsAsync();
// Delete existing models
- await DeleteAllModelsAsync().ConfigureAwait(false);
+ await DeleteAllModelsAsync();
// Create all the models
- await AddAllModelsAsync().ConfigureAwait(false);
+ await AddAllModelsAsync();
// Get all models
- await GetAllModelsAsync().ConfigureAwait(false);
+ await GetAllModelsAsync();
// Create twin counterparts for all the models
- await CreateAllTwinsAsync().ConfigureAwait(false);
+ await CreateAllTwinsAsync();
// Get all twins
- await QueryTwinsAsync().ConfigureAwait(false);
+ await QueryTwinsAsync();
// Create all the relationships
- await ConnectTwinsTogetherAsync().ConfigureAwait(false);
+ await ConnectTwinsTogetherAsync();
// Creating event route
- await CreateEventRoute().ConfigureAwait(false);
+ await CreateEventRoute();
// Get all event routes
- await GetEventRoutes().ConfigureAwait(false);
+ await GetEventRoutes();
// Deleting event route
- await DeleteEventRoute().ConfigureAwait(false);
+ await DeleteEventRoute();
}
///
@@ -119,7 +118,7 @@ private async Task DeleteAllModelsAsync()
foreach (string modelId in models)
{
- await DigitalTwinsClient.DeleteModelAsync(modelId).ConfigureAwait(false);
+ await client.DeleteModelAsync(modelId);
Console.WriteLine($"Deleted model {modelId}");
}
}
@@ -149,7 +148,7 @@ private async Task AddAllModelsAsync()
try
{
- Response> response = await DigitalTwinsClient.CreateModelsAsync(modelsToCreate).ConfigureAwait(false);
+ Response> response = await client.CreateModelsAsync(modelsToCreate);
Console.WriteLine($"Created models status: {response.GetRawResponse().Status}");
}
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.Conflict)
@@ -174,7 +173,7 @@ public async Task GetAllModelsAsync()
#region Snippet:DigitalTwinsSampleGetModels
- AsyncPageable allModels = DigitalTwinsClient.GetModelsAsync();
+ AsyncPageable allModels = client.GetModelsAsync();
await foreach (ModelData model in allModels)
{
Console.WriteLine($"Model Id: {model.Id}, display name: {model.DisplayName["en"]}, upload time: {model.UploadTime}, is decommissioned: {model.Decommissioned}");
@@ -182,7 +181,7 @@ public async Task GetAllModelsAsync()
#endregion Snippet:DigitalTwinsSampleGetModels
}
- catch (Exception ex)
+ catch (RequestFailedException ex)
{
FatalError($"Failed to get all the models due to:\n{ex}");
}
@@ -204,14 +203,14 @@ public async Task DeleteTwinsAsync()
#region Snippet:DigitalTwinsSampleGetRelationships
- AsyncPageable relationships = DigitalTwinsClient.GetRelationshipsAsync(twin.Key);
+ AsyncPageable relationships = client.GetRelationshipsAsync(twin.Key);
#endregion Snippet:DigitalTwinsSampleGetRelationships
await foreach (var relationshipJson in relationships)
{
BasicRelationship relationship = JsonSerializer.Deserialize(relationshipJson);
- await DigitalTwinsClient.DeleteRelationshipAsync(twin.Key, relationship.Id).ConfigureAwait(false);
+ await client.DeleteRelationshipAsync(twin.Key, relationship.Id);
Console.WriteLine($"Found and deleted relationship {relationship.Id}");
}
@@ -219,13 +218,13 @@ public async Task DeleteTwinsAsync()
#region Snippet:DigitalTwinsSampleGetIncomingRelationships
- AsyncPageable incomingRelationships = DigitalTwinsClient.GetIncomingRelationshipsAsync(twin.Key);
+ AsyncPageable incomingRelationships = client.GetIncomingRelationshipsAsync(twin.Key);
#endregion Snippet:DigitalTwinsSampleGetIncomingRelationships
await foreach (IncomingRelationship incomingRelationship in incomingRelationships)
{
- await DigitalTwinsClient.DeleteRelationshipAsync(incomingRelationship.SourceId, incomingRelationship.RelationshipId).ConfigureAwait(false);
+ await client.DeleteRelationshipAsync(incomingRelationship.SourceId, incomingRelationship.RelationshipId);
Console.WriteLine($"Found and deleted incoming relationship {incomingRelationship.RelationshipId}");
}
@@ -233,7 +232,7 @@ public async Task DeleteTwinsAsync()
#region Snippet:DigitalTwinsSampleDeleteTwin
- await DigitalTwinsClient.DeleteDigitalTwinAsync(twin.Key).ConfigureAwait(false);
+ await client.DeleteDigitalTwinAsync(twin.Key);
#endregion Snippet:DigitalTwinsSampleDeleteTwin
@@ -263,7 +262,7 @@ public async Task CreateAllTwinsAsync()
{
try
{
- Response response = await DigitalTwinsClient.CreateDigitalTwinAsync(twin.Key, twin.Value).ConfigureAwait(false);
+ Response response = await client.CreateDigitalTwinAsync(twin.Key, twin.Value);
Console.WriteLine($"Created digital twin {twin.Key}. Create response status: {response.GetRawResponse().Status}");
Console.WriteLine($"Body: {response?.Value}");
@@ -287,7 +286,7 @@ public async Task QueryTwinsAsync()
// This code snippet demonstrates the simplest way to iterate over the digital twin results, where paging
// happens under the covers.
- AsyncPageable asyncPageableResponse = DigitalTwinsClient.QueryAsync("SELECT * FROM digitaltwins");
+ AsyncPageable asyncPageableResponse = client.QueryAsync("SELECT * FROM digitaltwins");
// Iterate over the twin instances in the pageable response.
// The "await" keyword here is required because new pages will be fetched when necessary,
@@ -308,7 +307,7 @@ public async Task QueryTwinsAsync()
// the query API. It iterates over the response pages first to access to the query-charge header,
// and then the digital twin results within each page.
- AsyncPageable asyncPageableResponseWithCharge = DigitalTwinsClient.QueryAsync("SELECT * FROM digitaltwins");
+ AsyncPageable asyncPageableResponseWithCharge = client.QueryAsync("SELECT * FROM digitaltwins");
int pageNum = 0;
// The "await" keyword here is required as a call is made when fetching a new page.
@@ -363,12 +362,10 @@ public async Task ConnectTwinsTogetherAsync()
string serializedRelationship = JsonSerializer.Serialize(relationship);
- await DigitalTwinsClient
- .CreateRelationshipAsync(
- relationship.SourceId,
- relationship.Id,
- serializedRelationship)
- .ConfigureAwait(false);
+ await client.CreateRelationshipAsync(
+ relationship.SourceId,
+ relationship.Id,
+ serializedRelationship);
#endregion Snippet:DigitalTwinsSampleCreateRelationship
@@ -392,7 +389,7 @@ public async Task GetEventRoutes()
{
#region Snippet:DigitalTwinsSampleGetEventRoutes
- AsyncPageable response = DigitalTwinsClient.GetEventRoutesAsync();
+ AsyncPageable response = client.GetEventRoutesAsync();
await foreach (EventRoute er in response)
{
Console.WriteLine($"Event route: {er.Id}, endpoint name: {er.EndpointName}");
@@ -417,12 +414,12 @@ public async Task CreateEventRoute()
#region Snippet:DigitalTwinsSampleCreateEventRoute
string eventFilter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'";
- var eventRoute = new EventRoute(_eventhubEndpointName)
+ var eventRoute = new EventRoute(eventhubEndpointName)
{
Filter = eventFilter
};
- Response createEventRouteResponse = await DigitalTwinsClient.CreateEventRouteAsync(_eventRouteId, eventRoute).ConfigureAwait(false);
+ Response createEventRouteResponse = await client.CreateEventRouteAsync(_eventRouteId, eventRoute);
#endregion Snippet:DigitalTwinsSampleCreateEventRoute
@@ -444,7 +441,7 @@ public async Task DeleteEventRoute()
{
#region Snippet:DigitalTwinsSampleDeleteEventRoute
- Response response = await DigitalTwinsClient.DeleteEventRouteAsync(_eventRouteId).ConfigureAwait(false);
+ Response response = await client.DeleteEventRouteAsync(_eventRouteId);
#endregion Snippet:DigitalTwinsSampleDeleteEventRoute
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ModelLifecycleSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ModelLifecycleSamples.cs
index 20edf7e6d6c49..295fa6e20e559 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ModelLifecycleSamples.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ModelLifecycleSamples.cs
@@ -15,26 +15,19 @@ namespace Azure.DigitalTwins.Samples
{
internal class ModelLifecycleSamples
{
- private DigitalTwinsClient DigitalTwinsClient { get; }
-
- public ModelLifecycleSamples(DigitalTwinsClient dtClient)
- {
- DigitalTwinsClient = dtClient;
- }
-
///
/// Creates a new model with a random Id
/// Decommission the newly created model and check for success
///
- public async Task RunSamplesAsync()
+ public async Task RunSamplesAsync(DigitalTwinsClient client)
{
PrintHeader("MODEL LIFECYCLE SAMPLE");
// For the purpose of this example we will create temporary models using random model Ids and then decommission a model.
// We have to make sure these model Ids are unique within the DT instance.
- string newComponentModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryComponentModelPrefix, DigitalTwinsClient).ConfigureAwait(false);
- string sampleModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryModelPrefix, DigitalTwinsClient).ConfigureAwait(false);
+ string newComponentModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryComponentModelPrefix, client);
+ string sampleModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryModelPrefix, client);
string newComponentModelPayload = SamplesConstants.TemporaryComponentModelPayload
.Replace(SamplesConstants.ComponentId, newComponentModelId);
@@ -49,7 +42,7 @@ public async Task RunSamplesAsync()
{
#region Snippet:DigitalTwinsSampleCreateModels
- Response> response = await DigitalTwinsClient.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload }).ConfigureAwait(false);
+ Response> response = await client.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload });
Console.WriteLine($"Successfully created a model with Id: {newComponentModelId}, {sampleModelId}, status: {response.GetRawResponse().Status}");
#endregion Snippet:DigitalTwinsSampleCreateModels
@@ -68,7 +61,7 @@ public async Task RunSamplesAsync()
{
#region Snippet:DigitalTwinsSampleGetModel
- Response sampleModel = await DigitalTwinsClient.GetModelAsync(sampleModelId).ConfigureAwait(false);
+ Response sampleModel = await client.GetModelAsync(sampleModelId);
#endregion Snippet:DigitalTwinsSampleGetModel
@@ -85,7 +78,7 @@ public async Task RunSamplesAsync()
try
{
- await DigitalTwinsClient.DecommissionModelAsync(sampleModelId).ConfigureAwait(false);
+ await client.DecommissionModelAsync(sampleModelId);
Console.WriteLine($"Successfully decommissioned model {sampleModelId}");
}
@@ -102,7 +95,7 @@ public async Task RunSamplesAsync()
try
{
- await DigitalTwinsClient.DeleteModelAsync(sampleModelId).ConfigureAwait(false);
+ await client.DeleteModelAsync(sampleModelId);
Console.WriteLine($"Deleted model {sampleModelId}");
}
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs
index 2ea9652885a75..708999fecebb6 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/Program.cs
@@ -19,6 +19,8 @@ public class Program
///
public static async Task Main(string[] args)
{
+ // Parse and validate paramters
+
Options options = null;
ParserResult result = Parser.Default.ParseArguments(args)
.WithParsed(parsedOptions =>
@@ -38,6 +40,8 @@ public static async Task Main(string[] args)
Environment.Exit(1);
}
+ // Instantiate the client
+
var httpClient = new HttpClient();
DigitalTwinsClient dtClient = (options.GetLoginMethod()) switch
{
@@ -56,17 +60,21 @@ public static async Task Main(string[] args)
_ => throw new Exception("Unsupported login method"),
};
+ // Run the samples
+
var dtLifecycleSamples = new DigitalTwinsLifecycleSamples(dtClient, options.EventHubName);
- await dtLifecycleSamples.RunSamplesAsync().ConfigureAwait(false);
+ await dtLifecycleSamples.RunSamplesAsync();
+
+ var modelLifecycleSamples = new ModelLifecycleSamples();
+ await modelLifecycleSamples.RunSamplesAsync(dtClient);
- var modelLifecycleSamples = new ModelLifecycleSamples(dtClient);
- await modelLifecycleSamples.RunSamplesAsync().ConfigureAwait(false);
+ var componentSamples = new ComponentSamples();
+ await componentSamples.RunSamplesAsync(dtClient);
- var componentSamples = new ComponentSamples(dtClient);
- await componentSamples.RunSamplesAsync().ConfigureAwait(false);
+ var publishTelemetrySamples = new PublishTelemetrySamples();
+ await publishTelemetrySamples.RunSamplesAsync(dtClient);
- var publishTelemetrySamples = new PublishTelemetrySamples(dtClient);
- await publishTelemetrySamples.RunSamplesAsync().ConfigureAwait(false);
+ // Clean up
httpClient.Dispose();
}
@@ -91,13 +99,13 @@ private static DigitalTwinsClient GetDigitalTwinsClient(string tenantId, string
clientSecret,
new TokenCredentialOptions { AuthorityHost = KnownAuthorityHosts.AzureCloud });
- var dtClient = new DigitalTwinsClient(
+ var client = new DigitalTwinsClient(
new Uri(adtEndpoint),
tokenCredential);
#endregion Snippet:DigitalTwinsSampleCreateServiceClientWithClientSecret
- return dtClient;
+ return client;
}
///
@@ -126,14 +134,14 @@ private static DigitalTwinsClient GetDigitalTwinsClient(string tenantId, string
clientId,
new TokenCredentialOptions { AuthorityHost = KnownAuthorityHosts.AzureCloud });
- var dtClient = new DigitalTwinsClient(
+ var client = new DigitalTwinsClient(
new Uri(adtEndpoint),
tokenCredential,
clientOptions);
#endregion Snippet:DigitalTwinsSampleCreateServiceClientInteractiveLogin
- return dtClient;
+ return client;
}
}
}
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs
index 3e694e7b9b1d0..57ad195a833a6 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/PublishTelemetrySamples.cs
@@ -15,27 +15,20 @@ namespace Azure.DigitalTwins.Samples
{
internal class PublishTelemetrySamples
{
- private DigitalTwinsClient DigitalTwinsClient { get; }
-
- public PublishTelemetrySamples(DigitalTwinsClient dtClient)
- {
- DigitalTwinsClient = dtClient;
- }
-
///
/// Create a temporary component model, twin model and digital twin instance.
/// Publish a telemetry message and a component telemetry message to the digital twin instance.
///
- public async Task RunSamplesAsync()
+ public async Task RunSamplesAsync(DigitalTwinsClient client)
{
PrintHeader("PUBLISH TELEMETRY MESSAGE SAMPLE");
// For the purpose of this example we will create temporary models using a random model Ids.
// We will also create temporary twin instances to publish the telemetry to.
- string componentModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryComponentModelPrefix, DigitalTwinsClient).ConfigureAwait(false);
- string modelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryModelPrefix, DigitalTwinsClient).ConfigureAwait(false);
- string twinId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, DigitalTwinsClient).ConfigureAwait(false);
+ string componentModelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryComponentModelPrefix, client);
+ string modelId = await GetUniqueModelIdAsync(SamplesConstants.TemporaryModelPrefix, client);
+ string twinId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, client);
string newComponentModelPayload = SamplesConstants.TemporaryComponentModelPayload
.Replace(SamplesConstants.ComponentId, componentModelId);
@@ -45,9 +38,9 @@ public async Task RunSamplesAsync()
.Replace(SamplesConstants.ComponentId, componentModelId);
// Then we create the models.
- await DigitalTwinsClient
+ await client
.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload })
- .ConfigureAwait(false);
+ ;
Console.WriteLine($"Successfully created models with Ids: {componentModelId}, {modelId}");
@@ -56,7 +49,7 @@ await DigitalTwinsClient
.Replace(SamplesConstants.ModelId, modelId)
.Replace(SamplesConstants.ComponentId, componentModelId);
- await DigitalTwinsClient.CreateDigitalTwinAsync(twinId, twinPayload).ConfigureAwait(false);
+ await client.CreateDigitalTwinAsync(twinId, twinPayload);
Console.WriteLine($"Created digital twin {twinId}.");
try
@@ -64,7 +57,7 @@ await DigitalTwinsClient
#region Snippet:DigitalTwinsSamplePublishTelemetry
// construct your json telemetry payload by hand.
- Response publishTelemetryResponse = await DigitalTwinsClient.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}");
+ Response publishTelemetryResponse = await client.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}");
Console.WriteLine($"Successfully published telemetry message, status: {publishTelemetryResponse.Status}");
#endregion Snippet:DigitalTwinsSamplePublishTelemetry
@@ -76,7 +69,10 @@ await DigitalTwinsClient
{
{ "ComponentTelemetry1", 9}
};
- Response publishTelemetryToComponentResponse = await DigitalTwinsClient.PublishComponentTelemetryAsync(twinId, "Component1", JsonSerializer.Serialize(telemetryPayload));
+ Response publishTelemetryToComponentResponse = await client.PublishComponentTelemetryAsync(
+ twinId,
+ "Component1",
+ JsonSerializer.Serialize(telemetryPayload));
Console.WriteLine($"Successfully published component telemetry message, status: {publishTelemetryToComponentResponse.Status}");
#endregion Snippet:DigitalTwinsSamplePublishComponentTelemetry
@@ -89,11 +85,11 @@ await DigitalTwinsClient
try
{
// Delete the twin.
- await DigitalTwinsClient.DeleteDigitalTwinAsync(twinId).ConfigureAwait(false);
+ await client.DeleteDigitalTwinAsync(twinId);
// Delete the models.
- await DigitalTwinsClient.DeleteModelAsync(modelId).ConfigureAwait(false);
- await DigitalTwinsClient.DeleteModelAsync(componentModelId).ConfigureAwait(false);
+ await client.DeleteModelAsync(modelId);
+ await client.DeleteModelAsync(componentModelId);
}
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.NotFound)
{
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/UniqueIdHelper.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/UniqueIdHelper.cs
index 701a819b37d7f..7a117ffb0a81d 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/UniqueIdHelper.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/UniqueIdHelper.cs
@@ -14,12 +14,12 @@ internal static class UniqueIdHelper
internal static async Task GetUniqueModelIdAsync(string baseName, DigitalTwinsClient client, [CallerMemberName] string caller = "")
{
- return await GetUniqueIdAsync(baseName, (modelId) => client.GetModelAsync(modelId)).ConfigureAwait(false);
+ return await GetUniqueIdAsync(baseName, (modelId) => client.GetModelAsync(modelId));
}
internal static async Task GetUniqueTwinIdAsync(string baseName, DigitalTwinsClient client, [CallerMemberName] string caller = "")
{
- return await GetUniqueIdAsync(baseName, (twinId) => client.GetDigitalTwinAsync(twinId)).ConfigureAwait(false);
+ return await GetUniqueIdAsync(baseName, (twinId) => client.GetDigitalTwinAsync(twinId));
}
private static async Task GetUniqueIdAsync(string baseName, Func getResource)
@@ -32,7 +32,7 @@ private static async Task GetUniqueIdAsync(string baseName, Func containing list of json models. Check out sample models [here](https://github.com/Azure/azure-sdk-for-net-pr/tree/feature/IoT-ADT/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/DTDL/Models "Models")
+Let's create models using the code below. You need to pass in List containing list of json models. Check out sample models [here](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/DTDL/Models)
```C# Snippet:DigitalTwinsSampleCreateModels
-Response> response = await DigitalTwinsClient.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload }).ConfigureAwait(false);
+Response> response = await client.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload });
Console.WriteLine($"Successfully created a model with Id: {newComponentModelId}, {sampleModelId}, status: {response.GetRawResponse().Status}");
```
@@ -69,7 +54,7 @@ Console.WriteLine($"Successfully created a model with Id: {newComponentModelId},
Using `GetModelsAsync`, all created models are returned as AsyncPageable
```C# Snippet:DigitalTwinsSampleGetModels
-AsyncPageable allModels = DigitalTwinsClient.GetModelsAsync();
+AsyncPageable allModels = client.GetModelsAsync();
await foreach (ModelData model in allModels)
{
Console.WriteLine($"Model Id: {model.Id}, display name: {model.DisplayName["en"]}, upload time: {model.UploadTime}, is decommissioned: {model.Decommissioned}");
@@ -79,7 +64,7 @@ await foreach (ModelData model in allModels)
Use `GetModelAsync` with model's unique identifier to get a specific model
```C# Snippet:DigitalTwinsSampleGetModel
-Response sampleModel = await DigitalTwinsClient.GetModelAsync(sampleModelId).ConfigureAwait(false);
+Response sampleModel = await client.GetModelAsync(sampleModelId);
```
### Decommission models
@@ -89,7 +74,7 @@ To decommision a model, pass in a model Id for the model you want to decommision
```C# Snippet:DigitalTwinsSampleDecommisionModel
try
{
- await DigitalTwinsClient.DecommissionModelAsync(sampleModelId).ConfigureAwait(false);
+ await client.DecommissionModelAsync(sampleModelId);
Console.WriteLine($"Successfully decommissioned model {sampleModelId}");
}
@@ -106,7 +91,7 @@ To delete a model, pass in a model Id for the model you want to delete.
```C# Snippet:DigitalTwinsSampleDeleteModel
try
{
- await DigitalTwinsClient.DeleteModelAsync(sampleModelId).ConfigureAwait(false);
+ await client.DeleteModelAsync(sampleModelId);
Console.WriteLine($"Deleted model {sampleModelId}");
}
@@ -145,7 +130,7 @@ basicDigitalTwin.CustomProperties.Add("Component1", componentMetadata);
string basicDtPayload = JsonSerializer.Serialize(basicDigitalTwin);
-Response createBasicDtResponse = await DigitalTwinsClient.CreateDigitalTwinAsync(basicDtId, basicDtPayload).ConfigureAwait(false);
+Response createBasicDtResponse = await client.CreateDigitalTwinAsync(basicDtId, basicDtPayload);
Console.WriteLine($"Created digital twin {basicDtId} with response {createBasicDtResponse.GetRawResponse().Status}.");
```
@@ -154,7 +139,7 @@ By specifying your properties and types directly, it requires less code or knowl
interaction.
```C# Snippet:DigitalTwinsSampleCreateCustomTwin
-string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, DigitalTwinsClient).ConfigureAwait(false);
+string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, client);
var customDigitalTwin = new CustomDigitalTwin
{
Id = customDtId,
@@ -170,7 +155,7 @@ var customDigitalTwin = new CustomDigitalTwin
};
string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
-Response createCustomDtResponse = await DigitalTwinsClient.CreateDigitalTwinAsync(customDtId, dt2Payload).ConfigureAwait(false);
+Response createCustomDtResponse = await client.CreateDigitalTwinAsync(customDtId, dt2Payload);
Console.WriteLine($"Created digital twin {customDtId} with response {createCustomDtResponse.GetRawResponse().Status}.");
```
@@ -181,7 +166,7 @@ You can get a digital twin and deserialize it into a BasicDigitalTwin.
It works well for basic stuff, but as you can see it gets more difficult when delving into more complex properties, like components.
```C# Snippet:DigitalTwinsSampleGetBasicDigitalTwin
-Response getBasicDtResponse = await DigitalTwinsClient.GetDigitalTwinAsync(basicDtId).ConfigureAwait(false);
+Response getBasicDtResponse = await client.GetDigitalTwinAsync(basicDtId);
if (getBasicDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
{
BasicDigitalTwin basicDt = JsonSerializer.Deserialize(getBasicDtResponse.Value);
@@ -200,7 +185,7 @@ Getting and deserializing a digital twin into a custom data type is extremely ea
Custom types provide the best possible experience.
```C# Snippet:DigitalTwinsSampleCreateCustomTwin
-string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, DigitalTwinsClient).ConfigureAwait(false);
+string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, client);
var customDigitalTwin = new CustomDigitalTwin
{
Id = customDtId,
@@ -216,7 +201,7 @@ var customDigitalTwin = new CustomDigitalTwin
};
string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
-Response createCustomDtResponse = await DigitalTwinsClient.CreateDigitalTwinAsync(customDtId, dt2Payload).ConfigureAwait(false);
+Response createCustomDtResponse = await client.CreateDigitalTwinAsync(customDtId, dt2Payload);
Console.WriteLine($"Created digital twin {customDtId} with response {createCustomDtResponse.GetRawResponse().Status}.");
```
@@ -227,7 +212,7 @@ Query the Azure Digital Twins instance for digital twins using the [Azure Digita
```C# Snippet:DigitalTwinsSampleQueryTwins
// This code snippet demonstrates the simplest way to iterate over the digital twin results, where paging
// happens under the covers.
-AsyncPageable asyncPageableResponse = DigitalTwinsClient.QueryAsync("SELECT * FROM digitaltwins");
+AsyncPageable asyncPageableResponse = client.QueryAsync("SELECT * FROM digitaltwins");
// Iterate over the twin instances in the pageable response.
// The "await" keyword here is required because new pages will be fetched when necessary,
@@ -239,14 +224,14 @@ await foreach (string response in asyncPageableResponse)
}
```
-The SDK also allows you to extract the `query-charge` header from the pagebale response. Here's an example of how to query for digital twins and how to iterate over the pageable response to extract the `query-charge` header.
+The SDK also allows you to extract the `query-charge` header from the pageable response. Here's an example of how to query for digital twins and how to iterate over the pageable response to extract the `query-charge` header.
```C# Snippet:DigitalTwinsSampleQueryTwinsWithQueryCharge
// This code snippet demonstrates how you could extract the query charges incurred when calling
// the query API. It iterates over the response pages first to access to the query-charge header,
// and then the digital twin results within each page.
-AsyncPageable asyncPageableResponseWithCharge = DigitalTwinsClient.QueryAsync("SELECT * FROM digitaltwins");
+AsyncPageable asyncPageableResponseWithCharge = client.QueryAsync("SELECT * FROM digitaltwins");
int pageNum = 0;
// The "await" keyword here is required as a call is made when fetching a new page.
@@ -275,7 +260,7 @@ await foreach (Page page in asyncPageableResponseWithCharge.AsPages())
Delete a digital twin simply by providing Id of a digital twin as below.
```C# Snippet:DigitalTwinsSampleDeleteTwin
-await DigitalTwinsClient.DeleteDigitalTwinAsync(twin.Key).ConfigureAwait(false);
+await client.DeleteDigitalTwinAsync(twin.Key);
```
## Get and update digital twin components
@@ -290,7 +275,7 @@ var componentUpdateUtility = new UpdateOperationsUtility();
componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value");
string updatePayload = componentUpdateUtility.Serialize();
-Response response = await DigitalTwinsClient.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
+Response response = await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
Console.WriteLine($"Updated component for digital twin {basicDtId}. Update response status: {response.GetRawResponse().Status}");
```
@@ -300,37 +285,35 @@ Console.WriteLine($"Updated component for digital twin {basicDtId}. Update respo
Get a component by providing name of a component and Id of digital twin it belongs to.
```C# Snippet:DigitalTwinsSampleGetComponent
-response = await DigitalTwinsClient.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath).ConfigureAwait(false);
+response = await client.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath);
Console.WriteLine($"Get component for digital twin: \n{response.Value}. Get response status: {response.GetRawResponse().Status}");
```
## Create and list digital twin relationships
-### Create digital twin telationships
+### Create digital twin relationships
`CreateRelationshipAsync` creates a relationship on a digital twin provided with Id of a digital twin, name of relationship such as "contains", Id of an relationship such as "FloorContainsRoom" and an application/json relationship to be created. Must contain property with key "$targetId" to specify the target of the relationship. Sample payloads for relationships can be found [here](https://github.com/Azure/azure-sdk-for-net-pr/blob/feature/IoT-ADT/sdk/iot/Azure.Iot.DigitalTwins/samples/DigitalTwinServiceClientSample/DTDL/Relationships/HospitalRelationships.json "RelationshipExamples").
```C# Snippet:DigitalTwinsSampleCreateRelationship
string serializedRelationship = JsonSerializer.Serialize(relationship);
-await DigitalTwinsClient
- .CreateRelationshipAsync(
- relationship.SourceId,
- relationship.Id,
- serializedRelationship)
- .ConfigureAwait(false);
+await client.CreateRelationshipAsync(
+ relationship.SourceId,
+ relationship.Id,
+ serializedRelationship);
```
### List digital twin relationships
`GetrelationshipsAsync` and `GetIncomingRelationshipsAsync` lists all the relationships and all incoming relationships respectively of a digital twin
```C# Snippet:DigitalTwinsSampleGetRelationships
-AsyncPageable relationships = DigitalTwinsClient.GetRelationshipsAsync(twin.Key);
+AsyncPageable relationships = client.GetRelationshipsAsync(twin.Key);
```
```C# Snippet:DigitalTwinsSampleGetIncomingRelationships
-AsyncPageable incomingRelationships = DigitalTwinsClient.GetIncomingRelationshipsAsync(twin.Key);
+AsyncPageable incomingRelationships = client.GetIncomingRelationshipsAsync(twin.Key);
```
## Create, list, and delete event routes of digital twins
@@ -341,12 +324,12 @@ To create an event route, provide an Id of an event route such as "sampleEventRo
```C# Snippet:DigitalTwinsSampleCreateEventRoute
string eventFilter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'";
-var eventRoute = new EventRoute(_eventhubEndpointName)
+var eventRoute = new EventRoute(eventhubEndpointName)
{
Filter = eventFilter
};
-Response createEventRouteResponse = await DigitalTwinsClient.CreateEventRouteAsync(_eventRouteId, eventRoute).ConfigureAwait(false);
+Response createEventRouteResponse = await client.CreateEventRouteAsync(_eventRouteId, eventRoute);
```
### List event routes
@@ -354,7 +337,7 @@ Response createEventRouteResponse = await DigitalTwinsClient.CreateEventRouteAsy
List a specific event route given event route Id or all event routes setting options with `GetEventRouteAsync` and `GetEventRoutesAsync`.
```C# Snippet:DigitalTwinsSampleGetEventRoutes
-AsyncPageable response = DigitalTwinsClient.GetEventRoutesAsync();
+AsyncPageable response = client.GetEventRoutesAsync();
await foreach (EventRoute er in response)
{
Console.WriteLine($"Event route: {er.Id}, endpoint name: {er.EndpointName}");
@@ -366,7 +349,7 @@ await foreach (EventRoute er in response)
Delete an event route given event route Id.
```C# Snippet:DigitalTwinsSampleDeleteEventRoute
-Response response = await DigitalTwinsClient.DeleteEventRouteAsync(_eventRouteId).ConfigureAwait(false);
+Response response = await client.DeleteEventRouteAsync(_eventRouteId);
```
### Publish telemetry messages for a digital twin
@@ -375,7 +358,7 @@ To publish a telemetry message for a digital twin, you need to provide the digit
```C# Snippet:DigitalTwinsSamplePublishTelemetry
// construct your json telemetry payload by hand.
-Response publishTelemetryResponse = await DigitalTwinsClient.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}");
+Response publishTelemetryResponse = await client.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}");
Console.WriteLine($"Successfully published telemetry message, status: {publishTelemetryResponse.Status}");
```
@@ -387,6 +370,9 @@ var telemetryPayload = new Dictionary
{
{ "ComponentTelemetry1", 9}
};
-Response publishTelemetryToComponentResponse = await DigitalTwinsClient.PublishComponentTelemetryAsync(twinId, "Component1", JsonSerializer.Serialize(telemetryPayload));
+Response publishTelemetryToComponentResponse = await client.PublishComponentTelemetryAsync(
+ twinId,
+ "Component1",
+ JsonSerializer.Serialize(telemetryPayload));
Console.WriteLine($"Successfully published component telemetry message, status: {publishTelemetryToComponentResponse.Status}");
```
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs
index bd1be4fdb3ec4..560fb9a8a93ab 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs
@@ -48,7 +48,7 @@ public class DigitalTwinsClient
/// clientSecret,
/// new TokenCredentialOptions { AuthorityHost = KnownAuthorityHosts.AzureCloud });
///
- /// var dtClient = new DigitalTwinsClient(
+ /// var client = new DigitalTwinsClient(
/// new Uri(adtEndpoint),
/// tokenCredential);
///
@@ -86,7 +86,7 @@ public DigitalTwinsClient(Uri endpoint, TokenCredential credential)
/// clientId,
/// new TokenCredentialOptions { AuthorityHost = KnownAuthorityHosts.AzureCloud });
///
- /// var dtClient = new DigitalTwinsClient(
+ /// var client = new DigitalTwinsClient(
/// new Uri(adtEndpoint),
/// tokenCredential,
/// clientOptions);
@@ -130,7 +130,7 @@ protected DigitalTwinsClient()
/// This sample demonstrates getting and deserializing a digital twin into a custom data type.
///
///
- /// Response<string> getCustomDtResponse = await DigitalTwinsClient.GetDigitalTwinAsync(customDtId).ConfigureAwait(false);
+ /// Response<string> getCustomDtResponse = await client.GetDigitalTwinAsync(customDtId);
/// if (getCustomDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
/// {
/// CustomDigitalTwin customDt = JsonSerializer.Deserialize<CustomDigitalTwin>(getCustomDtResponse.Value);
@@ -170,7 +170,7 @@ public virtual Response GetDigitalTwin(string digitalTwinId, Cancellatio
/// The created application/json digital twin and the http response.
///
///
- /// string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, DigitalTwinsClient).ConfigureAwait(false);
+ /// string customDtId = await GetUniqueTwinIdAsync(SamplesConstants.TemporaryTwinPrefix, client);
/// var customDigitalTwin = new CustomDigitalTwin
/// {
/// Id = customDtId,
@@ -186,7 +186,7 @@ public virtual Response GetDigitalTwin(string digitalTwinId, Cancellatio
/// };
/// string dt2Payload = JsonSerializer.Serialize(customDigitalTwin);
///
- /// Response<string> createCustomDtResponse = await DigitalTwinsClient.CreateDigitalTwinAsync(customDtId, dt2Payload).ConfigureAwait(false);
+ /// Response<string> createCustomDtResponse = await client.CreateDigitalTwinAsync(customDtId, dt2Payload);
/// Console.WriteLine($"Created digital twin {customDtId} with response {createCustomDtResponse.GetRawResponse().Status}.");
///
///
@@ -219,7 +219,7 @@ public virtual Response CreateDigitalTwin(string digitalTwinId, string d
///
///
///
- /// await DigitalTwinsClient.DeleteDigitalTwinAsync(twin.Key).ConfigureAwait(false);
+ /// await client.DeleteDigitalTwinAsync(twin.Key);
///
///
public virtual Task DeleteDigitalTwinAsync(string digitalTwinId, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
@@ -281,7 +281,7 @@ public virtual Response UpdateDigitalTwin(string digitalTwinId, string d
/// Json string representation of the component corresponding to the provided componentPath and the HTTP response.
///
///
- /// response = await DigitalTwinsClient.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath).ConfigureAwait(false);
+ /// response = await client.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath);
///
/// Console.WriteLine($"Get component for digital twin: \n{response.Value}. Get response status: {response.GetRawResponse().Status}");
///
@@ -322,7 +322,7 @@ public virtual Response GetComponent(string digitalTwinId, string compon
/// componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value");
/// string updatePayload = componentUpdateUtility.Serialize();
///
- /// Response<string> response = await DigitalTwinsClient.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
+ /// Response<string> response = await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
///
/// Console.WriteLine($"Updated component for digital twin {basicDtId}. Update response status: {response.GetRawResponse().Status}");
///
@@ -359,7 +359,7 @@ public virtual Response UpdateComponent(string digitalTwinId, string com
/// The pageable list of application/json relationships belonging to the specified digital twin and the http response.
///
///
- /// AsyncPageable<string> relationships = DigitalTwinsClient.GetRelationshipsAsync(twin.Key);
+ /// AsyncPageable<string> relationships = client.GetRelationshipsAsync(twin.Key);
///
///
public virtual AsyncPageable GetRelationshipsAsync(string digitalTwinId, string relationshipName = null, CancellationToken cancellationToken = default)
@@ -464,7 +464,7 @@ Page NextPageFunc(string nextLink, int? pageSizeHint)
/// The pageable list of application/json relationships directed towards the specified digital twin and the http response.
///
///
- /// AsyncPageable<IncomingRelationship> incomingRelationships = DigitalTwinsClient.GetIncomingRelationshipsAsync(twin.Key);
+ /// AsyncPageable<IncomingRelationship> incomingRelationships = client.GetIncomingRelationshipsAsync(twin.Key);
///
///
public virtual AsyncPageable GetIncomingRelationshipsAsync(string digitalTwinId, CancellationToken cancellationToken = default)
@@ -624,12 +624,10 @@ public virtual Response DeleteRelationship(string digitalTwinId, string relation
///
/// string serializedRelationship = JsonSerializer.Serialize(relationship);
///
- /// await DigitalTwinsClient
- /// .CreateRelationshipAsync(
- /// relationship.SourceId,
- /// relationship.Id,
- /// serializedRelationship)
- /// .ConfigureAwait(false);
+ /// await client.CreateRelationshipAsync(
+ /// relationship.SourceId,
+ /// relationship.Id,
+ /// serializedRelationship);
///
///
public virtual Task> CreateRelationshipAsync(string digitalTwinId, string relationshipId, string relationship, CancellationToken cancellationToken = default)
@@ -699,7 +697,7 @@ public virtual Response UpdateRelationship(string digitalTwinId, string relation
/// A pageable set of application/json models and the http response.
///
///
- /// AsyncPageable<ModelData> allModels = DigitalTwinsClient.GetModelsAsync();
+ /// AsyncPageable<ModelData> allModels = client.GetModelsAsync();
/// await foreach (ModelData model in allModels)
/// {
/// Console.WriteLine($"Model Id: {model.Id}, display name: {model.DisplayName["en"]}, upload time: {model.UploadTime}, is decommissioned: {model.Decommissioned}");
@@ -799,7 +797,7 @@ Page NextPageFunc(string nextLink, int? pageSizeHint)
/// The application/json model and the http response.
///
///
- /// Response<ModelData> sampleModel = await DigitalTwinsClient.GetModelAsync(sampleModelId).ConfigureAwait(false);
+ /// Response<ModelData> sampleModel = await client.GetModelAsync(sampleModelId);
///
///
public virtual Task> GetModelAsync(string modelId, CancellationToken cancellationToken = default)
@@ -838,7 +836,7 @@ public virtual Response GetModel(string modelId, CancellationToken ca
///
/// try
/// {
- /// await DigitalTwinsClient.DecommissionModelAsync(sampleModelId).ConfigureAwait(false);
+ /// await client.DecommissionModelAsync(sampleModelId);
///
/// Console.WriteLine($"Successfully decommissioned model {sampleModelId}");
/// }
@@ -886,7 +884,7 @@ public virtual Response DecommissionModel(string modelId, CancellationToken canc
///
///
///
- /// Response<IReadOnlyList<ModelData>> response = await DigitalTwinsClient.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload }).ConfigureAwait(false);
+ /// Response<IReadOnlyList<ModelData>> response = await client.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload });
/// Console.WriteLine($"Successfully created a model with Id: {newComponentModelId}, {sampleModelId}, status: {response.GetRawResponse().Status}");
///
///
@@ -932,7 +930,7 @@ public virtual Response> CreateModels(IEnumerable
/// try
/// {
- /// await DigitalTwinsClient.DeleteModelAsync(sampleModelId).ConfigureAwait(false);
+ /// await client.DeleteModelAsync(sampleModelId);
///
/// Console.WriteLine($"Deleted model {sampleModelId}");
/// }
@@ -978,7 +976,7 @@ public virtual Response DeleteModel(string modelId, CancellationToken cancellati
///
/// // This code snippet demonstrates the simplest way to iterate over the digital twin results, where paging
/// // happens under the covers.
- /// AsyncPageable<string> asyncPageableResponse = DigitalTwinsClient.QueryAsync("SELECT * FROM digitaltwins");
+ /// AsyncPageable<string> asyncPageableResponse = client.QueryAsync("SELECT * FROM digitaltwins");
///
/// // Iterate over the twin instances in the pageable response.
/// // The "await" keyword here is required because new pages will be fetched when necessary,
@@ -1104,7 +1102,7 @@ Page NextPageFunc(string nextLink, int? pageSizeHint)
/// A pageable set of application/json event routes and the http response.
///
///
- /// AsyncPageable<EventRoute> response = DigitalTwinsClient.GetEventRoutesAsync();
+ /// AsyncPageable<EventRoute> response = client.GetEventRoutesAsync();
/// await foreach (EventRoute er in response)
/// {
/// Console.WriteLine($"Event route: {er.Id}, endpoint name: {er.EndpointName}");
@@ -1229,12 +1227,12 @@ public virtual Response GetEventRoute(string eventRouteId, Cancellat
///
///
/// string eventFilter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'";
- /// var eventRoute = new EventRoute(_eventhubEndpointName)
+ /// var eventRoute = new EventRoute(eventhubEndpointName)
/// {
/// Filter = eventFilter
/// };
///
- /// Response createEventRouteResponse = await DigitalTwinsClient.CreateEventRouteAsync(_eventRouteId, eventRoute).ConfigureAwait(false);
+ /// Response createEventRouteResponse = await client.CreateEventRouteAsync(_eventRouteId, eventRoute);
///
///
public virtual Task CreateEventRouteAsync(string eventRouteId, EventRoute eventRoute, CancellationToken cancellationToken = default)
@@ -1265,7 +1263,7 @@ public virtual Response CreateEventRoute(string eventRouteId, EventRoute eventRo
/// The http response.
///
///
- /// Response response = await DigitalTwinsClient.DeleteEventRouteAsync(_eventRouteId).ConfigureAwait(false);
+ /// Response response = await client.DeleteEventRouteAsync(_eventRouteId);
///
///
public virtual Task DeleteEventRouteAsync(string eventRouteId, CancellationToken cancellationToken = default)
@@ -1300,7 +1298,7 @@ public virtual Response DeleteEventRoute(string eventRouteId, CancellationToken
///
///
/// // construct your json telemetry payload by hand.
- /// Response publishTelemetryResponse = await DigitalTwinsClient.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}");
+ /// Response publishTelemetryResponse = await client.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}");
/// Console.WriteLine($"Successfully published telemetry message, status: {publishTelemetryResponse.Status}");
///
///
@@ -1352,7 +1350,10 @@ public virtual Response PublishTelemetry(string digitalTwinId, string payload, T
/// {
/// { "ComponentTelemetry1", 9}
/// };
- /// Response publishTelemetryToComponentResponse = await DigitalTwinsClient.PublishComponentTelemetryAsync(twinId, "Component1", JsonSerializer.Serialize(telemetryPayload));
+ /// Response publishTelemetryToComponentResponse = await client.PublishComponentTelemetryAsync(
+ /// twinId,
+ /// "Component1",
+ /// JsonSerializer.Serialize(telemetryPayload));
/// Console.WriteLine($"Successfully published component telemetry message, status: {publishTelemetryToComponentResponse.Status}");
///
///
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Queries/QueryChargeHelper.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Queries/QueryChargeHelper.cs
index e3c8b266cf6e4..d3bcdc6156556 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Queries/QueryChargeHelper.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Queries/QueryChargeHelper.cs
@@ -26,7 +26,7 @@ public static class QueryChargeHelper
/// // the query API. It iterates over the response pages first to access to the query-charge header,
/// // and then the digital twin results within each page.
///
- /// AsyncPageable<string> asyncPageableResponseWithCharge = DigitalTwinsClient.QueryAsync("SELECT * FROM digitaltwins");
+ /// AsyncPageable<string> asyncPageableResponseWithCharge = client.QueryAsync("SELECT * FROM digitaltwins");
/// int pageNum = 0;
///
/// // The "await" keyword here is required as a call is made when fetching a new page.
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs
index 2fd792d82f849..82bf7324ee279 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/BasicDigitalTwin.cs
@@ -31,14 +31,14 @@ namespace Azure.DigitalTwins.Core.Serialization
///
/// string basicDtPayload = JsonSerializer.Serialize(basicDigitalTwin);
///
- /// Response<string> createBasicDtResponse = await DigitalTwinsClient.CreateDigitalTwinAsync(basicDtId, basicDtPayload).ConfigureAwait(false);
+ /// Response<string> createBasicDtResponse = await client.CreateDigitalTwinAsync(basicDtId, basicDtPayload);
/// Console.WriteLine($"Created digital twin {basicDtId} with response {createBasicDtResponse.GetRawResponse().Status}.");
///
///
/// Here's an example of how to use the BasicDigitalTwin helper class to get and deserialize a digital twin.
///
///
- /// Response<string> getBasicDtResponse = await DigitalTwinsClient.GetDigitalTwinAsync(basicDtId).ConfigureAwait(false);
+ /// Response<string> getBasicDtResponse = await client.GetDigitalTwinAsync(basicDtId);
/// if (getBasicDtResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
/// {
/// BasicDigitalTwin basicDt = JsonSerializer.Deserialize<BasicDigitalTwin>(getBasicDtResponse.Value);
diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/UpdateOperationsUtility.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/UpdateOperationsUtility.cs
index 421fae4f398d4..48efd0c340643 100644
--- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/UpdateOperationsUtility.cs
+++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/UpdateOperationsUtility.cs
@@ -16,7 +16,7 @@ namespace Azure.DigitalTwins.Core.Serialization
/// componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value");
/// string updatePayload = componentUpdateUtility.Serialize();
///
- /// Response<string> response = await DigitalTwinsClient.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
+ /// Response<string> response = await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload);
///
/// Console.WriteLine($"Updated component for digital twin {basicDtId}. Update response status: {response.GetRawResponse().Status}");
///