Exemplo n.º 1
0
        /// <summary>
        /// Returns a list of azure servers given subscription
        /// </summary>
        /// <param name="azureResourceManagementSession">Subscription Context which includes credentials to use in the resource manager</param>
        /// <returns>The list of Sql server resources</returns>
        public async Task <IEnumerable <IAzureSqlServerResource> > GetSqlServerAzureResourcesAsync(
            IAzureResourceManagementSession azureResourceManagementSession)
        {
            CommonUtil.CheckForNull(azureResourceManagementSession, "azureResourceManagerSession");
            List <IAzureSqlServerResource> sqlServers = new List <IAzureSqlServerResource>();

            try
            {
                AzureResourceManagementSession vsAzureResourceManagementSession = azureResourceManagementSession as AzureResourceManagementSession;
                if (vsAzureResourceManagementSession != null)
                {
                    IServersOperations serverOperations = vsAzureResourceManagementSession.SqlManagementClient.Servers;
                    IPage <Server>     servers          = await ExecuteCloudRequest(
                        () => serverOperations.ListAsync(),
                        SR.FailedToGetAzureSqlServersWithError);

                    if (servers != null)
                    {
                        sqlServers.AddRange(servers.Select(server => {
                            var serverResource = new SqlAzureResource(server);
                            // TODO ResourceGroup name
                            return(serverResource);
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                TraceException(TraceEventType.Error, (int)TraceId.AzureResource, ex, "Failed to get servers");
                throw;
            }

            return(sqlServers);
        }
Exemplo n.º 2
0
 /// <summary>
 /// List all the servers in a given subscription.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 public static IEnumerable <Server> List(this IServersOperations operations)
 {
     return(operations.ListAsync().GetAwaiter().GetResult());
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets a list of all servers in the subscription.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='expand'>
 /// The child resources to include in the response.
 /// </param>
 public static IPage <Server> List(this IServersOperations operations, string expand = default(string))
 {
     return(operations.ListAsync(expand).GetAwaiter().GetResult());
 }