示例#1
0
        private static Collection <PageSettings> GetMenuPagesFromCache()
        {
            // 2008-09-06 realized we are caching 2 copies of pages because we cache it here but also the SiteMap itself is cached
            // since sitemap is cached there is no need to cache this collection, it was just using memory to cache it but not really helping performance
            // if we find out the caching was beneficial we can turn it back on with this config setting
            bool cachePagesForMenu = ConfigHelper.GetBoolProperty("CachePagesForMenu", false);

            if (!cachePagesForMenu)
            {
                return(LoadMenuPages());
            }

            string cachekey;
            bool   useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);

            if (useFolderForSiteDetection)
            {
                string siteFolderName = VirtualFolderEvaluator.VirtualFolderName();
                if (siteFolderName.Length == 0)
                {
                    siteFolderName = "root";
                }
                cachekey = "MenuPages_" + siteFolderName;
            }
            else
            {
                String hostName = WebUtils.GetHostName();
                cachekey = "MenuPages_" + hostName;
            }

            if (HttpRuntime.Cache[cachekey] == null)
            {
                TouchMenuCacheDependencyFile();

                int cacheTimeout = 360;
                if (ConfigurationManager.AppSettings["MenuCacheDurationInSeconds"] != null)
                {
                    cacheTimeout = int.Parse(ConfigurationManager.AppSettings["MenuCacheDurationInSeconds"]);
                }

                RefreshMenuCache(cachekey, cacheTimeout);
            }

            return(HttpRuntime.Cache[cachekey] as Collection <PageSettings>);
        }
示例#2
0
        private static SiteSettings GetSiteSettingsFromCache()
        {
            bool   useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);
            string cachekey;

            if (useFolderForSiteDetection)
            {
                string siteFolderName = VirtualFolderEvaluator.VirtualFolderName();
                if (siteFolderName.Length == 0)
                {
                    siteFolderName = "root";
                }
                cachekey = "SiteSettings_" + siteFolderName;
            }
            else
            {
                String hostName = WebUtils.GetHostName();
                cachekey = "SiteSettings_" + hostName;
            }

            if (HttpRuntime.Cache[cachekey] == null)
            {
                int  cacheTimeout;
                bool loadFromWebConfigSucceeded =
                    int.TryParse(ConfigurationManager.AppSettings["SiteSettingsCacheDurationInSeconds"], out cacheTimeout);
                if (!loadFromWebConfigSucceeded)
                {
                    cacheTimeout = 120;
                }

                RefreshSiteSettingsCache(cachekey, cacheTimeout);
            }

            // Return SiteSettings object from cache, or null if it is not there for some reason
            return(HttpRuntime.Cache[cachekey] as SiteSettings);
        }
