/// <summary>
        /// Creates a new instance of the <see cref="ApplicationPoolManager" /> class.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="log">The log.</param>
        /// <param name="server">The <see cref="ServerManager" /> to connect to.</param>
        /// <returns>a new instance of the <see cref="ApplicationPoolManager" />.</returns>
        public static ApplicationPoolManager Using(ICakeEnvironment environment, ICakeLog log, ServerManager server)
        {
            ApplicationPoolManager manager = new ApplicationPoolManager(environment, log);

            manager.SetServer(server);

            return(manager);
        }
            public static ApplicationPoolManager Using(ICakeEnvironment environment, ICakeLog log, ServerManager server)
            {
                ApplicationPoolManager manager = new ApplicationPoolManager(environment, log);
            
                manager.SetServer(server);

                return manager;
            }
 public static bool DeletePool(this ICakeContext context, string server, string name)
 {
     using (ServerManager manager = BaseManager.Connect(server))
     {
         return(ApplicationPoolManager
                .Using(context.Environment, context.Log, manager)
                .Delete(name));
     }
 }
 public static void CreatePool(this ICakeContext context, string server, ApplicationPoolSettings settings)
 {
     using (ServerManager manager = BaseManager.Connect(server))
     {
         ApplicationPoolManager
         .Using(context.Environment, context.Log, manager)
         .Create(settings);
     }
 }
        public static bool RestartPool(this ICakeContext context, string server, string name)
        {
            using (ServerManager manager = BaseManager.Connect(server))
            {
                ApplicationPoolManager poolManager = ApplicationPoolManager.Using(context.Environment, context.Log, manager);

                if (poolManager.Stop(name))
                {
                    return(poolManager.Start(name));
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Creates a IIS site
        /// </summary>
        /// <param name="settings">The setting of the site</param>
        /// <param name="exists">Check if the site exists</param>
        /// <returns>IIS Site.</returns>
        protected Site CreateSite(SiteSettings settings, out bool exists)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (string.IsNullOrWhiteSpace(settings.Name))
            {
                throw new ArgumentException("Site name cannot be null!");
            }



            //Get Site
            Site site = _Server.Sites.FirstOrDefault(p => p.Name == settings.Name);

            if (site != null)
            {
                _Log.Information("Site '{0}' already exists.", settings.Name);

                if (settings.Overwrite)
                {
                    _Log.Information("Site '{0}' will be overriden by request.", settings.Name);

                    this.Delete(settings.Name);

                    ApplicationPoolManager
                    .Using(_Environment, _Log, _Server)
                    .Delete(site.ApplicationDefaults.ApplicationPoolName);

                    exists = false;
                }
                else
                {
                    exists = true;
                    return(site);
                }
            }
            else
            {
                exists = false;
            }



            //Create Pool
            ApplicationPoolManager
            .Using(_Environment, _Log, _Server)
            .Create(settings.ApplicationPool);



            //Site Settings
            site = _Server.Sites.Add(
                settings.Name,
                this.GetPhysicalDirectory(settings),
                settings.Binding.Port);


            if (!String.IsNullOrEmpty(settings.AlternateEnabledProtocols))
            {
                site.ApplicationDefaults.EnabledProtocols = settings.AlternateEnabledProtocols;
            }

            site.Bindings.Clear();
            var binding = site.Bindings.CreateElement();

            binding.Protocol           = settings.Binding.BindingProtocol.ToString().ToLower();
            binding.BindingInformation = settings.Binding.BindingInformation;


            if (settings.Binding.CertificateHash != null)
            {
                binding.CertificateHash = settings.Binding.CertificateHash;
            }

            if (!String.IsNullOrEmpty(settings.Binding.CertificateStoreName))
            {
                binding.CertificateStoreName = settings.Binding.CertificateStoreName;
            }

            site.Bindings.Add(binding);

            site.ServerAutoStart = settings.ServerAutoStart;
            site.ApplicationDefaults.ApplicationPoolName = settings.ApplicationPool.Name;

            // Security
            var serverType = settings is WebsiteSettings ? "webServer" : "ftpServer";
            var hostConfig = GetWebConfiguration();

            hostConfig.SetAuthentication(serverType, settings.Name, "", settings.Authentication, _Log);
            hostConfig.SetAuthorization(serverType, settings.Name, "", settings.Authorization);

            return(site);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a IIS site
        /// </summary>
        /// <param name="settings">The setting of the site</param>
        /// <param name="exists">Check if the site exists</param>
        /// <returns>IIS Site.</returns>
        protected Site CreateSite(SiteSettings settings, out bool exists)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (string.IsNullOrWhiteSpace(settings.Name))
            {
                throw new ArgumentException("Site name cannot be null!");
            }



            //Get Site
            Site site = _Server.Sites.FirstOrDefault(p => p.Name == settings.Name);

            if (site != null)
            {
                _Log.Information("Site '{0}' already exists.", settings.Name);

                if (settings.Overwrite)
                {
                    _Log.Information("Site '{0}' will be overriden by request.", settings.Name);

                    this.Delete(settings.Name);

                    ApplicationPoolManager
                    .Using(_Environment, _Log, _Server)
                    .Delete(site.ApplicationDefaults.ApplicationPoolName);

                    exists = false;
                }
                else
                {
                    exists = true;
                    return(site);
                }
            }
            else
            {
                exists = false;
            }



            //Create Pool
            ApplicationPoolManager
            .Using(_Environment, _Log, _Server)
            .Create(settings.ApplicationPool);



            //Site Settings
            site = _Server.Sites.Add(
                settings.Name,
                settings.Binding.BindingProtocol.ToString().ToLower(),
                settings.Binding.BindingInformation,
                this.GetPhysicalDirectory(settings));

            if (settings.Binding.CertificateHash != null)
            {
                site.Bindings[0].CertificateHash = settings.Binding.CertificateHash;
            }

            if (!String.IsNullOrEmpty(settings.Binding.CertificateStoreName))
            {
                site.Bindings[0].CertificateStoreName = settings.Binding.CertificateStoreName;
            }

            site.ServerAutoStart = settings.ServerAutoStart;
            site.ApplicationDefaults.ApplicationPoolName = settings.ApplicationPool.Name;



            //Security
            string server = "";

            if (settings is WebsiteSettings)
            {
                server = "webServer";
            }
            else
            {
                server = "ftpServer";
            }

            this.SetAuthentication(server, settings.Name, "", settings.Authentication);
            this.SetAuthorization(server, settings.Name, "", settings.Authorization);

            return(site);
        }