private void CleanupDatabaseServers(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var server = obj as SqlAzureServer; if (server == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(server.Name, server.User, server.Password) != null) { var databases = server.GetDatabases(); // if after we deleted our databases there are still more than one (master) database, // it means some one reuses this server, so don't delete it if (databases.Count() <= 1) { manager.DeleteSqlServer(server.Name); } } } resources.Clear(); }, type.ToString()); }
private void CleanupDatabases(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var database = obj as SqlAzureDatabase; if (database == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(database.Server.Name, database.Server.User, database.Server.Password) != null && database.Server.DatabaseExists(database.Name)) { database.Server.DropDatabase(database.Name); } } resources.Clear(); }, type.ToString()); }
private void CleanupDatabaseServers(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var server = obj as SqlAzureServer; if (server == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(server.Name, server.User, server.Password) != null) { var databases = server.GetDatabases(); // if after we deleted our databases there are still more than one (master) database, // it means some one reuses this server, so don't delete it if (databases.Count() <= 1) { manager.DeleteSqlServer(server.Name); } } } resources.Clear(); }, type.ToString()); }
private void CleanupDatabases(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var database = obj as SqlAzureDatabase; if (database == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(database.Server.Name, database.Server.User, database.Server.Password) != null && database.Server.DatabaseExists(database.Name)) { database.Server.DropDatabase(database.Name); } } resources.Clear(); }, type.ToString()); }