示例#3
0
        private static Collection <PageSettings> LoadMenuPages()
        {
            Collection <PageSettings> menuPages
                = new Collection <PageSettings>();

            SiteSettings siteSettings = GetCurrentSiteSettings();

            if (siteSettings == null)
            {
                return(menuPages);
            }

            bool useFolderForSiteDetection
                = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);
            string virtualFolder;

            if (useFolderForSiteDetection)
            {
                virtualFolder = VirtualFolderEvaluator.VirtualFolderName();
            }
            else
            {
                virtualFolder = string.Empty;
            }


            using (IDataReader reader = PageSettings.GetPageList(siteSettings.SiteId))
            {
                int i = 0;
                while (reader.Read())
                {
                    PageSettings pageDetails = new PageSettings();
                    pageDetails.SiteId               = siteSettings.SiteId;
                    pageDetails.PageId               = Convert.ToInt32(reader["PageID"]);
                    pageDetails.ParentId             = Convert.ToInt32(reader["ParentID"]);
                    pageDetails.PageName             = reader["PageName"].ToString();
                    pageDetails.MenuImage            = reader["MenuImage"].ToString();
                    pageDetails.PageOrder            = Convert.ToInt32(reader["PageOrder"]);
                    pageDetails.AuthorizedRoles      = reader["AuthorizedRoles"].ToString();
                    pageDetails.EditRoles            = reader["EditRoles"].ToString();
                    pageDetails.DraftEditOnlyRoles   = reader["DraftEditRoles"].ToString();
                    pageDetails.CreateChildPageRoles = reader["CreateChildPageRoles"].ToString();


                    pageDetails.UseUrl             = Convert.ToBoolean(reader["UseUrl"]);
                    pageDetails.Url                = reader["Url"].ToString();
                    pageDetails.IncludeInMenu      = Convert.ToBoolean(reader["IncludeInMenu"]);
                    pageDetails.IncludeInSiteMap   = Convert.ToBoolean(reader["IncludeInSiteMap"]);
                    pageDetails.IncludeInSearchMap = Convert.ToBoolean(reader["IncludeInSearchMap"]);
                    pageDetails.IsClickable        = Convert.ToBoolean(reader["IsClickable"]);
                    pageDetails.ShowHomeCrumb      = Convert.ToBoolean(reader["ShowHomeCrumb"]);
                    pageDetails.RequireSsl         = Convert.ToBoolean(reader["RequireSSL"]);

                    if (
                        (useFolderForSiteDetection) &&
                        (virtualFolder.Length > 0) &&
                        (pageDetails.Url.StartsWith("~/"))
                        )
                    {
                        pageDetails.Url
                            = pageDetails.Url.Replace("~/", "~/" + virtualFolder + "/");
                    }

                    if (
                        (useFolderForSiteDetection) &&
                        (virtualFolder.Length > 0) &&
                        (!pageDetails.UseUrl)
                        )
                    {
                        pageDetails.Url
                            = "~/" + virtualFolder + "/Default.aspx?pageid="
                              + pageDetails.PageId.ToString();
                        pageDetails.UseUrl = true;
                    }


                    pageDetails.OpenInNewWindow          = Convert.ToBoolean(reader["OpenInNewWindow"]);
                    pageDetails.ShowChildPageMenu        = Convert.ToBoolean(reader["ShowChildPageMenu"]);
                    pageDetails.ShowChildPageBreadcrumbs = Convert.ToBoolean(reader["ShowChildBreadCrumbs"]);
                    pageDetails.PageIndex = i;

                    string cf = reader["ChangeFrequency"].ToString();
                    switch (cf)
                    {
                    case "Always":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Always;
                        break;

                    case "Hourly":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Hourly;
                        break;

                    case "Daily":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Daily;
                        break;

                    case "Monthly":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Monthly;
                        break;

                    case "Yearly":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Yearly;
                        break;

                    case "Never":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Never;
                        break;

                    case "Weekly":
                    default:
                        pageDetails.ChangeFrequency = PageChangeFrequency.Weekly;
                        break;
                    }

                    string smp = reader["SiteMapPriority"].ToString().Trim();
                    if (smp.Length > 0)
                    {
                        pageDetails.SiteMapPriority = smp;
                    }

                    if (reader["LastModifiedUTC"] != DBNull.Value)
                    {
                        pageDetails.LastModifiedUtc = Convert.ToDateTime(reader["LastModifiedUTC"]);
                    }

                    pageDetails.PageGuid   = new Guid(reader["PageGuid"].ToString());
                    pageDetails.ParentGuid = new Guid(reader["ParentGuid"].ToString());


                    pageDetails.HideAfterLogin = Convert.ToBoolean(reader["HideAfterLogin"]);

                    pageDetails.SiteGuid     = new Guid(reader["SiteGuid"].ToString());
                    pageDetails.CompiledMeta = reader["CompiledMeta"].ToString();
                    if (reader["CompiledMetaUtc"] != DBNull.Value)
                    {
                        pageDetails.CompiledMetaUtc = Convert.ToDateTime(reader["CompiledMetaUtc"]);
                    }

                    pageDetails.IsPending = Convert.ToBoolean(reader["IsPending"]);

                    menuPages.Add(pageDetails);
                    i++;
                }
            }

            return(menuPages);
        }
