Example #1
0
        private static void Run(string poolName)
        {
            try
            {
                var serverManager = new ServerManager();
                ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
                ApplicationPool           arnTestApplicationPool    = null;

                foreach (ApplicationPool applicationPool in applicationPoolCollection)
                {
                    if (string.Compare(applicationPool.Name, poolName, true) == 0)
                    {
                        arnTestApplicationPool = applicationPool;
                        break;
                    }
                }

                if (arnTestApplicationPool != null)
                {
                    if (arnTestApplicationPool.State == ObjectState.Stopped)
                    {
                        arnTestApplicationPool.Start();
                    }
                    else
                    {
                        arnTestApplicationPool.Recycle();
                    }
                }
            }
            catch (ServerManagerException ex)
            {
                Console.WriteLine(ex);
            }
        }
Example #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);
            }
        }
Example #3
0
        public static void GetApplicationPoolsAssociatedWithServer()
        {
            ServerManager server = new ServerManager();

            ApplicationPoolCollection applicationPools = server.ApplicationPools;

            foreach (ApplicationPool pool in applicationPools)
            {
                //get the AutoStart boolean value
                bool autoStart = pool.AutoStart;

                //get the name of the ManagedRuntimeVersion
                string runtime = pool.ManagedRuntimeVersion;

                //get the name of the ApplicationPool
                string appPoolName = pool.Name;

                //get the identity type
                ProcessModelIdentityType identityType = pool.ProcessModel.IdentityType;

                //get the username for the identity under which the pool runs
                string userName = pool.ProcessModel.UserName;

                //get the password for the identity under which the pool runs
                string password = pool.ProcessModel.Password;
            }
        }
        public void ApplicationPoolList()
        {
            ServerManager               serverManager               = new ServerManager();
            ApplicationPoolCollection   applicationPoolCollection   = serverManager.ApplicationPools;
            ApplicationPoolProcessModel applicationPoolProcessModel = null;

            _logger.InfoFormat("[{0}] - =======================================================================================", MethodInfo.GetCurrentMethod().Name);
            _logger.InfoFormat("[{0}] - Begin ApplicationPoolCollection", MethodInfo.GetCurrentMethod().Name);
            foreach (ApplicationPool itemApplicationPool in applicationPoolCollection)
            {
                _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                _logger.InfoFormat("[{0}] - itemApplicationPool.Name: {1}", MethodInfo.GetCurrentMethod().Name, itemApplicationPool.Name);
                _logger.InfoFormat("[{0}] - itemApplicationPool.AutoStart: {1}", MethodInfo.GetCurrentMethod().Name, itemApplicationPool.AutoStart);
                _logger.InfoFormat("[{0}] - itemApplicationPool.Enable32BitAppOnWin64: {1}", MethodInfo.GetCurrentMethod().Name, itemApplicationPool.Enable32BitAppOnWin64);
                _logger.InfoFormat("[{0}] - itemApplicationPool.ManagedRuntimeVersion: {1}", MethodInfo.GetCurrentMethod().Name, itemApplicationPool.ManagedRuntimeVersion);
                _logger.InfoFormat("[{0}] - itemApplicationPool.State: {1}", MethodInfo.GetCurrentMethod().Name, (int)itemApplicationPool.State);
                _logger.InfoFormat("[{0}] - itemApplicationPool.State[string]: {1}", MethodInfo.GetCurrentMethod().Name, itemApplicationPool.State);

                applicationPoolProcessModel = itemApplicationPool.ProcessModel;
                _logger.InfoFormat("[{0}] - applicationPoolProcessModel.IdentityType: {1}", MethodInfo.GetCurrentMethod().Name, (int)applicationPoolProcessModel.IdentityType);
                _logger.InfoFormat("[{0}] - applicationPoolProcessModel.IdentityType[string]: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.IdentityType);
                _logger.InfoFormat("[{0}] - applicationPoolProcessModel.UserName: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.UserName);
                _logger.InfoFormat("[{0}] - applicationPoolProcessModel.Password: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.Password);
                _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
            }
            _logger.InfoFormat("[{0}] - End ApplicationPoolCollection", MethodInfo.GetCurrentMethod().Name);
            _logger.InfoFormat("[{0}] - =======================================================================================", MethodInfo.GetCurrentMethod().Name);
        }
        internal static bool CreateOrUpdateApplicationPool(ServerManager serverManager, string appPoolName, string clrConfigFilePath, out bool isAppPoolNew)
        {
            bool flag = false;

            isAppPoolNew = false;
            ApplicationPoolCollection      applicationPools = serverManager.ApplicationPools;
            ConfigurationElementCollection collection       = applicationPools.GetCollection();

            if (IISConfigurationUtilities.FindElement(collection, "add", "name", appPoolName) == null)
            {
                flag         = true;
                isAppPoolNew = true;
                applicationPools.Add(appPoolName);
            }
            ApplicationPool applicationPool = applicationPools[appPoolName];

            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "autostart", true);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "managedPipelineMode", "Integrated");
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "managedRuntimeVersion", "v4.0");
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "queueLength", 65535);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.Failure, "rapidFailProtection", false);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "identityType", "LocalSystem");
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "loadUserProfile", true);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "idleTimeout", TimeSpan.FromSeconds(0.0));
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "pingingEnabled", false);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "shutdownTimeLimit", TimeSpan.FromSeconds(5.0));
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.Recycling, "disallowOverlappingRotation", true);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.Recycling.PeriodicRestart, "time", TimeSpan.FromSeconds(0.0));
            if (!string.IsNullOrEmpty(clrConfigFilePath))
            {
                flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "CLRConfigFile", clrConfigFilePath);
                flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "managedRuntimeLoader", string.Empty);
            }
            return(flag);
        }
        public static string CheckApplicationPools(XmlNode _AppPools, string bodyAppPool)
        {
            int                       i                         = 0;
            ServerManager             serverManager             = new ServerManager();
            ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

            if (applicationPoolCollection != null)
            {
                foreach (XmlNode _AppPool in _AppPools)
                {
                    foreach (ApplicationPool applicationPool in applicationPoolCollection)
                    {
                        if (_AppPool.InnerText.Equals(applicationPool.Name))
                        {
                            i++;
                            if (!(applicationPool.State == ObjectState.Started))
                            {
                                bodyAppPool = bodyAppPool + "\r\n" + applicationPool.Name + ": " + Convert.ToString(applicationPool.State);
                            }
                            break;
                        }
                    }
                }
            }
            if (i == 0)
            {
                bodyAppPool = "\r\n Ниодин Application Pool не найден";
            }
            return(bodyAppPool);
        }
        public void GetApplicationPoolDetail(ApplicationPoolCollection applicationPoolCollection, string applicationPoolName)
        {
            ApplicationPoolProcessModel applicationPoolProcessModel = null;
            ApplicationPool             applicationPool             = null;

            if ((applicationPoolCollection != null) && (applicationPoolCollection.Any()))
            {
                _logger.InfoFormat("[{0}] - applicationPoolName: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolName);

                applicationPool = applicationPoolCollection.FirstOrDefault(p => p.Name == applicationPoolName);
                if (applicationPool != null)
                {
                    _logger.InfoFormat("[{0}] - applicationPool.Name: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.Name);
                    _logger.InfoFormat("[{0}] - applicationPool.AutoStart: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.AutoStart);
                    _logger.InfoFormat("[{0}] - applicationPool.Enable32BitAppOnWin64: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.Enable32BitAppOnWin64);
                    _logger.InfoFormat("[{0}] - applicationPool.ManagedRuntimeVersion: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.ManagedRuntimeVersion);
                    _logger.InfoFormat("[{0}] - applicationPool.State: {1}", MethodInfo.GetCurrentMethod().Name, (int)applicationPool.State);
                    _logger.InfoFormat("[{0}] - applicationPool.State[string]: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.State);

                    applicationPoolProcessModel = applicationPool.ProcessModel;
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.IdentityType: {1}", MethodInfo.GetCurrentMethod().Name, (int)applicationPoolProcessModel.IdentityType);
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.IdentityType[string]: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.IdentityType);
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.UserName: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.UserName);
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.Password: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.Password);
                }
                else
                {
                    _logger.InfoFormat("[{0}] - ApplicationPool doesn't exists", MethodInfo.GetCurrentMethod().Name);
                }
            }
            else
            {
                _logger.InfoFormat("[{0}] - Server doesn't have any ApplicationPool", MethodInfo.GetCurrentMethod().Name);
            }
        }
Example #8
0
        private void RefreshAppPool(object sender, FileSystemEventArgs e)
        {
            if (e.Name.EndsWith(".dll"))   //yes, i know i can use filters, but dfs sucks and causes them not to work correctly
            {
                if (_connectionString != null)
                {
                    using (LegionLinqDataContext db = new LegionLinqDataContext(_connectionString)) {
                        db.xspSetAssemblyRefreshFlags();
                    }
                }

                string msg = string.Format("'{0}' modified", e.Name);
                Email(msg);
                eventLog.WriteEntry(msg);

                ServerManager             serverManager             = new ServerManager();
                ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
                foreach (ApplicationPool applicationPool in applicationPoolCollection)
                {
                    if (applicationPool.Name == _poolName)
                    {
                        applicationPool.Recycle();
                        break;
                    }
                }
                serverManager.CommitChanges();
            }
        }
        private void StartOrStopAppPool(string appPoolName, bool start)
        {
            string action = start ? "Starting" : "Stopping";

            TestUtility.LogTrace(String.Format("#################### {0} app pool {1} ####################", action, appPoolName));

            try
            {
                using (ServerManager serverManager = GetServerManager())
                {
                    ApplicationPoolCollection appPools = serverManager.ApplicationPools;
                    if (start)
                    {
                        appPools[appPoolName].Start();
                    }
                    else
                    {
                        appPools[appPoolName].Stop();
                    }

                    serverManager.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                TestUtility.LogInformation(String.Format("#################### {0} app pool {1} failed. Reason: {2} ####################", action, appPoolName, ex.Message));
            }
        }
        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);
            }
        }
 public ApplicationPoolsTreeNode(IServiceProvider serviceProvider, ApplicationPoolCollection pools)
     : base("Application Pools", serviceProvider)
 {
     ImageIndex         = 2;
     SelectedImageIndex = 2;
     Tag           = pools;
     ServerManager = pools.Parent;
 }
Example #12
0
        public static ServerManager GetServerManager(string server, out ApplicationPoolCollection applicationPools, out SiteCollection sites)
        {
            ServerManager serverManager = ServerManager.OpenRemote(server);

            applicationPools = serverManager.ApplicationPools;
            sites            = serverManager.Sites;
            return(serverManager);
        }
Example #13
0
        private string EnsureValidAppPoolName(ApplicationPoolCollection appPools, string appPoolName)
        {
            if (appPools.Any(appPool => appPool.Name.Equals(appPoolName)))
            {
                appPoolName += $"_{GetRandomString(10)}";
            }

            return(appPoolName);
        }
Example #14
0
        public static ApplicationPool AddNewWithDefaults(this ApplicationPoolCollection applicationPools)
        {
            string          defaultName     = string.Format("ApplicationPool{0}", applicationPools.Count + 1);
            ApplicationPool applicationPool = applicationPools.Add(defaultName);

            applicationPool.ManagedRuntimeVersion = "v4.0";

            return(applicationPool);
        }
        protected override void DoExecute(IScriptExecutionEnvironment environment)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

                ApplicationPool appPoolToWorkOn = null;
                bool            updatedExisting = false;

                foreach (ApplicationPool applicationPool in applicationPoolCollection)
                {
                    if (applicationPool.Name == applicationPoolName)
                    {
                        if (mode == CreateApplicationPoolMode.DoNothingIfExists)
                        {
                            environment.LogMessage(
                                String.Format(
                                    System.Globalization.CultureInfo.InvariantCulture,
                                    "Application pool '{0}' already exists, doing nothing.",
                                    applicationPoolName));
                        }
                        else if (mode == CreateApplicationPoolMode.FailIfAlreadyExists)
                        {
                            throw new RunnerFailedException(
                                      String.Format(
                                          System.Globalization.CultureInfo.InvariantCulture,
                                          "Application '{0}' already exists.",
                                          applicationPoolName));
                        }

                        // otherwise we should update the existing application pool
                        appPoolToWorkOn = applicationPool;
                        updatedExisting = true;
                        break;
                    }
                }

                if (appPoolToWorkOn == null)
                {
                    appPoolToWorkOn = serverManager.ApplicationPools.Add(applicationPoolName);
                }

                appPoolToWorkOn.AutoStart             = false;
                appPoolToWorkOn.Enable32BitAppOnWin64 = true;
                appPoolToWorkOn.ManagedPipelineMode   =
                    ClassicManagedPipelineMode ? ManagedPipelineMode.Classic : ManagedPipelineMode.Integrated;
                //serverManager.ApplicationPools.Add(appPoolToWorkOn);
                serverManager.CommitChanges();

                environment.LogMessage(
                    String.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "Application pool '{0}' {1}.",
                        applicationPoolName,
                        updatedExisting ? "updated" : "created"));
            }
        }
