public void AddSite(PropertyBag bag)
        {
            // ensure bag not empty
            if (bag == null)
            {
                throw new ArgumentNullException("bag");
            }

            // ensure site not exists
            string name = (string)bag[FtpSiteGlobals.Site_Name];

            if (ServerManager.Sites[name] != null)
            {
                throw new Exception("SiteAlreadyExistsExceptionError");
            }

            // ensure site path
            string directory = (string)bag[FtpSiteGlobals.VirtualDirectory_PhysicalPath];

            if (!Directory.Exists(FileUtils.EvaluateSystemVariables(directory)))
            {
                throw new Exception("SiteDirectoryDoesNotExistExceptionError");
            }

            // ensure site binding
            PropertyBag bag2 = (PropertyBag)bag[FtpSiteGlobals.Site_SingleBinding];

            if (bag2 == null)
            {
                throw new ArgumentNullException("bindingBag");
            }

            string bindingInformation = (string)bag2[FtpSiteGlobals.BindingInformation];

            SitesHelper.DeserializeSiteProperties(ServerManager.Sites.Add(name, "ftp", bindingInformation, directory), bag);
            // authorization
            PropertyBag authBag = (PropertyBag)bag[FtpSiteGlobals.Authorization_Rule];

            if (authBag != null)
            {
                AddAuthorizationRules(name, authBag);
            }

            ServerManager.CommitChanges();
            Site site = ServerManager.Sites[name];

            try
            {
                FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);
                //
                if (ftpSiteElement.ServerAutoStart)
                {
                    ftpSiteElement.Start();
                }
            }
            catch
            {
            }
        }
        public PropertyBag EditSiteProperties(PropertyBag bag)
        {
            if (bag == null)
            {
                throw new ArgumentNullException("bag");
            }
            string      siteName   = (string)bag[100];
            PropertyBag bindingBag = (PropertyBag)bag[0x68];

            if (bindingBag != null)
            {
                this.AddSiteBinding(siteName, bindingBag);
            }
            Site site = ServerManager.Sites[siteName];

            if (site == null)
            {
                throw new Exception("SiteDoesNotExistCannotEditExceptionError");
            }

            SitesHelper.DeserializeSiteProperties(site, bag);
            PropertyBag authBag = (PropertyBag)bag[0x1a6];

            if (authBag != null)
            {
                this.AddAuthorizationRules(siteName, authBag);
            }
            //
            ServerManager.CommitChanges();
            //
            site = ServerManager.Sites[siteName];
            try
            {
                FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);
                if (ftpSiteElement.ServerAutoStart)
                {
                    ftpSiteElement.Start();
                }
            }
            catch
            {
            }
            return(SitesHelper.SerializeSite(site));
        }