示例#4
0
        private static PageSettings LoadCurrentPage()
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("CacheHelper.cs LoadCurrentPage");
            }

            int pageID = WebUtils.ParseInt32FromQueryString("pageid", -1);

            SiteSettings siteSettings = GetCurrentSiteSettings();

            if (siteSettings == null)
            {
                return(null);
            }

            bool useFolderForSiteDetection
                = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);
            string virtualFolder;

            if (useFolderForSiteDetection)
            {
                virtualFolder = VirtualFolderEvaluator.VirtualFolderName();
            }
            else
            {
                virtualFolder = string.Empty;
            }


            PageSettings currentPage = new PageSettings(siteSettings.SiteId, pageID);

            if (currentPage.SiteId != siteSettings.SiteId)
            {   // probably url manipulation trying to use a pageid that
                // doesn't belong to the site so just return the home page
                currentPage = new PageSettings(siteSettings.SiteId, -1);
            }

            //if (currentPage.SiteID != siteSettings.SiteID)
            //{
            //    // throwing exceptions is bad for performance, just redirect
            //    if (HttpContext.Current != null) WebUtils.SetupRedirect(null, WebUtils.GetSiteRoot());
            //    return null;
            //}

            if (
                (useFolderForSiteDetection) &&
                (virtualFolder.Length > 0) &&
                (currentPage.Url.StartsWith("~/"))
                )
            {
                currentPage.Url
                    = currentPage.Url.Replace("~/", "~/" + virtualFolder + "/");

                currentPage.UrlHasBeenAdjustedForFolderSites = true;
            }

            if (
                (useFolderForSiteDetection) &&
                (virtualFolder.Length > 0) &&
                (!currentPage.UseUrl)
                )
            {
                currentPage.Url
                    = "~/" + virtualFolder + "/Default.aspx?pageid="
                      + currentPage.PageId.ToString();
                currentPage.UseUrl = true;
                currentPage.UrlHasBeenAdjustedForFolderSites = true;
            }


            using (IDataReader reader = Module.GetPageModules(currentPage.PageId))
            {
                while (reader.Read())
                {
                    Module m = new Module();
                    m.ModuleId            = Convert.ToInt32(reader["ModuleID"]);
                    m.ModuleGuid          = new Guid(reader["Guid"].ToString());
                    m.ModuleDefId         = Convert.ToInt32(reader["ModuleDefID"]);
                    m.PageId              = Convert.ToInt32(reader["PageID"]);
                    m.PaneName            = reader["PaneName"].ToString();
                    m.ModuleTitle         = reader["ModuleTitle"].ToString();
                    m.ViewRoles           = reader["ViewRoles"].ToString();
                    m.AuthorizedEditRoles = reader["AuthorizedEditRoles"].ToString();
                    m.DraftEditRoles      = reader["DraftEditRoles"].ToString();
                    m.CacheTime           = Convert.ToInt32(reader["CacheTime"]);
                    m.ModuleOrder         = Convert.ToInt32(reader["ModuleOrder"]);

                    m.HideFromAuthenticated   = Convert.ToBoolean(reader["HideFromAuth"]);
                    m.HideFromUnauthenticated = Convert.ToBoolean(reader["HideFromUnAuth"]);

                    if (reader["EditUserID"] != DBNull.Value)
                    {
                        m.EditUserId = Convert.ToInt32(reader["EditUserID"]);
                    }

                    string showTitle = reader["ShowTitle"].ToString();
                    m.ShowTitle     = (showTitle == "True" || showTitle == "1");
                    m.ControlSource = reader["ControlSrc"].ToString();


                    currentPage.Modules.Add(m);
                }
            }

            return(currentPage);
        }
示例#5
0
        private static SiteSettings LoadSiteSettings()
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("CacheHelper.cs LoadSiteSettings");
            }

            SiteSettings siteSettings = null;

            try
            {
                bool useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);

                string siteFolderName;
                if (useFolderForSiteDetection)
                {
                    siteFolderName = VirtualFolderEvaluator.VirtualFolderName();
                }
                else
                {
                    siteFolderName = string.Empty;
                }

                if (useFolderForSiteDetection)
                {
                    Guid siteGuid = SiteFolder.GetSiteGuid(siteFolderName);
                    siteSettings = new SiteSettings(siteGuid);
                }
                else
                {
                    siteSettings = new SiteSettings(WebUtils.GetHostName());
                }

                if (siteSettings.SiteId > -1)
                {
                    siteSettings.SiteRoot = WebUtils.GetSiteRoot();
                    if (useFolderForSiteDetection)
                    {
                        siteSettings.SiteFolderName = siteFolderName;
                    }
                    SetCurrentSkinBaseUrl(siteSettings);
                }
                else
                {
                    siteSettings = null;
                    log.Error("CacheHelper failed to load siteSettings");
                }
            }
            catch (System.Data.Common.DbException ex)
            {
                log.Error("Error trying to obtain siteSettings", ex);
            }
            catch (InvalidOperationException ex)
            {
                log.Error("Error trying to obtain siteSettings", ex);
            }
            catch (IndexOutOfRangeException ex)
            {
                log.Error("Error trying to obtain siteSettings", ex);
            }

            return(siteSettings);
        }