Example #16
0
        // POPULATE APP POOLS CHECKLIST__________________________________________________________________________

        private void PopulateAppPoolList()
        {
            ApplicationPoolCollection applicationPools = server.ApplicationPools;

            foreach (ApplicationPool pool in applicationPools)
            {
                string appPoolName = pool.Name;
                checkedListBox2.Items.Add(appPoolName);
            }
        }
Example #17
0
        public static List <string> GetAppPools()
        {
            List <string>             appPoolsList  = new List <string>();
            ServerManager             serverManager = new ServerManager();
            ApplicationPoolCollection sites         = serverManager.ApplicationPools;

            foreach (var item in sites)
            {
                appPoolsList.Add(item.Name);
            }
            return(appPoolsList);
        }
        protected override void DoExecute(IScriptExecutionEnvironment environment)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

                foreach (ApplicationPool applicationPool in applicationPoolCollection)
                {
                    if (applicationPool.Name == ApplicationPoolName)
                    {
                        switch (action)
                        {
                        case ControlApplicationPoolAction.Start:
                            RunWithRetries(x => applicationPool.Start(), 3);
                            break;

                        case ControlApplicationPoolAction.Stop:
                            RunWithRetries(x => applicationPool.Stop(), 3);
                            break;

                        case ControlApplicationPoolAction.Recycle:
                            RunWithRetries(x => applicationPool.Recycle(), 3);
                            break;

                        default:
                            throw new NotSupportedException();
                        }

                        serverManager.CommitChanges();

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

                        return;
                    }
                }

                string message = String.Format(
                    System.Globalization.CultureInfo.InvariantCulture,
                    "Application pool '{0}' does not exist.",
                    applicationPoolName);

                if (failIfNotExist)
                {
                    throw new RunnerFailedException(message);
                }

                environment.LogMessage(message);
            }
        }
