コード例 #1
0
        /// <summary>
        /// Adds a binding to a IIS site
        /// </summary>
        /// <param name="settings">The settings of the binding</param>
        /// <returns>If the binding was added.</returns>
        public bool AddBinding(string siteName, BindingSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

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



            //Get Site
            Site site = _Server.Sites.SingleOrDefault(p => p.Name == siteName);

            if (site != null)
            {
                if (site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation)) != null)
                {
                    throw new Exception("A binding with the same ip, port and host header already exists.");
                }



                //Add Binding
                Binding newBinding = site.Bindings.CreateElement();

                newBinding.Protocol           = settings.BindingProtocol.ToString();
                newBinding.BindingInformation = settings.BindingInformation;

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

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

                site.Bindings.Add(newBinding);
                _Server.CommitChanges();

                _Log.Information("Binding added.");
                return(true);
            }
            else
            {
                throw new Exception("Site: " + siteName + " does not exist.");
            }
        }
コード例 #2
0
ファイル: BaseSiteManager.cs プロジェクト: Azkel/Cake.IIS
        /// <summary>
        /// Removes a binding to a IIS site
        /// </summary>
        /// <param name="siteName">The website name</param>
        /// <param name="settings">The settings of the binding</param>
        /// <returns>If the binding was removed.</returns>
        public bool RemoveBinding(string siteName, BindingSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

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



            //Get Site
            Site site = _Server.Sites.SingleOrDefault(p => p.Name == siteName);

            if (site != null)
            {
                Binding binding = site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation));

                if (binding != null)
                {
                    //Remove Binding
                    site.Bindings.Remove(binding);
                    _Server.CommitChanges();

                    _Log.Information("Binding removed.");
                    return(true);
                }
                else
                {
                    _Log.Information("A binding with the same ip, port and host header does not exists.");
                    return(false);
                }
            }
            else
            {
                throw new Exception("Site: " + siteName + " does not exist.");
            }
        }
コード例 #3
0
ファイル: SiteAliases.cs プロジェクト: DrKoch/Cake.IIS
 public static void RemoveSiteBinding(this ICakeContext context, string server, BindingSettings settings)
 {
     using (ServerManager manager = BaseManager.Connect(server))
     {
         WebsiteManager
             .Using(context.Environment, context.Log, manager)
             .RemoveBinding(settings);
     }
 }
コード例 #4
0
ファイル: SiteAliases.cs プロジェクト: DrKoch/Cake.IIS
 public static void RemoveSiteBinding(this ICakeContext context, BindingSettings settings)
 {
     context.RemoveSiteBinding("", settings);
 }
コード例 #5
0
ファイル: BindingAliases.cs プロジェクト: shamork/Cake.IIS
 public static void RemoveBinding(this ICakeContext context, string server, string siteName, BindingSettings settings)
 {
     using (ServerManager manager = BaseManager.Connect(server))
     {
         WebsiteManager
         .Using(context.Environment, context.Log, manager)
         .RemoveBinding(siteName, settings);
     }
 }
コード例 #6
0
ファイル: BindingAliases.cs プロジェクト: shamork/Cake.IIS
 public static void RemoveBinding(this ICakeContext context, string siteName, BindingSettings settings)
 {
     context.RemoveBinding("", siteName, settings);
 }
コード例 #7
0
ファイル: BaseSiteManager.cs プロジェクト: DrKoch/Cake.IIS
            public bool RemoveBinding(BindingSettings settings)
            {
                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.SingleOrDefault(p => p.Name == settings.Name);

                if (site != null)
                {
                    Binding binding = site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation));

                    if (binding != null)
                    {
                        //Remove Binding
                        site.Bindings.Remove(binding);
                        _Server.CommitChanges();

                        _Log.Information("Binding removed.");
                        return true;
                    }
                    else
                    {
                        _Log.Information("A binding with the same ip, port and host header does not exists.");
                        return false;
                    }
                }
                else
                {
                    throw new Exception("Site: " + settings.Name + " does not exist.");
                }
            }
コード例 #8
0
ファイル: BaseSiteManager.cs プロジェクト: DrKoch/Cake.IIS
            public bool AddBinding(BindingSettings settings)
            {
                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.SingleOrDefault(p => p.Name == settings.Name);

                if (site != null)
                {
                    if (site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation)) != null)
                    {
                        throw new Exception("A binding with the same ip, port and host header already exists.");
                    }



                    //Add Binding
                    Binding newBinding = site.Bindings.CreateElement();

                    newBinding.Protocol = settings.BindingProtocol.ToString();
                    newBinding.BindingInformation = settings.BindingInformation;

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

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

                    site.Bindings.Add(newBinding);
                    _Server.CommitChanges();

                    _Log.Information("Binding added.");
                    return true;
                }
                else
                {
                    throw new Exception("Site: " + settings.Name + " does not exist.");
                }
            }