Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        private void CleanupContainers(AzureResourceType type, Dictionary <string, object> resources)
        {
            SafeExecute(() =>
            {
                foreach (var c in resources.Values)
                {
                    var container = c as CloudBlobContainer;
                    if (container == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    container.DeleteIfExists();
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 3
0
        private void CleanupBlobs(AzureResourceType type, Dictionary <string, object> resources)
        {
            SafeExecute(() =>
            {
                foreach (var b in resources.Values)
                {
                    var blob = b as CloudBlockBlob;
                    if (blob == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    blob.DeleteIfExists();
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 4
0
        private void CleanupWebSites(AzureResourceType type, Dictionary <string, object> resources)
        {
            SafeExecute(() =>
            {
                var manager = new AzureWebSiteManager();
                foreach (var obj in resources.Values)
                {
                    var site = obj as WAML.WebSites.Models.WebSite;
                    if (site == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    if (manager.WebSiteExists(site.Name))
                    {
                        manager.DeleteWebSite(site.Name);
                    }
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 5
0
        private void CleanupHostedServices(AzureResourceType type, Dictionary <string, object> resources)
        {
            SafeExecute(() =>
            {
                var manager = new AzureCloudServiceManager();
                foreach (var obj in resources.Values)
                {
                    var service = obj as string;
                    if (service == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    if (manager.GetHostedService(service) != null)
                    {
                        manager.DeleteHostedService(service);
                    }
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 6
0
        private void CleanupDeployments(AzureResourceType type, Dictionary <string, object> resources)
        {
            SafeExecute(() =>
            {
                var manager = new AzureCloudServiceManager();
                foreach (var obj in resources.Values)
                {
                    var deployment = obj as DeploymentInfo;
                    if (deployment == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    if (manager.GetDeployment(deployment.HostedService, deployment.Deployment.Name) != null)
                    {
                        manager.DeleteDeployment(deployment.HostedService, deployment.Deployment.Name);
                    }
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 7
0
        private void CleanupAffinityGroups(AzureResourceType type, Dictionary <string, object> resources)
        {
            SafeExecute(() =>
            {
                var manager = new AzureAffinityGroupManager();
                foreach (var obj in resources.Values)
                {
                    var group = obj as string;
                    if (group == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    if (manager.GetAffinityGroup(group) != null)
                    {
                        manager.DeleteAffinityGroup(group);
                    }
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        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());
        }
Exemplo n.º 11
0
        private void CleanupWebSites(AzureResourceType type, Dictionary<string, object> resources)
        {
            SafeExecute(() =>
                {
                    var manager = new AzureWebSiteManager();
                    foreach (var obj in resources.Values)
                    {
                        var site = obj as WAML.WebSites.Models.WebSite;
                        if (site == null)
                        {
                            throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                        }

                        if(manager.WebSiteExists(site.Name))
                        {
                            manager.DeleteWebSite(site.Name);
                        }
                    }

                    resources.Clear();
                }, type.ToString());
        }
Exemplo n.º 12
0
        private void CleanupHostedServices(AzureResourceType type, Dictionary<string, object> resources)
        {
            SafeExecute(() =>
            {
                var manager = new AzureCloudServiceManager();
                foreach (var obj in resources.Values)
                {
                    var service = obj as string;
                    if (service == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    if (manager.GetHostedService(service) != null)
                    {
                        manager.DeleteHostedService(service);
                    }
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 13
0
        private void CleanupDeployments(AzureResourceType type, Dictionary<string, object> resources)
        {
            SafeExecute(() =>
            {
                var manager = new AzureCloudServiceManager();
                foreach (var obj in resources.Values)
                {
                    var deployment = obj as DeploymentInfo;
                    if (deployment == null)
                    {
                        throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                    }

                    if (manager.GetDeployment(deployment.HostedService, deployment.Deployment.Name) != null)
                    {
                        manager.DeleteDeployment(deployment.HostedService, deployment.Deployment.Name);
                    }
                }

                resources.Clear();
            }, type.ToString());
        }
Exemplo n.º 14
0
        private void CleanupAffinityGroups(AzureResourceType type, Dictionary<string, object> resources)
        {
            SafeExecute(() =>
                {
                    var manager = new AzureAffinityGroupManager();
                    foreach (var obj in resources.Values)
                    {
                        var group = obj as string;
                        if (group == null)
                        {
                            throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                        }

                        if(manager.GetAffinityGroup(group) != null)
                        {
                            manager.DeleteAffinityGroup(group);
                        }
                    }

                    resources.Clear();
                }, type.ToString());
        }
Exemplo n.º 15
0
        private void CleanupContainers(AzureResourceType type, Dictionary<string, object> resources)
        {
            SafeExecute(() =>
                {
                    foreach (var c in resources.Values)
                    {
                        var container = c as CloudBlobContainer;
                        if (container == null)
                        {
                            throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                        }

                        container.DeleteIfExists();
                    }

                    resources.Clear();
                }, type.ToString());
        }
Exemplo n.º 16
0
        private void CleanupBlobs(AzureResourceType type, Dictionary<string, object> resources)
        {
            SafeExecute(() =>
                {
                    foreach (var b in resources.Values)
                    {
                        var blob = b as CloudBlockBlob;
                        if (blob == null)
                        {
                            throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type));
                        }

                        blob.DeleteIfExists();
                    }

                    resources.Clear();
                }, type.ToString());
        }