Example #19
0
        static void Main(string[] args)
        {
            //新建应用程序池
            ServerManager             mgr   = new ServerManager();
            ApplicationPoolCollection pools = mgr.ApplicationPools;

            for (int i = 0; i < NUMBEROFPOOLS; i++)
            {
                CreateAppPool(pools, i + APPPOOLBASENUMBER, POOLPREFIX, USERNAMEPREFIX, PASSWORDPREFIX, ENCRYPTPASSWORD);
            }
            mgr.CommitChanges();
        }
Example #20
0
        private static bool SiteExists(string siteName, bool deleteSiteIfExists)
        {
            Log.Logger.Verbose("Checking if site {siteName} exists", siteName);
            bool exists = false;

            using (ServerManager iisManager = new ServerManager())
            {
                var sites = iisManager.Sites;

                foreach (Site site in sites)
                {
                    if (site.Name == siteName.ToString())
                    {
                        exists = true;
                        Log.Logger.Verbose("Site {siteName} exists", siteName);
                        if (deleteSiteIfExists)
                        {
                            Log.Logger.Verbose("The user requested for the existing site {siteName} to be deleted", siteName);
                            if (site.ApplicationDefaults.ApplicationPoolName == siteName + "_nvQuickSite")
                            {
                                ApplicationPoolCollection appPools = iisManager.ApplicationPools;
                                foreach (ApplicationPool appPool in appPools)
                                {
                                    if (appPool.Name == siteName + "_nvQuickSite")
                                    {
                                        iisManager.ApplicationPools.Remove(appPool);
                                        break;
                                    }
                                }
                            }

                            iisManager.Sites.Remove(site);
                            iisManager.CommitChanges();
                            Log.Logger.Information("Site {siteName} was deleted", siteName);
                            exists = false;
                            break;
                        }

                        break;
                    }
                    else
                    {
                        exists = false;
                    }
                }
            }

            return(exists);
        }
        private static string ChooseAppPoolName([NotNull] string name, [NotNull] ApplicationPoolCollection applicationPools)
        {
            Assert.ArgumentNotNull(name, "name");
            Assert.ArgumentNotNull(applicationPools, "applicationPools");

            int    modifier = 0;
            string newname  = name;

            while (applicationPools[newname] != null)
            {
                newname = name + '_' + ++modifier;
            }

            return(newname);
        }
        public void DeleteAllAppPools(bool commitDelay = false)
        {
            TestUtility.LogTrace(String.Format("#################### Deleting all app pools ####################"));

            using (ServerManager serverManager = GetServerManager())
            {
                ApplicationPoolCollection appPools = serverManager.ApplicationPools;
                while (appPools.Count > 0)
                {
                    appPools.RemoveAt(0);
                }

                serverManager.CommitChanges();
            }
        }
