Пример #1
0
        public CmsSitePath AddChildDirectory(Data.Guid siteGuid, String parentPath, String newDirectory)
        {
            if (String.IsNullOrEmpty(parentPath))
                parentPath = RootPath;

            CmsSitePath parent = GetPath(siteGuid, parentPath);
            if (parent == null)
                throw new ArgumentException("Could not add child directory because the parent path '" + parentPath + "' does not exist.");

            String slash = (parent.Url.EndsWith("/")) ? "" : "/";
            CmsSitePath path = new CmsSitePath();

            if (newDirectory.StartsWith("/"))
                newDirectory = newDirectory.Substring(1);

            path.SubscriptionGuid = siteGuid.Value;
            path.Parent = parent.Url;
            path.IsDirectory = true;
            path.Depth = parent.Depth + 1;
            path.Url = parent.Url + slash + newDirectory;
            path.UrlHash = TextHash.MD5(path.Url).Value;
            path.Position = GetNextPosition(siteGuid,path.Depth);

            ValidatePath(siteGuid, path.Url);
            CmsSitePathDao dao = new CmsSitePathDao();
            using (Transaction tx = new Transaction())
            {
                dao.Save<CmsSitePath>(path);
                tx.Commit();
            }

            return path;
        }
Пример #2
0
 public RedirectItem(CmsSitePath path)
 {
     this.RedirectFrom = path.Url;
     this.RedirectTo = path.RedirectTo;
     this.SubscriptionId = path.SubscriptionGuid;
 }
Пример #3
0
 public void Save(CmsSitePath path)
 {
     CmsSitePathDao dao = new CmsSitePathDao();
     using (Transaction tx = new Transaction())
     {
         dao.Save<CmsSitePath>(path);
         tx.Commit();
     }
 }
Пример #4
0
        /// <summary>
        /// Gets the children for the specified parent
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public IList<CmsSitePath> GetChildren(CmsSitePath parent)
        {
            CmsSitePathDao dao = new CmsSitePathDao();
            IList<CmsSitePath> children = dao.FindChildren(parent.SubscriptionGuid,parent.Url);

            return children;
        }
Пример #5
0
        public CmsSitePath AddRootDirectory(Data.Guid siteGuid)
        {
            CmsSitePath path = GetRootPath(siteGuid);
            if (path == null)
            {
                path = new CmsSitePath();
                path.SubscriptionGuid = siteGuid.Value;
                path.Parent = null;
                path.IsDirectory = true;
                path.Depth = 1;
                path.Position = 0;
                path.Url = RootPath;
                path.UrlHash = TextHash.MD5(path.Url).Value;

                ValidatePath(siteGuid, path.Url);
                CmsSitePathDao dao = new CmsSitePathDao();
                using (Transaction tx = new Transaction())
                {
                    dao.Save<CmsSitePath>(path);
                    tx.Commit();
                }
            }
            return path;
        }
Пример #6
0
        public CmsSitePath AddRedirect(Data.Guid siteGuid, String redirectFrom, String redirectTo)
        {
            if ((!redirectFrom.StartsWith("http")) && (!redirectFrom.StartsWith("~/")))
            {
                if (redirectFrom.StartsWith("/"))
                    redirectFrom = "~" + redirectFrom;
                else if (!redirectFrom.StartsWith("/"))
                    redirectFrom = "~/" + redirectFrom;
            }

            if ((!redirectTo.StartsWith("http")) && (!redirectTo.StartsWith("~/")))
            {
                if (redirectTo.StartsWith("/"))
                    redirectTo = "~" + redirectTo;
                else if (!redirectTo.StartsWith("/"))
                    redirectTo = "~/" + redirectTo;
            }

            CmsSitePath path = GetPath(siteGuid, redirectFrom);
            if (path == null)
            {
                path = new CmsSitePath();
            }

            path.SubscriptionGuid = siteGuid.Value;
            path.Url = redirectFrom;
            path.UrlHash = TextHash.MD5(path.Url).Value;
            path.RedirectTo = redirectTo;
            path.IsRedirect = true;

            CmsSitePathDao dao = new CmsSitePathDao();
            using (Transaction tx = new Transaction())
            {
                dao.Save<CmsSitePath>(path);
                tx.Commit();
            }

            return path;
        }
Пример #7
0
        public CmsSitePath AddNewPage(Data.Guid siteGuid, String parentPath, String newPage)
        {
            CmsSitePath parent = GetPath(siteGuid, parentPath);
            if (parent == null)
                throw new ArgumentException(parentPath + " does not exist and can not be used as a parent for " + newPage);

            String fullurl = PathCombine(parent.Url, newPage);

            //Make sure the url doesn't already exist
            CmsSitePath path = GetPath(siteGuid, fullurl);
            if (path == null)
            {
                int depth = parent.Depth + 1;

                path = new CmsSitePath();
                path.SubscriptionGuid = siteGuid.Value;
                path.Depth = depth;
                path.Position = GetNextPosition(siteGuid, depth);
                path.Parent = parent.Url;
                path.Url = fullurl;
                path.UrlHash = TextHash.MD5(fullurl).Value;
                path.IsPage = true;

                CmsSitePathDao dao = new CmsSitePathDao();
                using (Transaction tx = new Transaction())
                {
                    dao.Save<CmsSitePath>(path);
                    tx.Commit();
                }
            }
            return path;
        }
Пример #8
0
        public void DeleteFolder(CmsSitePath folder)
        {
            if (!folder.IsDirectory)
                throw new ArgumentException("This method may only be used to delete folders not pages");

            IList<CmsSitePath> pages = CmsSiteMap.Instance.GetChildren(folder);
            foreach (CmsSitePath path in pages)
            {
                CmsUrl url = new CmsUrl(path.Url);
                CmsPage page = this.GetLatestPage(url, false);
                if (page == null)
                {
                    page = new CmsPage();
                    page.Url = path.Url;
                    page.UrlHash = TextHash.MD5(page.Url).Value;
                }
                this.DeleteAll(page);
            }

            //Delete the directory itself from the sitemap
            CmsSiteMap.Instance.Remove(folder);
        }