From 0dd6f17f5e152fb07781315bd39c3c0f98b8fa86 Mon Sep 17 00:00:00 2001 From: Basel Rustum Date: Thu, 11 Jun 2020 10:34:42 -0700 Subject: [PATCH 1/2] simplify delete relationship snippet --- .../RelationshipSamples.cs | 26 ++++++------------- .../Azure.DigitalTwins.Core/samples/Readme.md | 22 +++------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs index 6a3a4b89cd666..5c82d9589953e 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs @@ -178,27 +178,17 @@ public async Task RunSamplesAsync(DigitalTwinsClient client) #endregion Snippet:DigitalTwinsSampleGetIncomingRelationships - #region Snippet:DigitalTwinsSampleDeleteAllRelationships + #region Snippet:DigitalTwinsSampleDeleteRelationship - // Delete all relationships from building to floor. These relationships were created using the BasicRelationship type. - AsyncPageable buildingRelationshipsToDelete = client.GetRelationshipsAsync("buildingTwinId"); - await foreach (var relationshipToDelete in buildingRelationshipsToDelete) - { - BasicRelationship relationship = JsonSerializer.Deserialize(relationshipToDelete); - Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id); - Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}."); - } + // Delete the contains relationship from building to floor. + 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 floorRelationshipsToDelete = client.GetRelationshipsAsync("floorTwinId"); - await foreach (var relationshipToDelete in floorRelationshipsToDelete) - { - CustomRelationship relationship = JsonSerializer.Deserialize(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 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 diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md index f776b08e76296..fb6a9931389ec 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md @@ -416,24 +416,10 @@ 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 buildingRelationshipsToDelete = client.GetRelationshipsAsync("buildingTwinId"); -await foreach (var relationshipToDelete in buildingRelationshipsToDelete) -{ - BasicRelationship relationship = JsonSerializer.Deserialize(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 floorRelationshipsToDelete = client.GetRelationshipsAsync("floorTwinId"); -await foreach (var relationshipToDelete in floorRelationshipsToDelete) -{ - CustomRelationship relationship = JsonSerializer.Deserialize(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 +// Delete the contains relationship from building to floor. +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 From 5991c3f60bf607b54d278f058f1b629081ed45b9 Mon Sep 17 00:00:00 2001 From: Basel Rustum Date: Thu, 11 Jun 2020 16:14:35 -0700 Subject: [PATCH 2/2] Address PR feedback --- .../samples/DigitalTwinsClientSample/RelationshipSamples.cs | 5 +++-- sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs index 5c82d9589953e..2a102241918ec 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs @@ -178,15 +178,16 @@ public async Task RunSamplesAsync(DigitalTwinsClient client) #endregion Snippet:DigitalTwinsSampleGetIncomingRelationships + // Delete the contains relationship, created earlier in the sample code, from building to floor. + #region Snippet:DigitalTwinsSampleDeleteRelationship - // Delete the contains relationship from building to floor. Response deleteBuildingRelationshipResponse = await client.DeleteRelationshipAsync("buildingTwinId", "buildingFloorRelationshipId"); Console.WriteLine($"Deleted relationship with Id buildingFloorRelationshipId. Status response: {deleteBuildingRelationshipResponse.Status}."); #endregion Snippet:DigitalTwinsSampleDeleteRelationship - // Delete the containedIn relationship from floor to building. + // 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}."); diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md index fb6a9931389ec..afe29f39d27ce 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md @@ -417,7 +417,6 @@ 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:DigitalTwinsSampleDeleteRelationship -// Delete the contains relationship from building to floor. Response deleteBuildingRelationshipResponse = await client.DeleteRelationshipAsync("buildingTwinId", "buildingFloorRelationshipId"); Console.WriteLine($"Deleted relationship with Id buildingFloorRelationshipId. Status response: {deleteBuildingRelationshipResponse.Status}."); ```