Exemplo n.º 1
0
        public static PropertyBag SerializeSite(Site site)
        {
            PropertyBag bag = new PropertyBag();

            bag[FtpSiteGlobals.Site_Name] = site.Name;
            bag[FtpSiteGlobals.Site_ID]   = site.Id;
            Application application = site.Applications["/"];

            bag[FtpSiteGlobals.VirtualDirectory_PhysicalPath] = string.Empty;
            if (application != null)
            {
                VirtualDirectory directory = application.VirtualDirectories["/"];
                if (directory != null)
                {
                    bag[FtpSiteGlobals.VirtualDirectory_PhysicalPath] = directory.PhysicalPath;
                    bag[FtpSiteGlobals.VirtualDirectory_UserName]     = directory.UserName;
                    bag[FtpSiteGlobals.VirtualDirectory_Password]     = directory.Password;
                }
            }
            bag[FtpSiteGlobals.Site_Bindings] = GetFtpBindings(site.Bindings);
            FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);

            bag[FtpSiteGlobals.FtpSite_Status] = (int)ftpSiteElement.State;
            return(bag);
        }
Exemplo n.º 2
0
        public static void DeserializeSiteProperties(Site site, PropertyBag bag)
        {
            foreach (int num in bag.ModifiedKeys)
            {
                switch (num)
                {
                case FtpSiteGlobals.Site_Name:
                    string str = (string)bag[num];
                    site.Name = str;
                    break;
                }
            }
            Application element = site.Applications["/"];

            if (element == null)
            {
                element      = site.Applications.CreateElement();
                element.Path = "/";
                site.Applications.Add(element);
            }
            VirtualDirectory directory = element.VirtualDirectories["/"];

            if (directory == null)
            {
                directory      = element.VirtualDirectories.CreateElement();
                directory.Path = "/";
                element.VirtualDirectories.Add(directory);
            }
            DeserializeVirtualDirectoryProperties(directory, bag);
            DeserializeFtpSiteProperties(FtpHelper.GetFtpSiteElement(site), bag);
        }
Exemplo n.º 3
0
        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
            {
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets ftp site with given name.
        /// </summary>
        /// <param name="siteName">Site's name.</param>
        /// <returns>Ftp site.</returns>
        public FtpSite GetIisFtpSite(string siteName)
        {
            Site site = this.GetIisSite(siteName);

            if (site == null)
            {
                throw new ArgumentException("Site with given name doesn't exist.", "siteName");
            }
            FtpSite ftpSiteElement = FtpHelper.GetFtpSiteElement(site);

            ftpSiteElement.SiteServiceId = Convert.ToString(site.Id);
            //
            return(ftpSiteElement);
        }
Exemplo n.º 5
0
        public PropertyBag GetSiteProperties(string siteName)
        {
            if (string.IsNullOrEmpty(siteName))
            {
                throw new ArgumentNullException(siteName);
            }
            Site site = ServerManager.Sites[siteName];

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

            PropertyBag bag = SitesHelper.SerializeSite(site);

            SitesHelper.SerializeFtpSiteProperties(FtpHelper.GetFtpSiteElement(site), bag);
            return(bag);
        }
Exemplo n.º 6
0
        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));
        }