Exemple #1
0
 /// <summary>
 /// Returns azure subscriptions.
 /// </summary>
 private async Task <IEnumerable <IAzureUserAccountSubscriptionContext> > GetSubscriptionsAsync(bool selectedOnly = true)
 {
     try
     {
         return(selectedOnly ? await AzureAccountManager.GetSelectedSubscriptionsAsync() : await AzureAccountManager.GetSubscriptionsAsync());
     }
     catch (Exception ex)
     {
         throw new ServiceFailedException(string.Format(CultureInfo.CurrentCulture, SR.AzureSubscriptionFailedErrorMessage, ex));
     }
 }
Exemple #2
0
        public async Task <ServiceResponse <ServerInstanceInfo> > GetServerInstancesAsync()
        {
            ServiceResponse <ServerInstanceInfo> result          = new ServiceResponse <ServerInstanceInfo>();
            List <ServerInstanceInfo>            serverInstances = new List <ServerInstanceInfo>();

            if (AccountManager != null && AzureAccountManager != null && AzureResourceManager != null)
            {
                try
                {
                    IEnumerable <IAzureUserAccountSubscriptionContext> subscriptions =
                        await AzureAccountManager.GetSelectedSubscriptionsAsync();

                    if (subscriptions != null)
                    {
                        foreach (IAzureUserAccountSubscriptionContext subscription in subscriptions)
                        {
                            using (IAzureResourceManagementSession session = await AzureResourceManager.CreateSessionAsync(subscription))
                            {
                                IEnumerable <IAzureSqlServerResource> azureResources =
                                    await AzureResourceManager.GetSqlServerAzureResourcesAsync(session);

                                serverInstances.AddRange(
                                    azureResources.Select(x =>
                                                          new ServerInstanceInfo(ServerDefinition)
                                {
                                    Name = x.Name,
                                    FullyQualifiedDomainName = x.FullyQualifiedDomainName,
                                    AdministratorLogin       = x.AdministratorLogin
                                }));
                            }
                        }
                    }
                    result = new ServiceResponse <ServerInstanceInfo>(serverInstances);
                }
                catch (Exception ex)
                {
                    result = new ServiceResponse <ServerInstanceInfo>(serverInstances, new List <Exception>()
                    {
                        ex
                    });
                }
            }

            return(result);
        }