Example #23
0
        public static void Main()
        {
            string computerName = "jhkim-test";

            ServiceController[] services = ServiceController.GetServices(computerName);
            Console.WriteLine(services.Length);

            using (ServerManager serverManager = new ServerManager($@"\\{computerName}\c$\windows\system32\inetsrv\config\applicationHost.config"))
            {
                ApplicationPoolCollection appPool = serverManager.ApplicationPools;
                Console.WriteLine(appPool.Count);
            }

            Console.ReadKey();
        }
        public static string ChooseAppPoolName([NotNull] string name, [NotNull] ApplicationPoolCollection applicationPools)
        {
            Assert.ArgumentNotNull(name, nameof(name));
            Assert.ArgumentNotNull(applicationPools, nameof(applicationPools));

            var modifier = 0;
            var newname  = name;

            while (applicationPools[newname] != null)
            {
                newname = name + '_' + ++modifier;
            }

            return(newname);
        }
Example #25
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();
            }
        }
Example #27
0
 protected void ResetCache_Click(object sender, EventArgs e)
 {
     try
     {
         ServerManager             serverManager = new ServerManager();
         ApplicationPoolCollection appPools      = serverManager.ApplicationPools;
         foreach (ApplicationPool ap in appPools)
         {
             ap.Recycle();
         }
         divAnnounce.InnerText = "Success";
     }
     catch (Exception ex)
     {
         divAnnounce.InnerText = ex.ToString();
     }
 }
