Пример #1
0
 public DatabaseInstanceInfo(ServerDefinition serverDefinition, string serverName, string databaseName)
 {
     ServerInstanceInfo = new ServerInstanceInfo(serverDefinition)
     {
         Name = serverName
     };
     Name = databaseName;
 }
        /// <summary>
        /// Converts the resource to DatabaseInstanceInfo
        /// </summary>
        private DatabaseInstanceInfo ConvertToModel(ServerInstanceInfo serverInstanceInfo, IAzureResource azureResource)
        {
            DatabaseInstanceInfo databaseInstance = new DatabaseInstanceInfo(serverInstanceInfo)
            {
                Name = azureResource.Name.Replace(serverInstanceInfo.Name + "/", "")
            };

            return(databaseInstance);
        }
        private async Task <ServiceResponse <DatabaseInstanceInfo> > GetDatabasesForServerFromService(
            IAzureResourceManagementSession session,
            IAzureSqlServerResource azureSqlServer,
            string serverName,
            CancellationToken cancellationToken,
            CancellationToken internalCancellationToken)
        {
            try
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(new ServiceResponse <DatabaseInstanceInfo>());
                }
                ServerInstanceInfo serverInstanceInfo = new ServerInstanceInfo(ServerDefinition)
                {
                    Name = azureSqlServer.Name,
                    FullyQualifiedDomainName = azureSqlServer.FullyQualifiedDomainName,
                    AdministratorLogin       = azureSqlServer.AdministratorLogin
                };
                OnDatabaseFound(new DatabaseInstanceInfo(serverInstanceInfo));
                IEnumerable <IAzureResource> databases = await AzureResourceManager.GetAzureDatabasesAsync(
                    session,
                    azureSqlServer.ResourceGroupName,
                    azureSqlServer.Name);

                if (cancellationToken.IsCancellationRequested)
                {
                    return(new ServiceResponse <DatabaseInstanceInfo>());
                }
                else
                {
                    IEnumerable <DatabaseInstanceInfo>     data   = databases.Select(x => ConvertToModel(serverInstanceInfo, x));
                    ServiceResponse <DatabaseInstanceInfo> result = new ServiceResponse <DatabaseInstanceInfo>(data);
                    foreach (var databaseInstance in result.Data)
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            break;
                        }
                        OnDatabaseFound(databaseInstance);
                    }

                    return(result);
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <DatabaseInstanceInfo>(ex));
            }
        }
Пример #4
0
 /// <summary>
 /// Default constructor to initialize the instance
 /// </summary>
 /// <param name="serverInstanceInfo"></param>
 public DatabaseInstanceInfo(ServerInstanceInfo serverInstanceInfo)
 {
     ServerInstanceInfo = serverInstanceInfo;
 }