コード例 #1
0
        private static HaISqlServerModel LoadSqlServerCoreProperties(IAzure azure, ISqlServer sqlServer)
        {
            var myObject = new HaISqlServerModel();

            string myId = sqlServer.Id;

            //Id, Type, Name, ResourceGroupName, SubscriptionId, Region, RegionName, Type

            myObject.Id   = myId;
            myObject.Type = azure.GenericResources.GetById(myId).Type;
            myObject.Name = azure.GenericResources.GetById(myId).Name;
            myObject.ResourceGroupName = azure.GenericResources.GetById(myId).ResourceGroupName;
            myObject.SubscriptionId    = azure.GenericResources.GetById(myId).Id.Split('/')[2];
            myObject.Region            = azure.GenericResources.GetById(myId).Region;
            myObject.RegionName        = azure.GenericResources.GetById(myId).RegionName;
            myObject.Tags = azure.GenericResources.GetById(myId).Tags;

            //Specifics
            myObject.Version = sqlServer.Version;
            myObject.SystemAssignedManagedServiceIdentityPrincipalId = sqlServer.SystemAssignedManagedServiceIdentityPrincipalId;
            myObject.SystemAssignedManagedServiceIdentityTenantId    = sqlServer.SystemAssignedManagedServiceIdentityTenantId;
            myObject.Kind = sqlServer.Kind;
            myObject.FullyQualifiedDomainName        = sqlServer.FullyQualifiedDomainName;
            myObject.IsManagedServiceIdentityEnabled = sqlServer.IsManagedServiceIdentityEnabled;
            myObject.AdministratorLogin = sqlServer.AdministratorLogin;
            myObject.State = sqlServer.State;
            myObject.ManagedServiceIdentityType = sqlServer.ManagedServiceIdentityType;

            return(myObject);
        }
コード例 #2
0
        private static void LoadSqlDatabases(IAzure azure, ISqlServer sqlServer, HaISqlServerModel objSqlServer)
        {
            List <HaISqlDatabase> objSqlDatabase = new List <HaISqlDatabase>();


            foreach (var sqlDatabase in sqlServer.Databases.List())
            {
                string myId = sqlDatabase.Id;

                objSqlDatabase.Add(new HaISqlDatabase()
                {
                    //Generics:
                    //Name, ResourceGroupName, SubscriptionId, Region, RegionName, Type, Id, Tags
                    //Note, not all resources can have their attributes accessed in this manner.
                    Name = azure.GenericResources.GetById(myId).Name,
                    ResourceGroupName = azure.GenericResources.GetById(myId).ResourceGroupName,
                    SubscriptionId    = sqlDatabase.Id.Split('/')[2],
                    Region            = azure.GenericResources.GetById(myId).Region,
                    RegionName        = azure.GenericResources.GetById(myId).RegionName,
                    ParentId          = azure.GenericResources.GetById(myId).ParentResourceId,
                    Type = azure.GenericResources.GetById(myId).Type,
                    Id   = myId,
                    Tags = azure.GenericResources.GetById(sqlDatabase.Id).Tags,

                    //Specifics
                    Collation    = sqlDatabase.Collation,
                    CreationDate = sqlDatabase.CreationDate,
                    CurrentServiceObjectiveId = sqlDatabase.CurrentServiceObjectiveId,
                    DatabaseId = sqlDatabase.DatabaseId,
                    DefaultSecondaryLocation = sqlDatabase.DefaultSecondaryLocation,
                    EarliestRestoreDate      = sqlDatabase.EarliestRestoreDate,
                    Edition                       = sqlDatabase.Edition,
                    ElasticPoolName               = sqlDatabase.ElasticPoolName,
                    IsDataWarehouse               = sqlDatabase.IsDataWarehouse,
                    MaxSizeBytes                  = sqlDatabase.MaxSizeBytes,
                    RequestedServiceObjectiveId   = sqlDatabase.RequestedServiceObjectiveId,
                    RequestedServiceObjectiveName = sqlDatabase.RequestedServiceObjectiveName,
                    ServiceLevelObjective         = sqlDatabase.ServiceLevelObjective,
                    Status        = sqlDatabase.Status,
                    SyncGroups    = sqlDatabase.SyncGroups,
                    SqlServerName = sqlDatabase.SqlServerName
                }
                                   );
            }

            objSqlServer.sqlDatabases = objSqlDatabase;
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //var location = Region.EuropeWest;

            string      json             = File.ReadAllText("azureauth.properties");
            Credentials localCredentials = JsonConvert.DeserializeObject <Credentials>(json);

            HaAzureAutenticationModel autenticationModel = new HaAzureAutenticationModel(localCredentials.clientId, localCredentials.clientSecret, localCredentials.tenantId);
            AzureCredentials          credentials        = HaAzureAuthentication.GetAzCredentials(autenticationModel);
            IAzure azure = HaAzureAuthentication.GetAzManagementClient(credentials);


            String jsonString = null;
            List <HaISqlServerModel> sqlServerModels = new List <HaISqlServerModel>();


            foreach (var sqlServer in azure.SqlServers.List())
            {
                HaISqlServerModel objSqlServer = LoadSqlServerCoreProperties(azure, sqlServer);

                LoadSqlDatabases(azure, sqlServer, objSqlServer);

                //LoadSqlServerKeys(azure, sqlServer, objSqlServer);
                //LoadElasticPools(azure, sqlServer, objSqlServer);
                //LoadDnsAliases(azure, sqlServer, objSqlServer);
                //LoadSqlFailoverGroups(azure, sqlServer, objSqlServer);
                //LoadSqlEncryptionProtectors(azure, sqlServer, objSqlServer);
                //LoadSqlVirtualNetworkRules(azure, sqlServer, objSqlServer);
                //LoadSqlFirewallRules(azure, sqlServer, objSqlServer);

                sqlServerModels.Add(objSqlServer);
            }

            jsonString += JsonConvert.SerializeObject(sqlServerModels, Formatting.Indented);
            Console.WriteLine(jsonString);
        }