Example #28
0
        public static void RemoteRecycle()
        {
            ServerManager             manager  = ServerManager.OpenRemote("184.12.15.157");
            ApplicationPoolCollection appPools = manager.ApplicationPools;

            foreach (var ap in appPools)
            {
                ap.Recycle();
            }

            /*
             * 回收注意事项:
             *  1.需要添加引用 C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll ,然后using Microsoft.Web.Administration;
             *  2.远程账号需要有管理员权限;
             *  3.远程主机的账号密码添加在服务器的凭据管理器中 (控制面板->凭据管理器) ,能成功使用mstsc 登录即可;
             *  4.远程主机需要关闭UAC!! 因为这个问题卡了好几个礼拜才无意发现。
             */
        }
        public void SetIdleTimeoutForAppPool(string appPoolName, int idleTimeoutMinutes)
        {
            TestUtility.LogTrace(String.Format("#################### Setting idleTimeout to {0} minutes for AppPool {1} ####################", idleTimeoutMinutes, appPoolName));
            try
            {
                using (ServerManager serverManager = GetServerManager())
                {
                    ApplicationPoolCollection appPools = serverManager.ApplicationPools;
                    appPools[appPoolName].ProcessModel.IdleTimeout = TimeSpan.FromMinutes(idleTimeoutMinutes);

                    serverManager.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                TestUtility.LogInformation(String.Format("#################### Setting idleTimeout to {0} minutes for AppPool {1} failed. Reason: {2} ####################", idleTimeoutMinutes, appPoolName, ex.Message));
            }
        }
        public void SetMaxProcessesForAppPool(string appPoolName, int maxProcesses)
        {
            TestUtility.LogTrace(String.Format("#################### Setting maxProcesses to {0} for AppPool {1} ####################", maxProcesses, appPoolName));
            try
            {
                using (ServerManager serverManager = GetServerManager())
                {
                    ApplicationPoolCollection appPools = serverManager.ApplicationPools;
                    appPools[appPoolName].ProcessModel.MaxProcesses = maxProcesses;

                    serverManager.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                TestUtility.LogInformation(String.Format("#################### Setting maxProcesses to {0} for AppPool {1} failed. Reason: {2} ####################", maxProcesses, appPoolName, ex.Message));
            }
        }
Example #31
0
 private static bool CreateAppPool(ApplicationPoolCollection pools, AppPoolDTO dto)
 {
     try
     {
         var newPool = pools.Add(dto.PoolID);
         newPool.ProcessModel.UserName = dto.UserName;
         if (!dto.EncryptPassword)
         {
             newPool.ProcessModel.Attributes["password"].SetMetadata("encryptProvider", "");
         }
         newPool.ProcessModel.Password = dto.Password;
         newPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
         newPool.ManagedPipelineMode = dto.ManagedPipelineMode;
         newPool.ManagedRuntimeVersion = dto.RunTimeVersion == RunTimeVersion.V2 ? "v2.0" : dto.RunTimeVersion == RunTimeVersion.V4 ? "v4.0" : "";
     }
     catch (Exception ex)
     {
         Console.WriteLine("Adding AppPool {0} failed. Reason: {1}", dto.PoolID, ex.Message);
         return false;
     }
     return true;
 }
        private void Initialize()
        {
            if (this.Initialized)
            {
                return;
            }

            this.Initialized = true;
            PreInitialize();
            var machineConfig = Helper.IsRunningOnMono()
                ? "/Library/Frameworks/Mono.framework/Versions/Current/etc/mono/4.5/machine.config"
                : Path.Combine(
                                    Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                                    "Microsoft.NET",
                                    IntPtr.Size == 2 ? "Framework" : "Framework64",
                                    "v4.0.30319",
                                    "config",
                                    "machine.config");
            var machine =
                new Configuration(
                    new FileContext(
                        this,
                        machineConfig,
                        null,
                        null,
                        false,
                        true,
                        true));
            var webConfig = Helper.IsRunningOnMono()
                ? "/Library/Frameworks/Mono.framework/Versions/Current/etc/mono/4.5/web.config"
                : Path.Combine(
                                Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                                "Microsoft.NET",
                                IntPtr.Size == 2 ? "Framework" : "Framework64",
                                "v4.0.30319",
                                "config",
                                "web.config");
            var web =
                new Configuration(
                    new FileContext(
                        this,
                        webConfig,
                        machine.FileContext,
                        null,
                        false,
                        true,
                        true));

            _applicationHost =
                new Configuration(
                new FileContext(this, this.FileName, web.FileContext, null, true, false, this.ReadOnly));

            this.LoadCache();

            var poolSection = _applicationHost.GetSection("system.applicationHost/applicationPools");
            _applicationPoolDefaults =
                new ApplicationPoolDefaults(poolSection.GetChildElement("applicationPoolDefaults"), poolSection);
            this.ApplicationPoolCollection = new ApplicationPoolCollection(poolSection, this);
            var siteSection = _applicationHost.GetSection("system.applicationHost/sites");
            _siteDefaults = new SiteDefaults(siteSection.GetChildElement("siteDefaults"), siteSection);
            _applicationDefaults = new ApplicationDefaults(
                siteSection.GetChildElement("applicationDefaults"),
                siteSection);
            _virtualDirectoryDefaults =
                new VirtualDirectoryDefaults(siteSection.GetChildElement("virtualDirectoryDefaults"), siteSection);
            this.SiteCollection = new SiteCollection(siteSection, this);

            PostInitialize();
        }
 internal ApplicationPool(ConfigurationElement element, ApplicationPoolCollection parent)
     : base(element, "add", null, parent, null, null)
 {
     Parent = parent;
 }