Skip to content

Commit 0fe7635

Browse files
authored
update name from tryget to getifexists (Azure#22938)
* update name from tryget to getifexists * update to return Response<T> for GetIfExists and CheckIfExists * update api * update ManageGroup to adop if exists changes * update subscription to adopt if exists changes * update features to use new if exists * update generic resource to use new if exists * update provider to use new if exists * update resource group to use new if exists * final changes * update api after changes * update snippets to not use var update typo in readme * one more typo * update list references
1 parent d8c7b95 commit 0fe7635

File tree

95 files changed

+139686
-110957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+139686
-110957
lines changed

common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ protected void CleanupResourceGroups()
104104
{
105105
try
106106
{
107-
var sub = _cleanupClient.GetSubscriptions().TryGet(TestEnvironment.SubscriptionId);
108-
sub?.GetResourceGroups().Get(resourceGroup).Value.StartDelete();
107+
var sub = _cleanupClient.GetSubscriptions().GetIfExists(TestEnvironment.SubscriptionId);
108+
sub.Value?.GetResourceGroups().Get(resourceGroup).Value.StartDelete();
109109
}
110110
catch (RequestFailedException e) when (e.Status == 404)
111111
{
@@ -201,8 +201,8 @@ public void OneTimeCleanupResourceGroups()
201201
{
202202
Parallel.ForEach(OneTimeResourceGroupCleanupPolicy.ResourceGroupsCreated, resourceGroup =>
203203
{
204-
var sub = _cleanupClient.GetSubscriptions().TryGet(SessionEnvironment.SubscriptionId);
205-
sub?.GetResourceGroups().Get(resourceGroup).Value.StartDelete();
204+
var sub = _cleanupClient.GetSubscriptions().GetIfExists(SessionEnvironment.SubscriptionId);
205+
sub.Value?.GetResourceGroups().Get(resourceGroup).Value.StartDelete();
206206
});
207207
Parallel.ForEach(OneTimeManagementGroupCleanupPolicy.ManagementGroupsCreated, mgmtGroupId =>
208208
{

sdk/resourcemanager/Azure.ResourceManager/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using Azure.ResourceManager.Resources;
4242

4343
// Code omitted for brevity
4444
45-
var armClient = new ArmClient(new DefaultAzureCredential());
45+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
4646
```
4747

4848
Additional documentation for the `Azure.Identity.DefaultAzureCredential` class can be found in [this document](https://docs.microsoft.com/dotnet/api/azure.identity.defaultazurecredential).
@@ -149,9 +149,9 @@ AvailabilitySet availabilitySet = await availabilitySetOperations.GetAsync();
149149
```
150150

151151
### `tryGet` and `CheckIfExistss` convenience methods
152-
If you are not sure if a resource you want to get exists, or you just want to check if it exists, you can use `tryGet()` or `CheckIfExistss()` methods, which can be invoque from any [Resource]Container class.
152+
If you are not sure if a resource you want to get exists, or you just want to check if it exists, you can use `GetIfExists()` or `CheckIfExistss()` methods, which can be invoque from any [Resource]Container class.
153153

154-
`tryGet()` and `tryGetAsync()` are going to return a null object if the specified resource name or id does not exists. On the other hand, `CheckIfExistss()` and `CheckIfExistssAsync()` is going to return a boolean, depending if the specified resource exists.
154+
`GetIfExists()` and `GetIfExistsAsync()` are going to return a null object if the specified resource name or id does not exists. On the other hand, `CheckIfExistss()` and `CheckIfExistssAsync()` is going to return a boolean, depending if the specified resource exists.
155155

156156
You can find an example for these methods [below](#check-if-resource-group-exists).
157157

@@ -160,7 +160,7 @@ You can find an example for these methods [below](#check-if-resource-group-exist
160160
### Create a resource group
161161
```C# Snippet:Managing_Resource_Groups_CreateAResourceGroup
162162
// First, initialize the ArmClient and get the default subscription
163-
var armClient = new ArmClient(new DefaultAzureCredential());
163+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
164164
// Now we get a ResourceGroup container for that subscription
165165
Subscription subscription = armClient.DefaultSubscription;
166166
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
@@ -174,7 +174,7 @@ ResourceGroup resourceGroup = await rgContainer.Construct(location).CreateOrUpda
174174
### List all resource groups
175175
```C# Snippet:Managing_Resource_Groups_ListAllResourceGroup
176176
// First, initialize the ArmClient and get the default subscription
177-
var armClient = new ArmClient(new DefaultAzureCredential());
177+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
178178
Subscription subscription = armClient.DefaultSubscription;
179179
// Now we get a ResourceGroup container for that subscription
180180
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
@@ -189,7 +189,7 @@ await foreach (ResourceGroup rg in response)
189189
### Update a resource group
190190
```C# Snippet:Managing_Resource_Groups_UpdateAResourceGroup
191191
// Note: Resource group named 'myRgName' should exist for this example to work.
192-
var armClient = new ArmClient(new DefaultAzureCredential());
192+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
193193
Subscription subscription = armClient.DefaultSubscription;
194194
string rgName = "myRgName";
195195
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
@@ -198,7 +198,7 @@ resourceGroup = await resourceGroup.AddTagAsync("key", "value");
198198

199199
### Delete a resource group
200200
```C# Snippet:Managing_Resource_Groups_DeleteResourceGroup
201-
var armClient = new ArmClient(new DefaultAzureCredential());
201+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
202202
Subscription subscription = armClient.DefaultSubscription;
203203
string rgName = "myRgName";
204204
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
@@ -207,33 +207,33 @@ await resourceGroup.DeleteAsync();
207207

208208
### Check if Resource Group exists
209209
```C# Snippet:Readme_CheckIfExistssRG
210-
var armClient = new ArmClient(new DefaultAzureCredential());
210+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
211211
Subscription subscription = armClient.DefaultSubscription;
212212
string rgName = "myRgName";
213213

214-
var exists = await subscription.GetResourceGroups().CheckIfExistsAsync(rgName);
214+
bool exists = await subscription.GetResourceGroups().CheckIfExistsAsync(rgName);
215215

216216
if (exists)
217217
{
218218
Console.WriteLine($"Resource Group {rgName} exists.");
219219

220220
// We can get the resource group now that we are sure it exists.
221-
var myRG = await subscription.GetResourceGroups().GetAsync(rgName);
221+
ResourceGroup myRG = await subscription.GetResourceGroups().GetAsync(rgName);
222222
}
223223
else
224224
{
225225
Console.WriteLine($"Resource Group {rgName} does not exist.");
226226
}
227227
```
228228

229-
Another way to do this is by using `tryGet()`:
229+
Another way to do this is by using `GetIfExists()`:
230230

231231
```C# Snippet:Readme_TryGetRG
232-
var armClient = new ArmClient(new DefaultAzureCredential());
232+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
233233
Subscription subscription = armClient.DefaultSubscription;
234234
string rgName = "myRgName";
235235

236-
var myRG = await subscription.GetResourceGroups().TryGetAsync(rgName);
236+
ResourceGroup myRG = await subscription.GetResourceGroups().GetIfExistsAsync(rgName);
237237

238238
if (myRG == null)
239239
{
@@ -262,7 +262,7 @@ VirtualMachineContainer vmContainer = resourceGroup.GetVirtualMachines();
262262

263263
// Next we loop over all vms in the container
264264
// Each vm is a [Resource] object from above
265-
await foreach(VirtualMachine vm in vmContainer.ListAsync())
265+
await foreach(VirtualMachine vm in vmContainer.GetAll())
266266
{
267267
// We access the [Resource]Data properties from vm.Data
268268
if(!vm.Data.Tags.ContainsKey("owner"))

0 commit comments

Comments
 (0)