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

refactor(samples): Refactor the delete digital twin sample snippet #12716

Merged
merged 1 commit into from
Jun 11, 2020
Merged
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 @@ -196,19 +196,21 @@ public async Task DeleteTwinsAsync()

foreach (KeyValuePair<string, string> twin in twins)
{
var digitalTwinId = twin.Key;

try
{
// Delete all relationships
AsyncPageable<string> relationships = client.GetRelationshipsAsync(twin.Key);
AsyncPageable<string> relationships = client.GetRelationshipsAsync(digitalTwinId);
await foreach (var relationshipJson in relationships)
{
BasicRelationship relationship = JsonSerializer.Deserialize<BasicRelationship>(relationshipJson);
await client.DeleteRelationshipAsync(twin.Key, relationship.Id);
await client.DeleteRelationshipAsync(digitalTwinId, relationship.Id);
Console.WriteLine($"Found and deleted relationship with Id {relationship.Id}.");
}

// Delete any incoming relationships
AsyncPageable<IncomingRelationship> incomingRelationships = client.GetIncomingRelationshipsAsync(twin.Key);
AsyncPageable<IncomingRelationship> incomingRelationships = client.GetIncomingRelationshipsAsync(digitalTwinId);

await foreach (IncomingRelationship incomingRelationship in incomingRelationships)
{
Expand All @@ -217,7 +219,6 @@ public async Task DeleteTwinsAsync()
}

// Now the digital twin should be safe to delete
string digitalTwinId = twin.Key;

#region Snippet:DigitalTwinsSampleDeleteTwin

Expand All @@ -233,7 +234,7 @@ public async Task DeleteTwinsAsync()
}
catch (RequestFailedException ex)
{
FatalError($"Failed to delete {twin.Key} due to {ex.Message}");
FatalError($"Failed to delete {digitalTwinId} due to {ex.Message}");
}
}
}
Expand Down