Пример #1
0
        private async Task <ServiceResponse <IAzureUserAccountSubscriptionContext> > GetSubscriptionsForTentantAsync(
            IAzureUserAccount userAccount, IAzureTenant tenant, string lookupKey,
            CancellationToken cancellationToken, CancellationToken internalCancellationToken)
        {
            AzureTenant azureTenant = tenant as AzureTenant;

            if (azureTenant != null)
            {
                ServiceClientCredentials credentials = CreateCredentials(azureTenant);
                string armEndpoint = userAccount.UnderlyingAccount.Properties.ProviderSettings?.Settings?.ArmResource?.Endpoint;
                Uri    armUri      = null;
                if (armEndpoint != null)
                {
                    try
                    {
                        armUri = new Uri(armEndpoint);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Exception while parsing URI: {e.Message}");
                    }
                }
                using (SubscriptionClient client = new SubscriptionClient(armUri ?? _resourceManagementUri, credentials))
                {
                    IEnumerable <Subscription> subs = await GetSubscriptionsAsync(client);

                    return(new ServiceResponse <IAzureUserAccountSubscriptionContext>(subs.Select(sub =>
                    {
                        AzureSubscriptionIdentifier subId = new AzureSubscriptionIdentifier(userAccount, azureTenant.TenantId, sub.SubscriptionId, armUri ?? _resourceManagementUri);
                        AzureUserAccountSubscriptionContext context = new AzureUserAccountSubscriptionContext(subId, credentials);
                        return context;
                    })));
                }
            }
            return(new ServiceResponse <IAzureUserAccountSubscriptionContext>());
        }