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

Simplify delete relationship snippet #12717

Merged
merged 2 commits into from
Jun 11, 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 @@ -178,27 +178,18 @@ public async Task RunSamplesAsync(DigitalTwinsClient client)

#endregion Snippet:DigitalTwinsSampleGetIncomingRelationships

#region Snippet:DigitalTwinsSampleDeleteAllRelationships
// Delete the contains relationship, created earlier in the sample code, from building to floor.

#region Snippet:DigitalTwinsSampleDeleteRelationship

// Delete all relationships from building to floor. These relationships were created using the BasicRelationship type.
AsyncPageable<string> buildingRelationshipsToDelete = client.GetRelationshipsAsync("buildingTwinId");
await foreach (var relationshipToDelete in buildingRelationshipsToDelete)
{
BasicRelationship relationship = JsonSerializer.Deserialize<BasicRelationship>(relationshipToDelete);
Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id);
Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}.");
}
Response deleteBuildingRelationshipResponse = await client.DeleteRelationshipAsync("buildingTwinId", "buildingFloorRelationshipId");
Console.WriteLine($"Deleted relationship with Id buildingFloorRelationshipId. Status response: {deleteBuildingRelationshipResponse.Status}.");

// Delete all relationships from floor to building. These relationships were created using the CustomRelationship type.
AsyncPageable<string> floorRelationshipsToDelete = client.GetRelationshipsAsync("floorTwinId");
await foreach (var relationshipToDelete in floorRelationshipsToDelete)
{
CustomRelationship relationship = JsonSerializer.Deserialize<CustomRelationship>(relationshipToDelete);
Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id);
Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}.");
}
#endregion Snippet:DigitalTwinsSampleDeleteRelationship

#endregion Snippet:DigitalTwinsSampleDeleteAllRelationships
// Delete the containedIn relationship, created earlier in the sample code, from floor to building.
Response deleteFloorRelationshipResponse = await client.DeleteRelationshipAsync("floorTwinId", "floorBuildingRelationshipId");
Console.WriteLine($"Deleted relationship with Id floorBuildingRelationshipId. Status response: {deleteFloorRelationshipResponse.Status}.");

// Clean up.
try
Expand Down
21 changes: 3 additions & 18 deletions sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,24 +416,9 @@ await foreach (IncomingRelationship incomingRelationship in incomingRelationship

To delete all outgoing relationships for a digital twin, simply iterate over the relationships and delete them iteratively.

```C# Snippet:DigitalTwinsSampleDeleteAllRelationships
// Delete all relationships from building to floor. These relationships were created using the BasicRelationship type.
AsyncPageable<string> buildingRelationshipsToDelete = client.GetRelationshipsAsync("buildingTwinId");
await foreach (var relationshipToDelete in buildingRelationshipsToDelete)
{
BasicRelationship relationship = JsonSerializer.Deserialize<BasicRelationship>(relationshipToDelete);
Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id);
Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}.");
}

// Delete all relationships from floor to building. These relationships were created using the CustomRelationship type.
AsyncPageable<string> floorRelationshipsToDelete = client.GetRelationshipsAsync("floorTwinId");
await foreach (var relationshipToDelete in floorRelationshipsToDelete)
{
CustomRelationship relationship = JsonSerializer.Deserialize<CustomRelationship>(relationshipToDelete);
Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id);
Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}.");
}
```C# Snippet:DigitalTwinsSampleDeleteRelationship
Response deleteBuildingRelationshipResponse = await client.DeleteRelationshipAsync("buildingTwinId", "buildingFloorRelationshipId");
Console.WriteLine($"Deleted relationship with Id buildingFloorRelationshipId. Status response: {deleteBuildingRelationshipResponse.Status}.");
```

## Create, list, and delete event routes of digital twins
Expand Down