public void Save(CmsPage page) { CmsPageDao dao = new CmsPageDao(); using (Transaction tx = new Transaction()) { dao.Save<CmsPage>(page); tx.Commit(); } IStorageClient client = StorageHelper.GetStorageClient(); client.Save(SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId), StorageClientConst.RootFolder, page.Guid, page.Content, Permissions.Private); }
public void Remove(CmsPage page) { if (page != null) { String container = SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId); IStorageClient client = StorageHelper.GetStorageClient(); CmsPageDao dao = new CmsPageDao(); using (Transaction tx = new Transaction()) { client.Delete(container, StorageClientConst.RootFolder, page.Guid); dao.Delete<CmsPage>(page); tx.Commit(); } } }
public void RemoveObsoletePages(CmsPage page) { CmsPageDao dao = new CmsPageDao(); IList<CmsPage> unapproved = dao.FindUnapprovedPages(Data.Guid.New(page.SubscriptionId),Data.Hash.New(page.UrlHash)); IList<CmsPage> approved = dao.FindApprovedPages(Data.Guid.New(page.SubscriptionId), Data.Hash.New(page.UrlHash)); IStorageClient client = StorageHelper.GetStorageClient(); String container = SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId); //Loop through all of the unapproved pages and remove any old versions. //Start at the first one, since we always want to leave the latest unapproved version using (Transaction tx = new Transaction()) { for (int i = 1; i < unapproved.Count; i++) { client.Delete(container, StorageClientConst.RootFolder, unapproved[i].Guid); dao.Delete<CmsPage>(unapproved[i]); } tx.Commit(); } //Loop through all of the approved pages and remove any old versions. //Start at the first one, since we always want to leave the latest approved version using (Transaction tx = new Transaction()) { for (int i = 1; i < approved.Count; i++) { client.Delete(container, StorageClientConst.RootFolder, approved[i].Guid); dao.Delete<CmsPage>(approved[i]); } tx.Commit(); } }
public IList<CmsPage> GetPages(Data.Guid siteGuid, CmsUrl url) { CmsPageDao dao = new CmsPageDao(); return dao.FindByPageHash(siteGuid, TextHash.MD5(url.ToString())); }
public IList<CmsPage> GetUnapprovedPages(Data.Guid siteGuid) { CmsPageDao dao = new CmsPageDao(); return dao.FindUnapprovedPages(siteGuid); }
/// <summary> /// Gets the latest page baesd upon an encrypted primary key /// </summary> /// <param name="encryptedPageId"></param> /// <returns></returns> public CmsPage GetPage(Data.EncryptedValue encryptedPageId) { CmsPage result = null; int id = 0; String temp = TextEncryption.Decode(encryptedPageId.Value); Int32.TryParse(temp, out id); CmsPageDao dao = new CmsPageDao(); result = dao.FindByPrimaryKey<CmsPage>(id); LoadPageData(result); if (CurrentSite.IsProductionHost) { if (!result.IsApproved) { Logging.Info("A request for the page (primary key=" + id + ") has not been approved and will not be returned in production mode."); result = null; } } return result; }
public CmsPage GetPage(Data.Guid siteGuid, Data.Guid pageGuid, Boolean loadData) { CmsPageDao dao = new CmsPageDao(); Boolean approvedOnly = !(CurrentSite.IsStagingHost); CmsPage result = dao.FindByPageGuid(siteGuid, pageGuid); if (loadData) LoadPageData(result); if (CurrentSite.IsProductionHost) { if (!result.IsApproved) { Logging.Info("A request was made for page: " + pageGuid + ", (owner=" + result.SubscriptionId + ") however, this page is not approved and will not be returned."); result = null; } } return result; }
/// <summary> /// Gets the latest page based upon the path /// </summary> /// <param name="siteGuid">The site guid</param> /// <param name="path">The page path</param> /// <returns></returns> public CmsPage GetLatestPage(Data.Guid siteGuid, CmsUrl uri, bool loadData, bool forceLatest) { String path = uri.Path; Data.Hash pathHash = TextHash.MD5(path); CmsPageDao dao = new CmsPageDao(); Boolean approvedOnly = false; if (!forceLatest) approvedOnly = !(CurrentSite.IsStagingHost); CmsPage result = dao.FindLatesBySiteAndHash(siteGuid, pathHash, approvedOnly); //Check if there's a default page that should be loaded if (result == null) { String separator = CmsSiteMap.PathSeparator; if (path.EndsWith(CmsSiteMap.PathSeparator)) separator = String.Empty; Data.Hash hashWithDefault = TextHash.MD5(path + separator + CmsSiteMap.DefaultPageName); result = dao.FindLatesBySiteAndHash(siteGuid, hashWithDefault, approvedOnly); } //Load the page contents if (loadData) LoadPageData(result); return result; }
public System.Collections.Generic.IList<CmsPage> Filter(Data.Guid siteGuid, string filter) { if (String.IsNullOrWhiteSpace(filter)) filter = "*"; CmsPageDao dao = new CmsPageDao(); filter = filter.Replace("*", "%"); return dao.SearchByUrl(siteGuid,filter); }
/// <summary> /// Removes all versions of the page /// </summary> /// <param name="page"></param> public void DeleteAll(CmsPage page) { if (page != null) { String container = SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId); IStorageClient client = StorageHelper.GetStorageClient(); CmsPageDao dao = new CmsPageDao(); IList<CmsPage> pages = dao.FindAllPages(Data.Guid.New(page.SubscriptionId), Data.Hash.New(page.UrlHash)); using (Transaction tx = new Transaction()) { foreach (CmsPage temp in pages) { client.Delete(container, StorageClientConst.RootFolder, temp.Guid); dao.Delete<CmsPage>(temp); } tx.Commit(); } } CmsSitePath path = CmsSiteMap.Instance.GetPath(page.SubscriptionId,page.Url); if (path != null) CmsSiteMap.Instance.Remove(path); }
/// <summary> /// Deletes a specific page from the system /// </summary> /// <param name="pageGuid"></param> public void Delete(Data.Guid siteGuid, Data.Guid pageGuid) { String container = SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, siteGuid.Value); IStorageClient client = StorageHelper.GetStorageClient(); CmsPageDao dao = new CmsPageDao(); CmsPage page = GetPage(pageGuid, false); if (page != null) { if (!page.SubscriptionId.Equals(siteGuid.Value)) throw new ArgumentException("This page does not belong to the current subscription and can not be retrieved."); client.Delete(container, StorageClientConst.RootFolder, page.Guid); using (Transaction tx = new Transaction()) { dao.Delete<CmsPage>(page); tx.Commit(); } //Check if there are other versions of this page, if not, delete the sitepath as well IList<CmsPage> pages = GetPages(siteGuid, page.Url); if ((pages == null) || (pages.Count == 0)) { CmsSitePath path = CmsSiteMap.Instance.GetPath(page.Url); if (path != null) CmsSiteMap.Instance.Remove(path); } } }
/// <summary> /// Adds a new page to the CMS system. /// </summary> /// <param name="parent"></param> /// <param name="pageName"></param> /// <param name="page"></param> public void AddNewPage(string parent, string pageName, CmsPage page) { CmsPageDao dao = new CmsPageDao(); CmsSitePath path = null; try { path = CmsSiteMap.Instance.AddNewPage(Data.Guid.New(page.SubscriptionId),parent, pageName); Save(page); } catch (Exception ex) { Logging.Error("There was an unexpected exception adding the page", ex); CmsSiteMap.Instance.Remove(path); this.Remove(page); } }