public async Task <IList <ResourceGroupExtended> > GetResourceGroups() { if (currSubscription.Name == null) { throw new Exception(Properties.Resources.SubscriptionNotSet); } // Get the token for the tenant on this subscription. var cloudtoken = AuthenticateHelper.RefreshTokenByAuthority(azureARMAuthResult.TenantId, Properties.Settings.Default.appIdURI); subscriptionCreds = new TokenCloudCredentials(currSubscription.SubscriptionId, cloudtoken.AccessToken); resourceManagementClient = new ResourceManagementClient(subscriptionCreds, new Uri(Properties.Settings.Default.appIdURI)); ResourceGroupListResult resourceGroupResult = await resourceManagementClient.ResourceGroups.ListAsync(null); return(resourceGroupResult.ResourceGroups); }
public static async Task IterateResourceGroups(this ResourceManagementClient resourceManagementClient, CancellationToken ct, Func <ResourceGroupExtended, Task> action) { ResourceGroupListResult resourceGroupListResult = await resourceManagementClient.ResourceGroups.ListAsync(new ResourceGroupListParameters { }); string nextLink = resourceGroupListResult.NextLink; foreach (var resourceGroupExtended in resourceGroupListResult.ResourceGroups) { await action(resourceGroupExtended); } while (!string.IsNullOrEmpty(nextLink)) { resourceGroupListResult = await resourceManagementClient.ResourceGroups.ListNextAsync(nextLink, ct); nextLink = resourceGroupListResult.NextLink; foreach (var resourceGroupExtended in resourceGroupListResult.ResourceGroups) { await action(resourceGroupExtended); } } }