Beispiel #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Pool == null)
            {
                Pool = _collection.Add(txtName.Text);
            }
            else
            {
                Pool.Name = txtName.Text;
            }

            if (cbVersion.SelectedIndex == 0)
            {
                Pool.ManagedRuntimeVersion = "v4.0";
            }
            else if (cbVersion.SelectedIndex == 1)
            {
                Pool.ManagedRuntimeVersion = "v2.0";
            }
            else
            {
                Pool.ManagedRuntimeVersion = string.Empty;
            }

            if (_add && _collection.Parent.Mode == WorkingMode.IisExpress)
            {
                Pool["CLRConfigFile"] = @"%IIS_USER_HOME%\config\aspnet.config";
            }

            Pool.AutoStart           = cbStart.Checked;
            Pool.ManagedPipelineMode = (ManagedPipelineMode)cbMode.SelectedIndex;
            DialogResult             = DialogResult.OK;
        }
        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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        static bool CreateAppPool(ApplicationPoolCollection pools, int i, string appPoolPrefix, string userNamePrefix, string passwordPrefix, bool bEncryptPassword)
        {
            try
            {
                ApplicationPool newPool = pools.Add(appPoolPrefix + i);
                newPool.ProcessModel.UserName = userNamePrefix + i;
                // the SetMetadata call will remove the encryptionprovider in the schema. This results in clear-text passwords!!!
                //if (!bEncryptPassword)
                //    newPool.ProcessModel.Attributes["password"].SetMetadata("encryptionProvider", "");

                //newPool.ProcessModel.Password = passwordPrefix + i;
                newPool.ProcessModel.IdentityType = ProcessModelIdentityType.ApplicationPoolIdentity;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Adding AppPool {0} failed. Reason: {1}", appPoolPrefix + i, ex.Message);
                return(false);
            }

            return(true);
        }
Beispiel #5
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;
 }
Beispiel #6
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);
 }
        public ApplicationPoolBasicSettingsDialog(IServiceProvider serviceProvider, ApplicationPool pool, ApplicationPoolDefaults defaults, ApplicationPoolCollection collection)
            : base(serviceProvider)
        {
            InitializeComponent();
            Pool = pool;
            var add = pool == null;

            if (pool == null)
            {
                Text                 = "Add Application Pool";
                cbStart.Checked      = defaults.AutoStart;
                cbMode.SelectedIndex = (int)defaults.ManagedPipelineMode;
                SetRuntimeVersion(defaults.ManagedRuntimeVersion);
            }
            else
            {
                Text                 = "Edit Application Pool";
                txtName.Text         = pool.Name;
                txtName.Enabled      = false;
                cbStart.Checked      = pool.AutoStart;
                cbMode.SelectedIndex = (int)pool.ManagedPipelineMode;
                SetRuntimeVersion(Pool.ManagedRuntimeVersion);
            }

            var container = new CompositeDisposable();

            FormClosed += (sender, args) => container.Dispose();

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                if (Pool == null)
                {
                    if (collection.Any(item => item.Name == txtName.Text))
                    {
                        ShowMessage("An application pool with this name already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        txtName.Focus();
                        return;
                    }

                    Pool = collection.Add(txtName.Text);
                }
                else
                {
                    Pool.Name = txtName.Text;
                }

                if (cbVersion.SelectedIndex == 0)
                {
                    Pool.ManagedRuntimeVersion = "v4.0";
                }
                else if (cbVersion.SelectedIndex == 1)
                {
                    Pool.ManagedRuntimeVersion = "v2.0";
                }
                else
                {
                    Pool.ManagedRuntimeVersion = string.Empty;
                }

                if (add && collection.Parent.Mode == WorkingMode.IisExpress)
                {
                    Pool["CLRConfigFile"] = @"%IIS_USER_HOME%\config\aspnet.config";
                }

                Pool.AutoStart           = cbStart.Checked;
                Pool.ManagedPipelineMode = (ManagedPipelineMode)cbMode.SelectedIndex;
                DialogResult             = DialogResult.OK;
            }));
        }
Beispiel #8
0
        public void ConfigureApplicationSite(ApplicationSiteModel applicationSite = null)
        {
            if (applicationSite == null)
            {
                applicationSite = ApplicationSiteParseConfig(applicationSiteFilePath);
            }

            if (applicationSite != null)
            {
                try {
                    if (!Directory.Exists(applicationSite.PhysicalPath.Destination))
                    {
                        _logger.InfoFormat("[{0}] - ApplicationSite PhysicalPath Destination doesn't exists, failed to copy, can't create ApplicationSite", MethodInfo.GetCurrentMethod().Name);
                        _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);

                        return;
                    }

                    string applicationName = applicationSite.ApplicationName;

                    ServerManager             serverManager             = new ServerManager();
                    SiteCollection            siteCollection            = serverManager.Sites;
                    ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

                    ApplicationPool applicationPool = applicationPoolCollection.Add(applicationName);

                    if (applicationPool != null)
                    {
                        applicationPool.AutoStart                 = true;
                        applicationPool.Enable32BitAppOnWin64     = false;
                        applicationPool.ManagedRuntimeVersion     = "v4.0";
                        applicationPool.ManagedPipelineMode       = ManagedPipelineMode.Integrated;
                        applicationPool.ProcessModel.IdentityType = ProcessModelIdentityType.ApplicationPoolIdentity;
                    }

                    string physicalPath = applicationSite.PhysicalPath.Destination;

                    Site site = siteCollection.Add(applicationName, physicalPath, 80);
                    site.ServerAutoStart = true;
                    site.ApplicationDefaults.ApplicationPoolName = applicationPool.Name;
                    site.Applications[0].ApplicationPoolName     = applicationPool.Name;

                    string protocol           = "http";
                    string ipAddress          = "*";
                    string port               = "80";
                    string hostName           = "*";
                    string bindingInformation = string.Format("{0}:{1}:{2}", ipAddress, port, hostName);

                    site.Bindings.Clear();
                    foreach (BindingInformationModel itemBindingInformation in applicationSite.BindingInformation)
                    {
                        protocol           = itemBindingInformation.Protocol;
                        ipAddress          = itemBindingInformation.IPAddress;
                        port               = itemBindingInformation.Port;
                        hostName           = itemBindingInformation.HostName;
                        bindingInformation = string.Format("{0}:{1}:{2}", ipAddress, port, hostName);

                        site.Bindings.Add(bindingInformation, protocol);
                    }

                    serverManager.CommitChanges();

                    _logger.InfoFormat("[{0}] - ApplicationSite created", MethodInfo.GetCurrentMethod().Name);
                    _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                } catch (Exception ex) {
                    _logger.Error(string.Format("[{0}] - Problem on parse ApplicationSite config. Message: {1}", MethodInfo.GetCurrentMethod().Name, ex.Message), ex);
                    _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                }
            }
            else
            {
                _logger.InfoFormat("[{0}] - ApplicationSite file config not found, can't create ApplicationSite", MethodInfo.GetCurrentMethod().Name);
                _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
            }
        }