protected override int DoExecute(ITaskContextInternal context)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

                foreach (ApplicationPool applicationPool in applicationPoolCollection)
                {
                    if (applicationPool.Name == _appPoolName)
                    {
                        applicationPoolCollection.Remove(applicationPool);
                        serverManager.CommitChanges();

                        DoLogInfo($"Application pool '{_appPoolName}' has been deleted.");

                        return(0);
                    }
                }

                if (_failIfNotExist)
                {
                    throw new TaskExecutionException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Application '{0}' does not exist.",
                                  _appPoolName), 1);
                }

                DoLogInfo($"Application pool '{_appPoolName}' does not exist, doing nothing.");
                return(0);
            }
        }
Beispiel #2
0
        protected override void DoExecute(ITaskContext context)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

                foreach (ApplicationPool applicationPool in applicationPoolCollection)
                {
                    if (applicationPool.Name == ApplicationPoolName)
                    {
                        applicationPoolCollection.Remove(applicationPool);
                        serverManager.CommitChanges();

                        context.WriteInfo(
                            "Application pool '{0}' has been deleted.",
                            ApplicationPoolName);

                        return;
                    }
                }

                if (FailIfNotExist)
                {
                    throw new TaskExecutionException(
                              String.Format(
                                  CultureInfo.InvariantCulture,
                                  "Application '{0}' does not exist.",
                                  ApplicationPoolName));
                }

                context.WriteInfo(
                    "Application pool '{0}' does not exist, doing nothing.",
                    ApplicationPoolName);
            }
        }
Beispiel #3
0
        public static bool DeleteAppPool(string serverName, string appPoolName, out string message)
        {
            try
            {
                if (String.IsNullOrEmpty(appPoolName))
                {
                    message = "DeleteApplicationPool: applicationPoolName is null or empty.";
                    return(false);
                }

                using (ServerManager mgr = ServerManager.OpenRemote(serverName))
                {
                    ApplicationPool appPool = mgr.ApplicationPools[appPoolName];
                    if (appPool == null)
                    {
                        message = "Failed to find application pool.";
                        return(false);
                    }
                    StringBuilder sbAppNames = new StringBuilder();
                    foreach (Site site in mgr.Sites)
                    {
                        foreach (Application app in site.Applications)
                        {
                            if (app.ApplicationPoolName.ToString() == appPoolName)
                            {
                                sbAppNames.AppendLine(app.Path);
                            }
                        }
                    }
                    if (sbAppNames.Length > 0)
                    {
                        message = string.Format("Can not delete application pool as one or more applications are associated with it.\r\n{0}Please change application pools for these applications before deleting.", sbAppNames.ToString());
                        return(false);
                    }
                    ApplicationPoolCollection appColl = mgr.ApplicationPools;
                    appColl.Remove(appPool);
                    mgr.CommitChanges();

                    message = string.Format("Application pool: {0}, successfully deleted.", appPoolName);
                }
                return(true);
            }
            catch (Exception ex)
            {
                message = String.Format("DeleteApplicationPool Error :: {0} ", ex.Message);
                return(false);
            }
        }
        public static void DeleteApplicationPool(String applicationPoolName, bool RemoveSite)
        {
            if (RemoveSite)
            {
                if (string.IsNullOrEmpty(applicationPoolName))
                {
                    throw new ArgumentNullException("applicationPoolName", "DeleteApplicationPool: applicationPoolName is null or empty.");
                }

                ServerManager             iisManager  = new ServerManager();
                ApplicationPool           AppPool     = iisManager.ApplicationPools[applicationPoolName];
                ApplicationPoolCollection AppPoolColl = iisManager.ApplicationPools;
                AppPoolColl.Remove(AppPool);
                iisManager.CommitChanges();
            }
        }
        public void DeleteAppPool(string poolName)
        {
            try
            {
                using (ServerManager serverManager = GetServerManager())
                {
                    TestUtility.LogTrace(String.Format("#################### Deleting App Pool {0} ####################", poolName));

                    ApplicationPoolCollection appPools = serverManager.ApplicationPools;
                    appPools.Remove(appPools[poolName]);

                    serverManager.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                TestUtility.LogInformation(String.Format("#################### Delete app pool {0} failed. Reason: {1} ####################", poolName, ex.Message));
            }
        }
        protected override void DoExecute(IScriptExecutionEnvironment environment)
        {
            ServerManager             serverManager             = new ServerManager();
            ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

            foreach (ApplicationPool applicationPool in applicationPoolCollection)
            {
                if (applicationPool.Name == ApplicationPoolName)
                {
                    applicationPoolCollection.Remove(applicationPool);
                    serverManager.CommitChanges();

                    environment.LogMessage(
                        String.Format(
                            System.Globalization.CultureInfo.InvariantCulture,
                            "Application pool '{0}' has been deleted.",
                            ApplicationPoolName));

                    return;
                }
            }

            if (FailIfNotExist)
            {
                throw new RunnerFailedException(
                          String.Format(
                              CultureInfo.InvariantCulture,
                              "Application '{0}' does not exist.",
                              ApplicationPoolName));
            }

            environment.LogMessage(
                String.Format(
                    CultureInfo.InvariantCulture,
                    "Application pool '{0}' does not exist, doing nothing.",
                    ApplicationPoolName));
        }