private static void DeleteWebsite([NotNull] WebServerContext context, [NotNull] Site site)
        {
            Assert.ArgumentNotNull(context, nameof(context));
            Assert.ArgumentNotNull(site, nameof(site));

            foreach (Application application in site.Applications)
            {
                var             applicationPoolName = application.ApplicationPoolName;
                ApplicationPool appplicationPool    = context.ApplicationPools[applicationPoolName];

                // Application is used only in the current website or isn't used at all
                if (appplicationPool != null && context.Sites.Count(s => s.ApplicationDefaults.ApplicationPoolName.EqualsIgnoreCase(applicationPoolName)) <= 1)
                {
                    context.ApplicationPools.Remove(appplicationPool);
                }
            }

            context.Sites.Remove(site);
            context.CommitChanges();
        }
        public static bool AddHostBinding([NotNull] string siteName, [NotNull] BindingInfo binding)
        {
            Assert.ArgumentNotNull(siteName, nameof(siteName));
            Assert.ArgumentNotNull(binding, nameof(binding));

            using (WebServerContext context = CreateContext())
            {
                Site siteInfo = context.Sites.FirstOrDefault(site => site.Name.EqualsIgnoreCase(siteName));
                if (HostBindingExists(binding.Host) || siteInfo == null)
                {
                    return(false);
                }
                var bindingInformation = $"{binding.IP}:{binding.Port}:{binding.Host}";

                siteInfo.Bindings.Add(bindingInformation, binding.Protocol);
                context.CommitChanges();
            }

            return(true);
        }
        public static bool AddHostBinding([NotNull] string siteName, [NotNull] BindingInfo binding)
        {
            Assert.ArgumentNotNull(siteName, nameof(siteName));
            Assert.ArgumentNotNull(binding, nameof(binding));

            using (WebServerContext context = CreateContext("WebServerManager.AddHostBinding('{0}','{1}')".FormatWith(siteName, binding.Host)))
            {
                Site siteInfo = context.Sites.FirstOrDefault(site => Extensions.EqualsIgnoreCase(site.Name, siteName));
                if (HostBindingExists(binding.Host) || siteInfo == null)
                {
                    return(false);
                }
                var bindingInformation = binding.IP + ":" + binding.Port + ":" + binding.Host;

                siteInfo.Bindings.Add(bindingInformation, binding.Protocol);
                context.CommitChanges();
            }

            return(true);
        }