static Cms() { PyhicPath = AppDomain.CurrentDomain.BaseDirectory; //获得版本号 //AssemblyFileVersionAttribute ver = (AssemblyFileVersionAttribute)typeof(Cms).Assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0]; //string[] verarr = ver.Version.Split('.'); //Version = String.Format("{0}.{1}.{2}", verarr[0], verarr[1], verarr[2]); //获取编译生成的时间 //Version ver=typeof(Cms).Assembly.GetName().Version; //BuiltTime= new DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.Revision * 2); //BuiltTime=System.IO.File.GetLastWriteTime(typeof(Cms).Assembly.Location); //获取平台 Int32 platFormID = (Int32)Environment.OSVersion.Platform; if (platFormID == 4 || platFormID == 6 || platFormID == 128) { RunAtMono = true; } //初始化 Plugins = new CmsPluginContext(); Template = new CmsTemplate(); Cache = CacheFactory.Sington as CmsCache; Utility = new CmsUtility(); #region 缓存清除 // //UNDONE: 弱引用 // /* * WeakRefCache.OnLinkBuilting += () => * { * Cms.Cache.Clear(CacheSign.Link.ToString()); * }; * * WeakRefCache.OnModuleBuilting += () => * { * Cms.Cache.Clear(CacheSign.Module.ToString()); * }; * * WeakRefCache.OnPropertyBuilting += () => * { * Cms.Cache.Clear(CacheSign.Property.ToString()); * }; * * WeakRefCache.OnTemplateBindBuilting += () => * { * Cms.Cache.Clear(CacheSign.TemplateBind.ToString()); * }; * */ #endregion }
static Cms() { Version = CmsVariables.VERSION; PyhicPath = AppDomain.CurrentDomain.BaseDirectory; //获取编译生成的时间 //DateTime builtDate = new DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.Revision*2); string filePath = typeof(Cms).Assembly.Location; if (String.IsNullOrEmpty(filePath)) { filePath = PyhicPath + CmsVariables.FRAMEWORK_ASSEMBLY_PATH + "jrcms.dll"; } DateTime builtDate = File.GetLastWriteTime(filePath); BuiltTime = DateHelper.ToUnix(builtDate); //获取平台 Int32 platFormId = (Int32)Environment.OSVersion.Platform; if (platFormId == 4 || platFormId == 6 || platFormId == 128) { RunAtMono = true; } //初始化 Plugins = new CmsPluginContext(); Template = new CmsTemplate(); Cache = CacheFactory.Sington as CmsCache; Utility = new CmsUtility(); Language = new CmsLanguagePackage(); #region 缓存清除 // //UNDONE: 弱引用 // /* * WeakRefCache.OnLinkBuilting += () => * { * Cms.Cache.Clear(CacheSign.Link.ToString()); * }; * * WeakRefCache.OnModuleBuilting += () => * { * Cms.Cache.Clear(CacheSign.Module.ToString()); * }; * * WeakRefCache.OnPropertyBuilting += () => * { * Cms.Cache.Clear(CacheSign.Property.ToString()); * }; * * WeakRefCache.OnTemplateBindBuilting += () => * { * Cms.Cache.Clear(CacheSign.TemplateBind.ToString()); * }; * */ #endregion }
/// <summary> /// Gets the site. /// </summary> /// <param name="siteId">The site id.</param> /// <param name="returnInactive"></param> /// <returns></returns> public static SiteDto GetSite(Guid siteId, bool returnInactive) { // Assign new cache key, specific for site guid and response groups requested string cacheKey = CmsCache.CreateCacheKey("site", siteId.ToString()); SiteDto dto = null; // check cache first object cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { dto = (SiteDto)cachedObject; } // Load the object if (dto == null) { lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { dto = (SiteDto)cachedObject; } else { SiteAdmin admin = new SiteAdmin(); admin.Load(siteId, returnInactive); dto = admin.CurrentDto; // Insert to the cache collection CmsCache.Insert(cacheKey, dto, CmsConfiguration.Instance.Cache.SitesCollectionTimeout); } } } // Continue with security checks and other operations /* * foreach (SiteDto.SiteRow row in dto.Site.Rows) * { * // Check Security * IDataReader reader = DataHelper.CreateDataReader(dto.SiteSecurity, String.Format("SiteId = '{0}' or SiteId = '{1}'", Guid.Empty, row.SiteId)); * PermissionRecordSet recordSet = new PermissionRecordSet(PermissionHelper.ConvertReaderToRecords(reader)); * if (!PermissionManager.CheckPermission(SecurityScope.Site.ToString(), Permission.Read, recordSet)) * { * row.Delete(); * continue; * } * } * */ if (dto.HasChanges()) { dto.AcceptChanges(); } return(dto); }
/// <summary> /// Returns the full template dataset. Results are cached when not in design mode and not cached when in design mode. /// Use this method for all runtime calls. /// </summary> /// <returns></returns> public static TemplateDto GetTemplateDto() { bool useCache = !CMSContext.Current.IsDesignMode; // do not use template caching in design mode string cacheKey = CmsCache.CreateCacheKey("templates"); // check cache first object cachedObject = null; if (useCache) { cachedObject = CmsCache.Get(cacheKey); } if (cachedObject != null) { return((TemplateDto)cachedObject); } // TODO: add caching TemplateAdmin admin = new TemplateAdmin(); admin.Load(); // Insert to the cache collection if (useCache) { CmsCache.Insert(cacheKey, admin.CurrentDto, CmsConfiguration.Instance.Cache.TemplateTimeout); } return(admin.CurrentDto); }
static Cms() { Version = CmsVariables.VERSION; PyhicPath = AppDomain.CurrentDomain.BaseDirectory; //获取编译生成的时间 //Version ver=typeof(Cms).Assembly.GetName().Version; //BuiltTime= new DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.Revision * 2); //BuiltTime=System.IO.File.GetLastWriteTime(typeof(Cms).Assembly.Location); //获取平台 Int32 platFormId = (Int32)Environment.OSVersion.Platform; if (platFormId == 4 || platFormId == 6 || platFormId == 128) { RunAtMono = true; } //判断是否已经安装 FileInfo insLockFile = new FileInfo(String.Format("{0}config/install.lock", Cms.PyhicPath)); Installed = insLockFile.Exists; //初始化 Plugins = new CmsPluginContext(); Template = new CmsTemplate(); Cache = CacheFactory.Sington as CmsCache; Utility = new CmsUtility(); #region 缓存清除 // //UNDONE: 弱引用 // /* * WeakRefCache.OnLinkBuilting += () => * { * Cms.Cache.Clear(CacheSign.Link.ToString()); * }; * * WeakRefCache.OnModuleBuilting += () => * { * Cms.Cache.Clear(CacheSign.Module.ToString()); * }; * * WeakRefCache.OnPropertyBuilting += () => * { * Cms.Cache.Clear(CacheSign.Property.ToString()); * }; * * WeakRefCache.OnTemplateBindBuilting += () => * { * Cms.Cache.Clear(CacheSign.TemplateBind.ToString()); * }; * */ #endregion }
/// <summary> /// Retrieve a list of top-level menus from the database (if not already retrieved) /// </summary> private List <TopLevelMenuItem> GetTopLevelMenuItems() { string cacheKey = CmsCache.CreateCacheKey("sitemap-menus-top", CMSContext.Current.SiteId.ToString(), CMSContext.Current.LanguageId.ToString()); object cachedObject = CMSContext.Current.Context.Items[cacheKey]; if (cachedObject != null) { return((List <TopLevelMenuItem>)cachedObject); } cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { return((List <TopLevelMenuItem>)cachedObject); } List <TopLevelMenuItem> menus = new List <TopLevelMenuItem>(); lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { return((List <TopLevelMenuItem>)cachedObject); } //retrieve and iterate through datareader of root nodes and build generic list of items IDataReader reader = mc.MenuItem.LoadAllRoot(CMSContext.Current.SiteId); while (reader.Read()) { TopLevelMenuItem item = new TopLevelMenuItem(); try { item.MenuId = int.Parse(reader["MenuId"].ToString()); item.MenuName = reader["Text"].ToString(); } catch { reader.Close(); throw new Exception("Invalid menu data returned"); } menus.Add(item); } reader.Close(); CmsCache.Insert(cacheKey, menus, CmsConfiguration.Instance.Cache.MenuTimeout); CMSContext.Current.Context.Items[cacheKey] = menus; } return(menus); }
/// <summary> /// Sets the headers. /// </summary> private void SetHeaders() { string cacheKey = CmsCache.CreateCacheKey("page-headers", CMSContext.Current.PageId.ToString()); // check cache first object cachedObject = CmsCache.Get(cacheKey); string[] headersArray = null; if (cachedObject != null) { headersArray = (string[])cachedObject; } // Load the object if (headersArray == null) { lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { headersArray = (string[])cachedObject; } else { using (IDataReader reader = PageAttributes.GetByPageId(CMSContext.Current.PageId)) { if (reader.Read()) { headersArray = new string[] { (string)reader["MetaKeys"], (string)reader["MetaDescriptions"], (string)reader["Title"] }; CmsCache.Insert(cacheKey, headersArray, CmsConfiguration.Instance.Cache.PageDocumentTimeout); } reader.Close(); } } } } if (headersArray != null) { MetaKeyWord.Attributes.Add("content", headersArray[0]); MetaKeyWord.Attributes.Add("name", "keywords"); MetaDescription.Attributes.Add("content", headersArray[1]); MetaDescription.Attributes.Add("name", "description"); Head1.Title = headersArray[2]; Page.Title = headersArray[2]; // Set footer as well PageInclude.Text = GlobalVariable.GetVariable("page_include", CMSContext.Current.SiteId); } }
/// <summary> /// Gets the site. /// </summary> /// <param name="siteId">The site id.</param> /// <param name="responseGroup">The response group.</param> /// <returns></returns> internal static CmsSite GetSite(Guid siteId, SiteResponseGroup responseGroup) { // Assign new cache key, specific for site guid and response groups requested string cacheKey = CmsCache.CreateCacheKey("site-object", siteId.ToString(), responseGroup.CacheKey); CmsSite site = null; // check cache first object cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { site = (CmsSite)cachedObject; } // Load the object if (site == null) { lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { site = (CmsSite)cachedObject; } else { SiteDto siteDto = GetSite(siteId); // Load main site parameters site = ObjectHelper.CreateSite(siteDto.Site[0]); // Load menus if (responseGroup.ContainsGroup(SiteResponseGroup.ResponseGroup.Full) || responseGroup.ContainsGroup(SiteResponseGroup.ResponseGroup.Menus)) { List <SiteMenu> menuList = new List <SiteMenu>(); MenuDto menuDto = MenuManager.GetMenuDto(siteId); foreach (MenuDto.MenuRow row in menuDto.Menu) { menuList.Add(ObjectHelper.CreateMenu(menuDto, row)); } site.Menus = menuList.ToArray(); } // Insert to the cache collection CmsCache.Insert(cacheKey, site, CmsConfiguration.Instance.Cache.SitesCollectionTimeout); } } } return(site); }
/// <summary> /// Deletes from temp. /// </summary> private static void DeleteFromTemp() { if (PageDocument.Current != null) { PageDocument.Current.Delete(PageDocument.Current.PageVersionId, (Guid)ProfileContext.Current.User.ProviderUserKey, DeleteMode.TemporaryStorage); PageDocument.Current.Delete(CMSContext.Current.VersionId, (Guid)ProfileContext.Current.User.ProviderUserKey, DeleteMode.TemporaryStorage); PageDocument.Current.Delete(-2, (Guid)ProfileContext.Current.User.ProviderUserKey, DeleteMode.TemporaryStorage); PageDocument.Current.ResetModified(); } // Clear cache CmsCache.Clear(); }
private void ResetMenuNodes() { string cacheKey = GetSitemapCacheKey(); if (CMSContext.Current.Context.Items.Contains(cacheKey)) { CMSContext.Current.Context.Items.Remove(cacheKey); } object cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { CmsCache.Remove(cacheKey); } }
/// <summary> /// Resets the root node. /// </summary> private void ResetRootNode() { string cacheKey = CmsCache.CreateCacheKey("sitemap-rootnode", CMSContext.Current.SiteId.ToString(), CMSContext.Current.LanguageId.ToString()); CmsCache.CreateCacheKey(new string[] { cacheKey }); if (CMSContext.Current.Context.Items.Contains(cacheKey)) { CMSContext.Current.Context.Items.Remove(cacheKey); } object cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { CmsCache.Remove(cacheKey); } }
/// <summary> /// Gets the data source. /// </summary> /// <returns></returns> public DataTable GetDataSource() { string cacheKey = GetSitemapCacheKey(); object cachedObject = CMSContext.Current.Context.Items[cacheKey]; if (cachedObject != null) { return((DataTable)cachedObject); } cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { return((DataTable)cachedObject); } DataTable dt = null; lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { return((DataTable)cachedObject); } dt = mc.MenuItem.LoadAllDT(CMSContext.Current.SiteId, CMSContext.Current.LanguageId); if (ActiveTopLevelMenuId > 0) { DataView dv = dt.DefaultView; dv.RowFilter = String.Format("MenuId = {0}", ActiveTopLevelMenuId); dt = dv.ToTable(); } CmsCache.Insert(cacheKey, dt, CmsConfiguration.Instance.Cache.MenuTimeout); CMSContext.Current.Context.Items[cacheKey] = dt; } return(dt); }
/// <summary> /// Saves the specified pagedocument. /// </summary> /// <param name="pageVersionId">The page version id.</param> /// <param name="saveMode">The save mode.</param> /// <param name="userUID">The user UID.</param> public void Save(int pageVersionId, SaveMode saveMode, Guid userUID) { switch (saveMode) { case SaveMode.TemporaryStorage: if (userUID != null) { TemporaryDocumentStorage.Save(this, pageVersionId, userUID); } break; case SaveMode.PersistentStorage: // Save new document PersistentDocumentStorage.Save(this, pageVersionId, Guid.Empty); // Remove old cache CmsCache.RemoveByPattern(CmsCache.CreateCacheKey("pagedocument", pageVersionId.ToString())); break; default: throw new ArgumentNullException(); } }
static Cms() { PyhicPath = AppDomain.CurrentDomain.BaseDirectory; //获得版本号 //AssemblyFileVersionAttribute ver = (AssemblyFileVersionAttribute)typeof(Cms).Assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0]; //string[] verarr = ver.Version.Split('.'); //Version = String.Format("{0}.{1}.{2}", verarr[0], verarr[1], verarr[2]); //获取编译生成的时间 //Version ver=typeof(Cms).Assembly.GetName().Version; //BuiltTime= new DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.Revision * 2); //BuiltTime=System.IO.File.GetLastWriteTime(typeof(Cms).Assembly.Location); //获取平台 Int32 platFormID = (Int32)Environment.OSVersion.Platform; if (platFormID == 4 || platFormID == 6 || platFormID == 128) { RunAtMono = true; } //初始化 Plugins= new CmsPluginContext(); Template= new CmsTemplate(); Cache=CacheFactory.Sington as CmsCache; Utility=new CmsUtility(); #region 缓存清除 // //UNDONE: 弱引用 // /* WeakRefCache.OnLinkBuilting += () => { Cms.Cache.Clear(CacheSign.Link.ToString()); }; WeakRefCache.OnModuleBuilting += () => { Cms.Cache.Clear(CacheSign.Module.ToString()); }; WeakRefCache.OnPropertyBuilting += () => { Cms.Cache.Clear(CacheSign.Property.ToString()); }; WeakRefCache.OnTemplateBindBuilting += () => { Cms.Cache.Clear(CacheSign.TemplateBind.ToString()); }; */ #endregion }
private string GetSitemapCacheKey() { return(CmsCache.CreateCacheKey("sitemap", CMSContext.Current.SiteId.ToString(), ActiveTopLevelMenuId.ToString(), CMSContext.Current.LanguageId.ToString())); }
private static void PrepareCms() { #if NETSTANDARD IsNetStandard = true; if (_cache == null) { _cache = new MemoryCacheWrapper(); } #endif Version = CmsVariables.VERSION; PhysicPath = EnvUtil.GetBaseDirectory(); //获取编译生成的时间 //DateTime builtDate = new DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.Revision*2); var filePath = typeof(Cms).Assembly.Location; if (string.IsNullOrEmpty(filePath)) { filePath = PhysicPath + CmsVariables.FRAMEWORK_ASSEMBLY_PATH + "jrcms.dll"; } var builtDate = File.GetLastWriteTime(filePath); BuiltTime = DateHelper.ToUnix(builtDate); //获取平台 var platFormId = (int)Environment.OSVersion.Platform; if (platFormId == 4 || platFormId == 6 || platFormId == 128) { RunAtMono = true; } //初始化 //todo: plugin //Plugins = new CmsPluginContext(); // 初始化缓存工厂 CmsCacheFactory.Configure(_cache); CacheFactory.Configure(_cache); // 初始化模板 Template = new CmsTemplate(_cache, TemplateNames.FileName); Cache = new CmsCache(CmsCacheFactory.Singleton); // 初始化内存缓存 Utility = new CmsUtility(); Language = new CmsLanguagePackage(); #region 缓存清除 // //UNDONE: 弱引用 // /* * WeakRefCache.OnLinkBuilting += () => * { * Cms.Cache.Clear(CacheSign.Link.ToString()); * }; * * WeakRefCache.OnModuleBuilting += () => * { * Cms.Cache.Clear(CacheSign.Module.ToString()); * }; * * WeakRefCache.OnPropertyBuilting += () => * { * Cms.Cache.Clear(CacheSign.Property.ToString()); * }; * * WeakRefCache.OnTemplateBindBuilting += () => * { * Cms.Cache.Clear(CacheSign.TemplateBind.ToString()); * }; * */ #endregion }
static Cms() { Version = CmsVariables.VERSION; PyhicPath = AppDomain.CurrentDomain.BaseDirectory; //获取编译生成的时间 //Version ver=typeof(Cms).Assembly.GetName().Version; //BuiltTime= new DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.Revision * 2); //BuiltTime=System.IO.File.GetLastWriteTime(typeof(Cms).Assembly.Location); //获取平台 Int32 platFormId = (Int32)Environment.OSVersion.Platform; if (platFormId == 4 || platFormId == 6 || platFormId == 128) { RunAtMono = true; } //判断是否已经安装 FileInfo insLockFile = new FileInfo(String.Format("{0}config/install.lock", Cms.PyhicPath)); Installed = insLockFile.Exists; //初始化 Plugins = new CmsPluginContext(); Template = new CmsTemplate(); Cache = CacheFactory.Sington as CmsCache; Utility = new CmsUtility(); #region 缓存清除 // //UNDONE: 弱引用 // /* WeakRefCache.OnLinkBuilting += () => { Cms.Cache.Clear(CacheSign.Link.ToString()); }; WeakRefCache.OnModuleBuilting += () => { Cms.Cache.Clear(CacheSign.Module.ToString()); }; WeakRefCache.OnPropertyBuilting += () => { Cms.Cache.Clear(CacheSign.Property.ToString()); }; WeakRefCache.OnTemplateBindBuilting += () => { Cms.Cache.Clear(CacheSign.TemplateBind.ToString()); }; */ #endregion }
/// <summary> /// Runs the command. /// </summary> /// <param name="commandName">Name of the command.</param> private void RunCommand(string commandName) { FileSystemResourceProvider prov = (FileSystemResourceProvider)ResourceHandler.ResourceHandler.ResourceProvider; { //EXIT FROM DESIGN-MODE if (commandName == "Cancel") { // delete temp pagedocument DeleteFromTemp(); this.ViewState.Clear(); CMSContext.Current.IsDesignMode = false; //back to prev page if (Request.QueryString["PrevVersionId"] != null) { NameValueCollection vals = new NameValueCollection(); if (Int32.Parse(Request.QueryString["PrevVersionId"]) > 0) { vals.Add("VersionId", Request.QueryString["PrevVersionId"]); } else { vals.Add("VersionId", ""); } string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals); Response.Redirect(url); //Response.Redirect("~" + CMSContext.Current.Outline + "?VersionId=" + Request.QueryString["PrevVersionId"]); } else { Response.Redirect(Request.RawUrl, true); } } //ENTER DESIGN-MODE if (commandName == "Edit") { //GA: delete temp pagedocument DeleteFromTemp(); // Check if we have access to the current version, if not, the new version for a current language will // need to be created for "edit" command if (!PageHelper.HasLanguageVersion(CMSContext.Current.PageId, LanguageId, CMSContext.Current.VersionId)) { // add new version _CommandValue.Value = String.Format("{0},{1}", CMSContext.Current.PageId, LanguageId); RunCommand("AddVersion"); } //back to prev page if (Request.QueryString["PrevVersionId"] != null) { NameValueCollection vals = new NameValueCollection(); vals.Add("PrevVersionId", Request.QueryString["PrevVersionId"]); string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals); Response.Redirect(url); //Response.Redirect("~" + CMSContext.Current.Outline + "?VersionId=" + Request.QueryString["PrevVersionId"]); } else { Response.Redirect(Request.RawUrl, true); } } //SAVE AS DRAFT if (commandName == "SaveDraft") { if (CMSContext.Current.VersionId == -2) { CMSContext.Current.VersionId = PageVersion.AddDraft(CMSContext.Current.PageId, CMSContext.Current.TemplateId, LanguageId, (Guid)ProfileContext.Current.User.ProviderUserKey); PageDocument.Current.PageVersionId = CMSContext.Current.VersionId; //copy resources DirectoryInfo resDir = new DirectoryInfo(MapPath("~/" + prov.Archive + "/" + ProfileContext.Current.User.UserName + "/")); CommonHelper.CopyDirectory(resDir.FullName, MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/")); if (resDir.Exists) { resDir.Delete(true); } } PageDocument.Current.IsModified = true; using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId)) { if (reader.Read()) { int verId = -1; bool addVersion = false; using (IDataReader r = PageVersion.GetVersionById(CMSContext.Current.VersionId)) { if (r.Read()) { addVersion = (int)r["StatusId"] != -1; if (!addVersion) { verId = CMSContext.Current.VersionId; PageVersion.UpdatePageVersion(verId, (int)r["TemplateId"], (int)r["LangId"], -1, WorkflowStatus.DraftId, (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty); } } r.Close(); } if (addVersion) { verId = PageVersion.AddPageVersion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty); using (IDataReader reader2 = PageVersion.GetVersionById(verId)) { if (reader2.Read()) { PageVersion.UpdatePageVersion(verId, (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.DraftId, (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty); } reader2.Close(); } //copy resources //todo: feature suspended, reimplement in the future //CommonHelper.CopyDirectory(MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/"), MapPath("~/" + prov.Archive + "/" + verId.ToString() + "/")); CMSContext.Current.VersionId = verId; } } reader.Close(); } //SAVE DRAFT TO PERSIST STORAGE PageDocument.Current.Save(CMSContext.Current.VersionId, SaveMode.PersistentStorage, Guid.Empty); PageDocument.Current.ResetModified(); //delete from temporary storage DeleteFromTemp(); this.ViewState.Clear(); //SWITCH TO VIEW MODE EnableViewMode(); RedirectToNewPage(); } //PUBLISH if (commandName == "Publish") { bool firstVersion = false; if (CMSContext.Current.VersionId == -2) { firstVersion = true; CMSContext.Current.VersionId = PageVersion.AddDraft(CMSContext.Current.PageId, CMSContext.Current.TemplateId, LanguageId, (Guid)ProfileContext.Current.User.ProviderUserKey); PageDocument.Current.PageVersionId = CMSContext.Current.VersionId; //copy resources DirectoryInfo resDir = new DirectoryInfo(MapPath("~/" + prov.Archive + "/" + ProfileContext.Current.User.UserName + "/")); CommonHelper.CopyDirectory(resDir.FullName, MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/")); if (resDir.Exists) { resDir.Delete(true); } } using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId)) { if (reader.Read()) { int langId = (int)reader["LangId"]; if (WorkflowStatus.GetNext((int)reader["StatusId"]) != -1 || (int)reader["StatusId"] == -1) { PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty); } // if we publish version if (WorkflowStatus.GetLast((int)reader["StatusId"]) == WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"]))) { //find old published and put to archive using (IDataReader reader2 = PageVersion.GetVersionByStatusId((int)reader["PageId"], WorkflowStatus.GetLast((int)reader["StatusId"]))) { while (reader2.Read()) { if ((int)reader2["LangId"] == langId) { if (CMSContext.Current.VersionId != (int)reader2["VersionId"]) { PageVersion.UpdatePageVersion((int)reader2["VersionId"], (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.GetArcStatus((int)reader2["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 2, "sent to archieve"); } } } reader2.Close(); } } } reader.Close(); } //SAVE TO PERSIST STORAGE PageDocument.Current.Save(CMSContext.Current.VersionId, SaveMode.PersistentStorage, Guid.Empty); PageDocument.Current.ResetModified(); //delete from temporary storage DeleteFromTemp(); this.ViewState.Clear(); //SWITCH TO VIEW MODE EnableViewMode(); // replace VersionId in query string with a new id string url = Request.RawUrl; if (firstVersion) { // if the page has just been created and is being published, need to remove "VersionId=-2" from the queryString to load published version NameValueCollection vals = new NameValueCollection(); vals.Add("VersionId", String.Empty); url = CommonHelper.FormatQueryString(url, vals); } Response.Redirect(url, true); } if (commandName == "Approve") { using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId)) { if (reader.Read()) { PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, /*ddText.TextValue*/ ""); int langId = (int)reader["langId"]; // if we publish version if (WorkflowStatus.GetLast((int)reader["StatusId"]) == WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"]))) { //find old publishd and put to archive using (IDataReader reader2 = PageVersion.GetVersionByStatusId((int)reader["PageId"], WorkflowStatus.GetLast((int)reader["StatusId"]))) { while (reader2.Read()) { if (langId == (int)reader2["LangId"]) { if (CMSContext.Current.VersionId != (int)reader2["VersionId"]) { PageVersion.UpdatePageVersion((int)reader2["VersionId"], (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.GetArcStatus((int)reader2["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, "Archieved"); } } } reader2.Close(); } } //PageVersion.DeletePageVersion(CMSContext.Current.VersionId); //PageVersion.AddPageVerion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)Membership.GetUser(Page.User.Identity.Name).ProviderUserKey, 1, ddText.TextValue); } reader.Close(); } Response.Redirect(Request.RawUrl, true); //RedirectToNewPage(); } if (commandName == "Deny") { using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId)) { if (reader.Read()) { PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowStatus.GetPrevious((int)reader["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 2, /*ddText.TextValue*/ ""); //PageVersion.AddPageVerion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)Membership.GetUser(Page.User.Identity.Name).ProviderUserKey, 1, ddText.TextValue); } reader.Close(); } string url = Page.Request.Url.ToString(); if (!url.Contains("VersionId")) { NameValueCollection vals = new NameValueCollection(); vals.Add("VersionId", CMSContext.Current.VersionId.ToString()); url = CommonHelper.FormatQueryString(url, vals); Response.Redirect(url); } } if (commandName == "ChangeTemplate") { // Clear cache CmsCache.Clear(); CMSContext mcContext = CMSContext.Current; using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId)) { if (reader.Read()) { int pageTemplateId; if (Int32.TryParse(_CommandValue.Value, out pageTemplateId)) { PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, int.Parse(_CommandValue.Value), this.LanguageId, (int)reader["StatusId"], (int)reader["StatusId"], (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty); } } reader.Close(); } if (mcContext.VersionId == -2) { NameValueCollection vals = new NameValueCollection(); vals.Add("TemplateId", _CommandValue.Value); string url = CommonHelper.FormatQueryString(Request.RawUrl, vals); Response.Redirect(url, true); } else { Response.Redirect(Request.RawUrl, true); } } if (commandName == "AddVersion") { string separator = ","; int pageId = int.Parse(_CommandValue.Value.Split(separator.ToCharArray())[0]); int langId = int.Parse(_CommandValue.Value.Split(separator.ToCharArray())[1]); string currentCulture = "en-us"; using (IDataReader reader = Language.LoadLanguage(langId)) { if (reader.Read()) { currentCulture = (string)reader["LangName"]; } reader.Close(); } NameValueCollection vals = new NameValueCollection(); vals.Add("lang", currentCulture); vals.Add("VersionId", "-2"); vals.Add("PrevVersionId", CMSContext.Current.VersionId.ToString()); string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals); Response.Redirect(url); } return; } }
/// <summary> /// Loads the published version context. /// </summary> /// <param name="loadDefaults">if set to <c>true</c> [load defaults].</param> private void LoadPublishedVersionContext(bool loadDefaults) { //GET PUBLISHED VERSION int statusId = WorkflowStatus.GetLast(); string cacheKey = CmsCache.CreateCacheKey("page-published", CMSContext.Current.PageId.ToString(), statusId.ToString(), loadDefaults.ToString(), Thread.CurrentThread.CurrentCulture.Name); // check cache first object cachedObject = CmsCache.Get(cacheKey); int[] versionArray = null; if (cachedObject != null) { versionArray = (int[])cachedObject; } // Load the object if (versionArray == null) { lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { versionArray = (int[])cachedObject; } else { //using (IDataReader reader = PageVersion.GetByLangIdAndStatusId(CMSContext.Current.PageId, LanguageId, statusId)) using (IDataReader reader = PageVersion.GetVersionByStatusId(CMSContext.Current.PageId, statusId)) { while (reader.Read()) { // Load first language that we encounter, possibly should be the default language if (CMSContext.Current.VersionId == -1 && loadDefaults) { versionArray = new int[] { (int)reader["VersionId"], (int)reader["TemplateId"] }; } if ((int)reader["LangId"] == LanguageId) { versionArray = new int[] { (int)reader["VersionId"], (int)reader["TemplateId"] }; break; } } reader.Close(); } CmsCache.Insert(cacheKey, versionArray, CmsConfiguration.Instance.Cache.PageDocumentTimeout); } } } // Populate info from version array if (versionArray != null) { CMSContext.Current.VersionId = versionArray[0]; CMSContext.Current.TemplateId = versionArray[1]; } }
/// <summary> /// Returns an instance of a class that implements the <see cref="T:System.Web.IHttpHandler"></see> interface. /// </summary> /// <param name="context">An instance of the <see cref="T:System.Web.HttpContext"></see> class that provides references to intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> /// <param name="requestType">The HTTP data transfer method (GET or POST) that the client uses.</param> /// <param name="url">The <see cref="P:System.Web.HttpRequest.RawUrl"></see> of the requested resource.</param> /// <param name="pathTranslated">The <see cref="P:System.Web.HttpRequest.PhysicalApplicationPath"></see> to the requested resource.</param> /// <returns> /// A new <see cref="T:System.Web.IHttpHandler"></see> object that processes the request. /// </returns> public IHttpHandler GetHandler( HttpContext context, string requestType, string url, string pathTranslated) { if (url.EndsWith("logout.aspx")) { FormsAuthentication.SignOut(); context.Response.Redirect(CMSContext.Current.ResolveUrl("~")); context.Response.End(); } string outline = url; if (CMSContext.Current.AppPath.Length != 1) { outline = outline.Substring(CMSContext.Current.AppPath.Length); } // Outline must start with "/", so add it if we are missing if (!outline.StartsWith("/", StringComparison.Ordinal)) { outline = "/" + outline; } // Set the outline CMSContext.Current.Outline = outline; // Load current outline bool isFolder = false; int folderId = 0; int pageId = -1; string masterFile = String.Empty; string cacheKey = CmsCache.CreateCacheKey("filetree", CMSContext.Current.SiteId.ToString(), outline); DataTable fileTreeItemTable = null; // check cache first object cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { fileTreeItemTable = (DataTable)cachedObject; } if (fileTreeItemTable == null) { lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { fileTreeItemTable = (DataTable)cachedObject; } else { fileTreeItemTable = FileTreeItem.GetItemByOutlineAllDT(outline, CMSContext.Current.SiteId); if (fileTreeItemTable.Rows.Count > 0) { CmsCache.Insert(cacheKey, fileTreeItemTable, CmsConfiguration.Instance.Cache.PageDocumentTimeout); } } } } if (fileTreeItemTable != null && fileTreeItemTable.Rows.Count > 0) { DataRow row = fileTreeItemTable.Rows[0]; folderId = (int)row[0]; CMSContext.Current.PageId = folderId; isFolder = (bool)row[4]; masterFile = (string)row[8]; if (String.Compare(outline, (string)row[2], true, CultureInfo.InvariantCulture) == 0) { pageId = (int)row[0]; } } /* * using (IDataReader reader = FileTreeItem.GetItemByOutlineAll(outline, CMSContext.Current.SiteId)) * { * if (reader.Read()) * { * folderId = reader.GetInt32(0); * CMSContext.Current.PageId = folderId; * isFolder = reader.GetBoolean(4); * masterFile = reader.GetString(8); * if (String.Compare(outline, reader.GetString(2), true, CultureInfo.InvariantCulture) == 0) * { * pageId = reader.GetInt32(0); * } * } * * reader.Close(); * } * */ //if (FileTreeItem.IsVirtual(outline)) if (pageId != -1) // is this folder/page virtual? { // If URL is not rewritten, then save the one originally requested if (!CMSContext.Current.IsUrlReWritten) { CMSContext.Current.IsUrlReWritten = true; if (HttpContext.Current.Request.QueryString.Count == 0) { CMSContext.Current.CurrentUrl = url; } else { CMSContext.Current.CurrentUrl = String.Format(url + "?" + HttpContext.Current.Request.QueryString); } } /* * bool isFolder = false; * int folderId = 0; * string masterFile = String.Empty; * * using (IDataReader reader = FileTreeItem.GetItemByOutlineAll(outline, CMSContext.Current.SiteId)) * { * if (reader.Read()) * { * folderId = reader.GetInt32(0); * isFolder = reader.GetBoolean(4); * masterFile = reader.GetString(8); * } * } * */ if (!isFolder) { Uri rawUrl = BuildUri(String.Format("~/template.aspx"), HttpContext.Current.Request.IsSecureConnection); string filePath; string sendToUrlLessQString; string sendToUrl = rawUrl.PathAndQuery; RewriteUrl(context, sendToUrl, out sendToUrlLessQString, out filePath); return(PageParser.GetCompiledPageInstance(sendToUrlLessQString, filePath, context)); } else { string newUrl = String.Empty; //try to find default page for folder using (IDataReader reader = FileTreeItem.GetFolderDefaultPage(folderId)) { if (reader.Read()) { newUrl = Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath(reader.GetString(2)); } else { reader.Close(); throw new HttpException(204, "Default page for folder not found"); } reader.Close(); } Uri rawUrl = BuildUri(newUrl, HttpContext.Current.Request.IsSecureConnection); string filePath; string sendToUrlLessQString; string sendToUrl = rawUrl.PathAndQuery; RewriteUrl(context, sendToUrl, out sendToUrlLessQString, out filePath); return(PageParser.GetCompiledPageInstance(sendToUrlLessQString, filePath, context)); } } else if (!string.IsNullOrEmpty(pathTranslated)) { return(PageParser.GetCompiledPageInstance(url, pathTranslated, context)); } else { return (PageParser.GetCompiledPageInstance( url, context.Server.MapPath("~"), context)); } }
/// <summary> /// Opens the specified pagedocument. /// </summary> /// <param name="pageVersionId">The page version id.</param> /// <param name="openMode">The open mode.</param> /// <param name="userUID">The user UID.</param> /// <returns></returns> public static PageDocument Open(int pageVersionId, OpenMode openMode, Guid userUID) { PageDocument pDocument = null; string cacheKey = CmsCache.CreateCacheKey("pagedocument", pageVersionId.ToString(), userUID.ToString()); // Check cache first if (openMode == OpenMode.View) // only use cache in view mode { // check cache first object cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { pDocument = (PageDocument)cachedObject; return(pDocument); } } int pageDocumentId = -1; //CHECK using (IDataReader reader = Database.PageDocument.GetByPageVersionId(pageVersionId)) { //EXIST PD if (reader.Read()) { pageDocumentId = (int)reader["PageId"]; } //CREATE NEW PD else { pageDocumentId = Database.PageDocument.Add(pageVersionId); Database.Node.Add(pageDocumentId, (int)Database.NodeType.Type.StaticNode, "StaticNode", "", "", "", 0); } reader.Close(); } if (pageDocumentId > 0) { switch (openMode) { case OpenMode.Design: //load from temp storage pDocument = _temporaryDocumentStorage.Load(pageVersionId, userUID); //create temp page document if (pDocument == null && pageVersionId == -2) { pDocument = new PageDocument(); pDocument.PageVersionId = -2; } //load from persist storage if (pDocument == null) { pDocument = _persistentDocumentStorage.Load(pageVersionId, Guid.Empty); } break; case OpenMode.View: pDocument = _persistentDocumentStorage.Load(pageVersionId, Guid.Empty); // Insert to the cache collection CmsCache.Insert(cacheKey, pDocument, CmsConfiguration.Instance.Cache.PageDocumentTimeout); break; default: throw new ArgumentNullException(); } //_current = pDocument; return(pDocument); } return(null); }