/// <summary> /// Read the Path dir and returns an ArrayList with all the Layouts found. /// Static because the list is Always the same. /// </summary> /// <returns> /// A list of public layouts. /// </returns> public static List <LayoutItem> GetPublicLayouts() { // Jes1111 - 27-02-2005 - new version - correct caching List <LayoutItem> baseLayoutList; if (!CurrentCache.Exists(Key.LayoutList(Path))) { // Try to read directories from public Layout path var layouts = Directory.Exists(Path) ? Directory.GetDirectories(Path) : new string[0]; // Ignore CVS and SVN baseLayoutList = layouts.Select(layout => new LayoutItem { Name = layout.Substring(Path.Length + 1) }) .Where(layout => layout.Name != "CVS" && layout.Name != "_svn" && layout.Name != ".svn") .ToList(); CurrentCache.Insert(Key.LayoutList(Path), baseLayoutList, new CacheDependency(Path)); } else { baseLayoutList = (List <LayoutItem>)CurrentCache.Get(Key.LayoutList(Path)); } return(baseLayoutList); }
/// <summary> /// Read the Path dir and returns an ArrayList with all the Themes found. /// Static because the list is Always the same. /// </summary> /// <returns> /// A list of theme items. /// </returns> public static List <ThemeItem> GetPublicThemes() { List <ThemeItem> baseThemeList; if (!CurrentCache.Exists(Key.ThemeList(Path))) { // Initialize array // Try to read directories from public theme path var themes = Directory.Exists(Path) ? Directory.GetDirectories(Path) : new string[0]; // Ignore CVS and SVN. baseThemeList = themes.Select(t1 => new ThemeItem { Name = t1.Substring(Path.Length + 1) }).Where( t => t.Name != "CVS" && t.Name != "_svn").ToList(); CurrentCache.Insert(Key.ThemeList(Path), baseThemeList, new CacheDependency(Path)); } else { baseThemeList = (List <ThemeItem>)CurrentCache.Get(Key.ThemeList(Path)); } return(baseThemeList); }
private static GeographicProvider GetCurrentObject() { // Get the names of providers var config = ProviderConfiguration.GetProviderConfiguration(ProviderType); // Read specific configuration information for this provider var providerSettings = (ProviderSettings)config.Providers[config.DefaultProvider]; // In the cache? var cacheKey = "Appleseed::Web::GeographicProvider::" + config.DefaultProvider; if (CurrentCache[cacheKey] == null) { // The assembly should be in \bin or GAC, so we simply need // to get an instance of the type try { CurrentCache.Insert( cacheKey, ProviderHelper.InstantiateProvider(providerSettings, typeof(GeographicProvider))); } catch (Exception e) { throw new Exception("Unable to load provider", e); } } return((GeographicProvider)CurrentCache[cacheKey]); }
/// <summary> /// The GetModuleSettings Method returns a hashtable of /// custom module specific settings from the database. This method is /// used by some user control modules to access misc settings. /// </summary> /// <param name="moduleID">The module ID.</param> /// <param name="_baseSettings">The _base settings.</param> /// <returns></returns> public static Hashtable GetModuleSettings(int moduleID, Hashtable _baseSettings) { if (!CurrentCache.Exists(Key.ModuleSettings(moduleID))) { // Get Settings for this module from the database Hashtable _settings = new Hashtable(); // Create Instance of Connection and Command Object using (SqlConnection myConnection = Config.SqlConnectionString) { using (SqlCommand myCommand = new SqlCommand("rb_GetModuleSettings", myConnection)) { // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC SqlParameter parameterModuleID = new SqlParameter(strATModuleID, SqlDbType.Int, 4); parameterModuleID.Value = moduleID; myCommand.Parameters.Add(parameterModuleID); // Execute the command myConnection.Open(); using (SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection)) { while (dr.Read()) { _settings[dr["SettingName"].ToString()] = dr["SettingValue"].ToString(); } } } } foreach (string key in _baseSettings.Keys) { if (_settings[key] != null) { SettingItem s = ((SettingItem)_baseSettings[key]); if (_settings[key].ToString().Length != 0) { s.Value = _settings[key].ToString(); } } } CurrentCache.Insert(Key.ModuleSettings(moduleID), _baseSettings); } else { _baseSettings = (Hashtable)CurrentCache.Get(Key.ModuleSettings(moduleID)); } return(_baseSettings); }
/// <summary> /// Productses the specified tab. /// </summary> /// <param name="tab">The tab.</param> /// <returns></returns> private bool products(int tab) { if (!AutoShopDetect) { return(false); } if (!CurrentCache.Exists(Key.TabNavigationSettings(tab, "Shop"))) { PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"]; bool exists = new ModulesDB().ExistModuleProductsInPage(tab, portalSettings.PortalID); CurrentCache.Insert(Key.TabNavigationSettings(tab, "Shop"), exists); } return((bool)CurrentCache.Get(Key.TabNavigationSettings(tab, "Shop"))); }
/// <summary> /// Gets the administrative division's name in the specified language if available. It not, gets the default one. /// </summary> /// <param name="administrativeDivisionName"></param> /// <param name="c">a <code>System.Globalization.CultureInfo</code> describing the language we want the name for</param> /// <returns> /// A <code>string</code> containing the localized name. /// </returns> public override string GetAdministrativeDivisionName(string administrativeDivisionName, CultureInfo c) { var cacheKey = string.Format("ADMINISTRATIVEDIVISIONNAME_{0} - {1}", administrativeDivisionName, c.TwoLetterISOLanguageName); if (CurrentCache.Get(cacheKey) == null) { var result = this.GetLocalizedDisplayName("ADMINISTRATIVEDIVISIONNAME_" + administrativeDivisionName, c); if (string.IsNullOrEmpty(result)) { result = administrativeDivisionName; } CurrentCache.Insert(cacheKey, result); } return((string)CurrentCache.Get(cacheKey)); }
/// <summary> /// Gets the states's name in the specified language if available. It not, gets the default one. /// </summary> /// <param name="stateId"></param> /// <param name="c">a <code>System.Globalization.CultureInfo</code> describing the language we want the name for</param> /// <returns> /// A <code>string</code> containing the localized name. /// </returns> /// <exception cref="StateNotFoundException">If the state is not found</exception> public override string GetStateDisplayName(int stateId, CultureInfo c) { var cacheKey = string.Format("STATENAME_{0} - {1}", stateId, c.TwoLetterISOLanguageName); if (CurrentCache.Get(cacheKey) == null) { var result = this.GetLocalizedDisplayName("STATENAME_" + stateId, c); if (string.IsNullOrEmpty(result)) { result = this.GetState(stateId).NeutralName; } CurrentCache.Insert(cacheKey, result); } return((string)CurrentCache.Get(cacheKey)); }
/// <summary> /// Gets the display name of the country. /// </summary> /// <param name="countryId">The country id.</param> /// <param name="c">The c.</param> /// <returns></returns> public override string GetCountryDisplayName(string countryId, CultureInfo c) { var cacheKey = string.Format("COUNTRY_{0} - {1}", countryId, c.TwoLetterISOLanguageName); if (CurrentCache.Get(cacheKey) == null) { var result = this.GetLocalizedDisplayName("COUNTRY_" + countryId, c); if (string.IsNullOrEmpty(result)) { result = this.GetCountry(countryId).NeutralName; } CurrentCache.Insert(cacheKey, result); } return((string)CurrentCache.Get(cacheKey)); }
/// <summary> /// <see cref="Rainbow.Framework.Providers.Geographic.GeographicProvider.GetAdministrativeDivisionName( string, System.Globalization.CultureInfo )"/> /// </summary> public override string GetAdministrativeDivisionName(string administrativeDivisionName, System.Globalization.CultureInfo c) { string cacheKey = "ADMINISTRATIVEDIVISIONNAME_" + administrativeDivisionName + " - " + c.TwoLetterISOLanguageName; if (CurrentCache.Get(cacheKey) == null) { string result = GetLocalizedDisplayName("ADMINISTRATIVEDIVISIONNAME_" + administrativeDivisionName, c); if (string.IsNullOrEmpty(result)) { result = administrativeDivisionName; } CurrentCache.Insert(cacheKey, result); } return(( string )CurrentCache.Get(cacheKey)); }
/// <summary> /// <see cref="Rainbow.Framework.Providers.Geographic.GeographicProvider.GetStateDisplayName( int, System.Globalization.CultureInfo )"/> /// </summary> public override string GetStateDisplayName(int stateID, System.Globalization.CultureInfo c) { string cacheKey = "STATENAME_" + stateID + " - " + c.TwoLetterISOLanguageName; if (CurrentCache.Get(cacheKey) == null) { string result = GetLocalizedDisplayName("STATENAME_" + stateID, c); if (string.IsNullOrEmpty(result)) { result = this.GetState(stateID).NeutralName; } CurrentCache.Insert(cacheKey, result); } return(( string )CurrentCache.Get(cacheKey)); }
/// <summary> /// Gets the image menu. /// </summary> /// <returns> /// A System.Collections.Hashtable value... /// </returns> private Hashtable GetImageMenu() { Hashtable imageMenuFiles; if (!CurrentCache.Exists(Key.ImageMenuList(this.PortalSettings.CurrentLayout))) { imageMenuFiles = new Hashtable { { General.GetString("PAGESETTINGS_SITEDEFAULT", "(Site Default)"), string.Empty } }; var layoutManager = new LayoutManager(this.PortalPath); var menuDirectory = Path.WebPathCombine( layoutManager.PortalLayoutPath, this.PortalSettings.CurrentLayout); if (Directory.Exists(menuDirectory)) { menuDirectory = Path.WebPathCombine(menuDirectory, "menuimages"); } else { menuDirectory = Path.WebPathCombine( LayoutManager.Path, this.PortalSettings.CurrentLayout, "menuimages"); } if (Directory.Exists(menuDirectory)) { var menuImages = (new DirectoryInfo(menuDirectory)).GetFiles("*.gif"); foreach (var fi in menuImages.Where(fi => fi.Name != "spacer.gif" && fi.Name != "icon_arrow.gif")) { imageMenuFiles.Add(fi.Name, fi.Name); } } CurrentCache.Insert(Key.ImageMenuList(this.PortalSettings.CurrentLayout), imageMenuFiles, null); } else { imageMenuFiles = (Hashtable)CurrentCache.Get(Key.ImageMenuList(this.PortalSettings.CurrentLayout)); } return(imageMenuFiles); }
/// <summary> /// Read the Path dir and returns /// an ArrayList with all the Themes found, public and privates /// </summary> /// <returns></returns> public ArrayList GetPrivateThemes() { ArrayList privateThemeList; if (!CurrentCache.Exists(Key.ThemeList(PortalThemePath))) { privateThemeList = new ArrayList(); string[] themes; // Try to read directories from private theme path if (Directory.Exists(PortalThemePath)) { themes = Directory.GetDirectories(PortalThemePath); } else { themes = new string[0]; } for (int i = 0; i <= themes.GetUpperBound(0); i++) { ThemeItem t = new ThemeItem(); t.Name = themes[i].Substring(PortalThemePath.Length + 1); if (t.Name != "CVS" && t.Name != "_svn") //Ignore CVS { privateThemeList.Add(t); } } CurrentCache.Insert(Key.ThemeList(PortalThemePath), privateThemeList, new CacheDependency(PortalThemePath)); //Debug.WriteLine("Storing privateThemeList in Cache: item count is " + privateThemeList.Count.ToString()); } else { privateThemeList = (ArrayList)CurrentCache.Get(Key.ThemeList(PortalThemePath)); //Debug.WriteLine("Retrieving privateThemeList from Cache: item count is " + privateThemeList.Count.ToString()); } return(privateThemeList); }
/// <summary> /// Gets the image menu. /// </summary> /// <returns>A System.Collections.Hashtable value...</returns> private Hashtable GetImageMenu() { Hashtable imageMenuFiles; if (!CurrentCache.Exists(Key.ImageMenuList(portalSettings.CurrentLayout))) { imageMenuFiles = new Hashtable(); imageMenuFiles.Add("-Default-", string.Empty); string menuDirectory = string.Empty; LayoutManager layoutManager = new LayoutManager(PortalPath); menuDirectory = Path.WebPathCombine(layoutManager.PortalLayoutPath, portalSettings.CurrentLayout); if (Directory.Exists(menuDirectory)) { menuDirectory = Path.WebPathCombine(menuDirectory, "menuimages"); } else { menuDirectory = Path.WebPathCombine(LayoutManager.Path, portalSettings.CurrentLayout, "menuimages"); } if (Directory.Exists(menuDirectory)) { FileInfo[] menuImages = (new DirectoryInfo(menuDirectory)).GetFiles("*.gif"); foreach (FileInfo fi in menuImages) { if (fi.Name != "spacer.gif" && fi.Name != "icon_arrow.gif") { imageMenuFiles.Add(fi.Name, fi.Name); } } } CurrentCache.Insert(Key.ImageMenuList(portalSettings.CurrentLayout), imageMenuFiles, null); } else { imageMenuFiles = (Hashtable)CurrentCache.Get(Key.ImageMenuList(portalSettings.CurrentLayout)); } return(imageMenuFiles); }
/// <summary> /// Read the Path dir and returns an ArrayList with all the Themes found. /// Static because the list is Always the same. /// </summary> /// <returns></returns> public static ArrayList GetPublicThemes() { ArrayList baseThemeList; if (!CurrentCache.Exists(Key.ThemeList(Path))) { //Initialize array baseThemeList = new ArrayList(); string[] themes; // Try to read directories from public theme path if (Directory.Exists(Path)) { themes = Directory.GetDirectories(Path); } else { themes = new string[0]; } for (int i = 0; i < themes.Length; i++) { ThemeItem t = new ThemeItem(); t.Name = themes[i].Substring(Path.Length + 1); if (t.Name != "CVS" && t.Name != "_svn") //Ignore CVS and _svn folders { baseThemeList.Add(t); } } CurrentCache.Insert(Key.ThemeList(Path), baseThemeList, new CacheDependency(Path)); } else { baseThemeList = (ArrayList)CurrentCache.Get(Key.ThemeList(Path)); } return(baseThemeList); }
/// <summary> /// Read the Path dir and returns /// an ArrayList with all the Themes found, public and privates /// </summary> /// <returns> /// A list of theme items. /// </returns> public List <ThemeItem> GetPrivateThemes() { List <ThemeItem> privateThemeList; if (!CurrentCache.Exists(Key.ThemeList(this.PortalThemePath))) { privateThemeList = new List <ThemeItem>(); // Try to read directories from private theme path var themes = Directory.Exists(this.PortalThemePath) ? Directory.GetDirectories(this.PortalThemePath) : new string[0]; for (var i = 0; i <= themes.GetUpperBound(0); i++) { var t = new ThemeItem { Name = themes[i].Substring(this.PortalThemePath.Length + 1) }; // Ignore CVS and SVN if (t.Name != "CVS" && t.Name != "_svn") { privateThemeList.Add(t); } } CurrentCache.Insert( Key.ThemeList(this.PortalThemePath), privateThemeList, new CacheDependency(this.PortalThemePath)); // Debug.WriteLine("Storing privateThemeList in Cache: item count is " + privateThemeList.Count.ToString()); } else { privateThemeList = (List <ThemeItem>)CurrentCache.Get(Key.ThemeList(this.PortalThemePath)); // Debug.WriteLine("Retrieving privateThemeList from Cache: item count is " + privateThemeList.Count.ToString()); } return(privateThemeList); }
/// <summary> /// Gets module settings. /// </summary> /// <param name="moduleId"> /// The module id. /// </param> /// <param name="baseSettings"> /// The base settings. /// </param> /// <returns> /// A hash table. /// </returns> /// <remarks> /// </remarks> public static Dictionary <string, ISettingItem> GetModuleSettings( int moduleId, Dictionary <string, ISettingItem> baseSettings) { if (!CurrentCache.Exists(Key.ModuleSettings(moduleId))) { var hashtable = new Hashtable(); using (var connection = Config.SqlConnectionString) using (var command = new SqlCommand("rb_GetModuleSettings", connection)) { command.CommandType = CommandType.StoredProcedure; var parameter = new SqlParameter("@ModuleID", SqlDbType.Int, 4) { Value = moduleId }; command.Parameters.Add(parameter); connection.Open(); using (var reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { hashtable[reader["SettingName"].ToString()] = reader["SettingValue"].ToString(); } } } foreach (var key in baseSettings.Keys.Where(key => hashtable[key] != null).Where( key => hashtable[key].ToString().Length != 0)) { baseSettings[key].Value = hashtable[key]; } CurrentCache.Insert(Key.ModuleSettings(moduleId), baseSettings); return(baseSettings); } baseSettings = (Dictionary <string, ISettingItem>)CurrentCache.Get(Key.ModuleSettings(moduleId)); return(baseSettings); }
/// <summary> /// Loads the theme. /// </summary> /// <param name="CurrentWebPath">The current web path.</param> /// <returns>A bool value...</returns> private bool LoadTheme(string CurrentWebPath) { CurrentTheme.WebPath = CurrentWebPath; //if (!Rainbow.Framework.Settings.Cache.CurrentCache.Exists (Rainbow.Framework.Settings.Cache.Key.CurrentTheme(CurrentWebPath))) if (!CurrentCache.Exists(Key.CurrentTheme(CurrentTheme.Path))) { if (File.Exists(CurrentTheme.ThemeFileName)) { if (LoadXml(CurrentTheme.ThemeFileName)) { //Rainbow.Framework.Settings.Cache.CurrentCache.Insert(Rainbow.Framework.Settings.Cache.Key.CurrentTheme(CurrentWebPath), CurrentTheme, new CacheDependency(CurrentTheme.ThemeFileName)); CurrentCache.Insert(Key.CurrentTheme(CurrentTheme.Path), CurrentTheme, new CacheDependency(CurrentTheme.Path)); } else { // failed return(false); } } else { //Return fail return(false); } } else { //CurrentTheme = (Theme) Rainbow.Framework.Settings.Cache.CurrentCache.Get (Rainbow.Framework.Settings.Cache.Key.CurrentTheme(CurrentWebPath)); CurrentTheme = (Theme)CurrentCache.Get(Key.CurrentTheme(CurrentTheme.Path)); } CurrentTheme.WebPath = CurrentWebPath; return(true); }
/// <summary> /// /// </summary> /// <returns></returns> public ArrayList GetPrivateLayouts() { ArrayList privateLayoutList; if (!CurrentCache.Exists(Key.LayoutList(PortalLayoutPath))) { privateLayoutList = new ArrayList(); string[] layouts; // Try to read directories from private theme path if (Directory.Exists(PortalLayoutPath)) { layouts = Directory.GetDirectories(PortalLayoutPath); } else { layouts = new string[0]; } for (int i = 0; i <= layouts.GetUpperBound(0); i++) { LayoutItem t = new LayoutItem(); t.Name = layouts[i].Substring(PortalLayoutPath.Length + 1); if (t.Name != "CVS" && t.Name != "_svn") //Ignore CVS { privateLayoutList.Add(t); } } CurrentCache.Insert(Key.LayoutList(PortalLayoutPath), privateLayoutList, new CacheDependency(PortalLayoutPath)); } else { privateLayoutList = (ArrayList)CurrentCache.Get(Key.LayoutList(PortalLayoutPath)); } return(privateLayoutList); }
/// <summary> /// Loads the theme. /// </summary> /// <param name="currentWebPath"> /// The current web path. /// </param> /// <returns> /// A bool value... /// </returns> private bool LoadTheme(string currentWebPath) { this.currentTheme.WebPath = currentWebPath; // if (!Appleseed.Framework.Settings.Cache.CurrentCache.Exists (Appleseed.Framework.Settings.Cache.Key.CurrentTheme(CurrentWebPath))) if (!CurrentCache.Exists(Key.CurrentTheme(this.currentTheme.Path))) { if (File.Exists(this.currentTheme.ThemeFileName)) { if (this.LoadXml(this.currentTheme.ThemeFileName)) { // Appleseed.Framework.Settings.Cache.CurrentCache.Insert(Appleseed.Framework.Settings.Cache.Key.CurrentTheme(CurrentWebPath), CurrentTheme, new CacheDependency(CurrentTheme.ThemeFileName)); CurrentCache.Insert( Key.CurrentTheme(this.currentTheme.Path), this.currentTheme, new CacheDependency(this.currentTheme.Path)); } else { // failed return(false); } } else { // Return fail return(false); } } else { // CurrentTheme = (Theme) Appleseed.Framework.Settings.Cache.CurrentCache.Get (Appleseed.Framework.Settings.Cache.Key.CurrentTheme(CurrentWebPath)); this.currentTheme = (Theme)CurrentCache.Get(Key.CurrentTheme(this.currentTheme.Path)); } this.currentTheme.WebPath = currentWebPath; return(true); }
/// <summary> /// Gets the private layouts. /// </summary> /// <returns> /// A list of private layouts. /// </returns> public List <LayoutItem> GetPrivateLayouts() { List <LayoutItem> privateLayoutList; if (!CurrentCache.Exists(Key.LayoutList(this.PortalLayoutPath))) { privateLayoutList = new List <LayoutItem>(); // Try to read directories from private theme path var layouts = Directory.Exists(this.PortalLayoutPath) ? Directory.GetDirectories(this.PortalLayoutPath) : new string[0]; for (var i = 0; i <= layouts.GetUpperBound(0); i++) { var t = new LayoutItem { Name = layouts[i].Substring(this.PortalLayoutPath.Length + 1) }; // Ignore CVS if (t.Name != "CVS" && t.Name != "_svn" && t.Name != ".svn") { privateLayoutList.Add(t); } } CurrentCache.Insert( Key.LayoutList(this.PortalLayoutPath), privateLayoutList, new CacheDependency(this.PortalLayoutPath)); } else { privateLayoutList = (List <LayoutItem>)CurrentCache.Get(Key.LayoutList(this.PortalLayoutPath)); } return(privateLayoutList); }
/// <summary> /// The PageSettings.GetPageCustomSettings Method returns a hashtable of /// custom Page specific settings from the database. This method is /// used by Portals to access misc Page settings. /// </summary> /// <param name="pageID">The page ID.</param> /// <returns></returns> public Hashtable GetPageCustomSettings(int pageID) { Hashtable _baseSettings; if (!CurrentCache.Exists(Key.TabSettings(pageID))) { _baseSettings = GetPageBaseSettings(); // Get Settings for this Page from the database Hashtable _settings = new Hashtable(); // Create Instance of Connection and Command Object using (SqlConnection myConnection = Config.SqlConnectionString) { using (SqlCommand myCommand = new SqlCommand("rb_GetTabCustomSettings", myConnection)) { // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC SqlParameter parameterPageID = new SqlParameter("@TabID", SqlDbType.Int, 4); parameterPageID.Value = pageID; myCommand.Parameters.Add(parameterPageID); // Execute the command myConnection.Open(); SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); try { while (dr.Read()) { _settings[dr["SettingName"].ToString()] = dr["SettingValue"].ToString(); } } finally { dr.Close(); //by Manu, fixed bug 807858 myConnection.Close(); } } } // Thierry (Tiptopweb) // TODO : put back the cache in GetPageBaseSettings() and reset values not found in the database foreach (string key in _baseSettings.Keys) { if (_settings[key] != null) { SettingItem s = ((SettingItem)_baseSettings[key]); if (_settings[key].ToString().Length != 0) { s.Value = _settings[key].ToString(); } } else //by Manu // Thierry (Tiptopweb), see the comment in Hashtable GetPageBaseSettings() // this is not resetting key not found in the database { SettingItem s = ((SettingItem)_baseSettings[key]); //s.Value = string.Empty; 3_aug_2004 Cory Isakson. This line caused an error with booleans } } CurrentCache.Insert(Key.TabSettings(pageID), _baseSettings); } else { _baseSettings = (Hashtable)CurrentCache.Get(Key.TabSettings(pageID)); } return(_baseSettings); }
/// <summary> /// The PageSettings.GetPageCustomSettings Method returns a hash table of /// custom Page specific settings from the database. This method is /// used by Portals to access misc Page settings. /// </summary> /// <param name="pageId"> /// The page ID. /// </param> /// <returns> /// The hash table. /// </returns> public Dictionary <string, ISettingItem> GetPageCustomSettings(int pageId) { Dictionary <string, ISettingItem> baseSettings; if (CurrentCache.Exists(Key.TabSettings(pageId))) { baseSettings = (Dictionary <string, ISettingItem>)CurrentCache.Get(Key.TabSettings(pageId)); } else { baseSettings = this.GetPageBaseSettings(); // Get Settings for this Page from the database var settings = new Hashtable(); // Create Instance of Connection and Command Object using (var connection = Config.SqlConnectionString) using (var command = new SqlCommand("rb_GetTabCustomSettings", connection)) { // Mark the Command as a SPROC command.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC var parameterPageId = new SqlParameter("@TabID", SqlDbType.Int, 4) { Value = pageId }; command.Parameters.Add(parameterPageId); // Execute the command connection.Open(); var dr = command.ExecuteReader(CommandBehavior.CloseConnection); try { while (dr.Read()) { settings[dr["SettingName"].ToString()] = dr["SettingValue"].ToString(); } } finally { dr.Close(); // by Manu, fixed bug 807858 connection.Close(); } } // Thierry (Tiptopweb) // TODO : put back the cache in GetPageBaseSettings() and reset values not found in the database // REVIEW: This code is duplicated in portal settings. foreach (var key in baseSettings.Keys.Where(key => settings[key] != null).Where( key => settings[key].ToString().Length != 0)) { baseSettings[key].Value = settings[key]; } CurrentCache.Insert(Key.TabSettings(pageId), baseSettings); } return(baseSettings); }
/// <summary> /// Read the Path dir and returns an ArrayList with all the Layouts found. /// Static because the list is Always the same. /// </summary> /// <returns></returns> public static ArrayList GetPublicLayouts() { // Jes1111 - 27-02-2005 - new version - correct caching ArrayList baseLayoutList; if (!CurrentCache.Exists(Key.LayoutList(Path))) { // initialize array baseLayoutList = new ArrayList(); string[] layouts; // Try to read directories from public Layout path if (Directory.Exists(Path)) { layouts = Directory.GetDirectories(Path); } else { layouts = new string[0]; } for (int i = 0; i < layouts.Length; i++) { LayoutItem t = new LayoutItem(); t.Name = layouts[i].Substring(Path.Length + 1); if (t.Name != "CVS" && t.Name != "_svn") //Ignore CVS { baseLayoutList.Add(t); } } CurrentCache.Insert(Key.LayoutList(Path), baseLayoutList, new CacheDependency(Path)); } else { baseLayoutList = (ArrayList)CurrentCache.Get(Key.LayoutList(Path)); } return(baseLayoutList); // Jes1111 - old version // if (LayoutManager.cachedLayoutsList == null) // { // //Initialize array // ArrayList layoutsList = new ArrayList(); // // string[] layouts; // // // Try to read directories from public Layout path // if (Directory.Exists(Path)) // { // layouts = Directory.GetDirectories(Path); // } // else // { // layouts = new string[0]; // } // // for (int i = 0; i < layouts.Length; i++) // { // LayoutItem t = new LayoutItem(); // t.Name = layouts[i].Substring(Path.Length + 1); // if(t.Name != "CVS") //Ignore CVS // layoutsList.Add(t); // } // // //store list in cache // lock (typeof(LayoutManager)) // { // if (LayoutManager.cachedLayoutsList == null) // { // LayoutManager.cachedLayoutsList = layoutsList; // } // } // } // // return LayoutManager.cachedLayoutsList; }
/// <summary> /// Called only by Application_Error in global.asax.cs to deal with unhandled exceptions. /// </summary> public static void ProcessUnhandledException() { try { var e = HttpContext.Current.Server.GetLastError(); ErrorHandler.PublishToLog(LogLevel.Error, "Error no procesado", e); var redirectUrl = Config.SmartErrorRedirect; // default value var httpStatusCode = HttpStatusCode.InternalServerError; // default value var cacheKey = string.Empty; StringBuilder sb; dynamic errModule = null; if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith(Config.SmartErrorRedirect.Substring(2))) { HttpContext.Current.Response.Write("Sorry - a critical error has occurred - unable to continue"); HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.End(); } try { var auxMessage = string.Empty; LogLevel logLevel; // default value if (e is DatabaseUnreachableException || e is SqlException) { logLevel = LogLevel.Fatal; redirectUrl = Config.DatabaseErrorRedirect; httpStatusCode = Config.DatabaseErrorResponse; } else if (e is DatabaseVersionException) { // db version is behind code version logLevel = LogLevel.Fatal; httpStatusCode = Config.DatabaseUpdateResponse; redirectUrl = Config.InvalidPageIdRedirect; } else if (e is CodeVersionException) { // code version is behind db version logLevel = LogLevel.Fatal; httpStatusCode = Config.CodeUpdateResponse; redirectUrl = Config.CodeUpdateRedirect; } else if (e is PortalsLockedException) { // AllPortals lock is "on" logLevel = ((PortalsLockedException)e).Level; auxMessage = "Attempt to access locked portal by non-key-holder."; httpStatusCode = ((PortalsLockedException)e).StatusCode; redirectUrl = Config.LockRedirect; e = null; } else if (e is AppleseedRedirect) { logLevel = ((AppleseedRedirect)e).Level; httpStatusCode = ((AppleseedRedirect)e).StatusCode; redirectUrl = ((AppleseedRedirect)e).RedirectUrl; } else if (string.IsNullOrEmpty(HttpContext.Current.Request.Params["modErr"]) && ((errModule = GetFaultyModule(e, PageId)) != null)) { logLevel = LogLevel.Error; var errorGuid = Guid.NewGuid().ToString("N"); HttpContext.Current.Cache.Add(errorGuid, errModule, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 2, 0), System.Web.Caching.CacheItemPriority.Normal, null); redirectUrl = HttpUrlBuilder.BuildUrl("~/" + HttpUrlBuilder.DefaultPage, PageId, "modErr=" + errorGuid); } else if (e is AppleseedException) { logLevel = ((AppleseedException)e).Level; httpStatusCode = ((AppleseedException)e).StatusCode; } else if (e is HttpException) { logLevel = LogLevel.Fatal; httpStatusCode = (HttpStatusCode)((HttpException)e).GetHttpCode(); } else { logLevel = LogLevel.Fatal; // default value httpStatusCode = HttpStatusCode.InternalServerError; // default value } if (errModule == null) { // create unique id var myguid = Guid.NewGuid().ToString("N"); auxMessage += string.Format("errorGUID: {0}", myguid); auxMessage += string.Format("\nUrl: {0}", HttpContext.Current.Request.Url); auxMessage += string.Format("\nUrlReferer: {0}", HttpContext.Current.Request.UrlReferrer); auxMessage += string.Format( "\nUser: {0}", HttpContext.Current.User != null ? HttpContext.Current.User.Identity.Name : "unauthenticated"); if (e != null) { auxMessage += string.Format("\nStackTrace: {0}", e.StackTrace); } // log it var sw = new StringWriter(); PublishToLog(logLevel, auxMessage, e, sw); // bundle the info var storedError = new List <object>(3) { logLevel, myguid, sw }; // cache it sb = new StringBuilder(Portal.UniqueID); sb.Append("_rb_error_"); sb.Append(myguid); cacheKey = sb.ToString(); CurrentCache.Insert(cacheKey, storedError); } } catch { try { HttpContext.Current.Response.WriteFile(Config.CriticalErrorRedirect); HttpContext.Current.Response.StatusCode = (int)Config.CriticalErrorResponse; } catch { HttpContext.Current.Response.Write("Sorry - a critical error has occurred - unable to continue"); HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; } } finally { if (AppleseedMaster.IsModalChangeMaster) { if (redirectUrl.Contains("?")) { redirectUrl += "&ModalChangeMaster=true"; } else { redirectUrl += "?ModalChangeMaster=true"; } } HttpContext.Current.Server.ClearError(); if (errModule != null) { HttpContext.Current.Response.Redirect(redirectUrl, false); } else { RedirectToErrorHandlerPage(redirectUrl, httpStatusCode, cacheKey); } HttpContext.Current.ApplicationInstance.CompleteRequest(); } } catch (Exception ex) { Publish(LogLevel.Fatal, "Unexpected error in ErrorHandler", ex); } }
/// <summary> /// The run db update. /// </summary> /// <param name="connectionString"> /// The connection string. /// </param> /// <returns> /// The run db update. /// </returns> /// <remarks> /// </remarks> public bool RunDBUpdate(string connectionString) { CurrentCache.Insert(Portal.UniqueID + "_ConnectionString", connectionString); var databaseVersion = DatabaseVersion; var xmlDocument = new XmlDocument(); var tempScriptsList = new List <UpdateEntry>(); try { if (databaseVersion < Portal.CodeVersion) { ErrorHandler.Publish( LogLevel.Debug, string.Format("db:{0} Code:{1}", databaseVersion, Portal.CodeVersion)); // load the history file var docPath = HttpContext.Current.Server.MapPath("~/Setup/Scripts/History.xml"); xmlDocument.Load(docPath); // get a list of <Release> nodes if (xmlDocument.DocumentElement != null) { var releases = xmlDocument.DocumentElement.SelectNodes("Release"); if (releases != null) { // iterate over the <Release> nodes // (we can do this because XmlNodeList implements IEnumerable) foreach (XmlNode release in releases) { var updateEntry = new UpdateEntry(); // get the header information // we check for null to avoid exception if any of these nodes are not present if (release.SelectSingleNode("ID") != null) { updateEntry.VersionNumber = Int32.Parse(release.SelectSingleNode("ID/text()").Value); } if (release.SelectSingleNode("Version") != null) { updateEntry.Version = release.SelectSingleNode("Version/text()").Value; } if (release.SelectSingleNode("Script") != null) { updateEntry.ScriptNames.Add(release.SelectSingleNode("Script/text()").Value); } if (release.SelectSingleNode("Date") != null) { updateEntry.Date = DateTime.Parse(release.SelectSingleNode("Date/text()").Value); } // We should apply this patch if (databaseVersion < updateEntry.VersionNumber) { // Appleseed.Framework.Helpers.LogHelper.Logger.Log(Appleseed.Framework.Site.Configuration.LogLevel.Debug, "Detected version to apply: " + myUpdate.Version); updateEntry.Apply = true; // get a list of <Installer> nodes var installers = release.SelectNodes("Modules/Installer/text()"); // iterate over the <Installer> Nodes (in original document order) // (we can do this because XmlNodeList implements IEnumerable) foreach (XmlNode installer in installers) { // and build an ArrayList of the scripts... updateEntry.Modules.Add(installer.Value); // Appleseed.Framework.Helpers.LogHelper.Logger.Log(Appleseed.Framework.Site.Configuration.LogLevel.Debug, "Detected module to install: " + installer.Value); } // get a <Script> node, if any var sqlScripts = release.SelectNodes("Scripts/Script/text()"); // iterate over the <Installer> Nodes (in original document order) // (we can do this because XmlNodeList implements IEnumerable) foreach (XmlNode sqlScript in sqlScripts) { // and build an ArrayList of the scripts... updateEntry.ScriptNames.Add(sqlScript.Value); // Appleseed.Framework.Helpers.LogHelper.Logger.Log(Appleseed.Framework.Site.Configuration.LogLevel.Debug, "Detected script to run: " + sqlScript.Value); } tempScriptsList.Add(updateEntry); } } } } // If we have some version to apply... if (tempScriptsList.Count <= 0) { // No update is needed } else { this.scriptsList = tempScriptsList.ToArray(); // by Manu. Versions are sorted by version number Array.Sort(this.scriptsList); // Create a flat version for binding var currentVersion = 0; var databindList = new List <string>(); foreach (var updateEntry in this.scriptsList.Where(updateEntry => updateEntry.Apply)) { if (currentVersion != updateEntry.VersionNumber) { databindList.Add(string.Format("Version: {0}", updateEntry.VersionNumber)); currentVersion = updateEntry.VersionNumber; } databindList.AddRange( updateEntry.ScriptNames.Where(scriptName => scriptName.Length > 0).Select( scriptName => string.Format("-- Script: {0}", scriptName))); databindList.AddRange( updateEntry.Modules.Where(moduleInstaller => moduleInstaller.Length > 0).Select( moduleInstaller => string.Format("-- Module: {0}", moduleInstaller))); } var errors = new List <object>(); // var messages = new List<object>(); foreach (var updateEntry in this.scriptsList) { if (updateEntry.Apply && DatabaseVersion < updateEntry.VersionNumber && DatabaseVersion < Portal.CodeVersion) { // Version check (a script may update more than one version at once) foreach (var scriptName in updateEntry.ScriptNames) { if (scriptName.Length <= 0) { continue; } // It may be a module update only var currentScriptName = HttpContext.Current.Server.MapPath( System.IO.Path.Combine("~/Setup/Scripts/", scriptName)); ErrorHandler.Publish( LogLevel.Info, string.Format( "CODE: {0} - DB: {1} - CURR: {2} - Applying: {3}", Portal.CodeVersion, DatabaseVersion, updateEntry.VersionNumber, currentScriptName)); var myerrors = DBHelper.ExecuteScript(currentScriptName, true); errors.AddRange(myerrors); // Display errors if any if (myerrors.Count <= 0) { continue; } errors.Insert(0, string.Format("<p>{0}</p>", scriptName)); ErrorHandler.Publish( LogLevel.Error, string.Format( "Version {0} completed with errors. - {1}", updateEntry.Version, scriptName)); break; } // Installing modules foreach (var currentModuleInstaller in from string moduleInstaller in updateEntry.Modules select HttpContext.Current.Server.MapPath(System.IO.Path.Combine("~/", moduleInstaller))) { try { ModuleInstall.InstallGroup(currentModuleInstaller, true); } catch (Exception ex) { ErrorHandler.Publish( LogLevel.Fatal, string.Format( "Exception in UpdateDatabaseCommand installing module: {0}", currentModuleInstaller), ex); if (ex.InnerException != null) { // Display more meaningful error message if InnerException is defined ErrorHandler.Publish( LogLevel.Warn, string.Format( "Exception in UpdateDatabaseCommand installing module: {0}", currentModuleInstaller), ex.InnerException); errors.Add( string.Format( "Exception in UpdateDatabaseCommand installing module: {0}<br />{1}<br />{2}", currentModuleInstaller, ex.InnerException.Message, ex.InnerException.StackTrace)); } else { ErrorHandler.Publish( LogLevel.Warn, string.Format( "Exception in UpdateDatabaseCommand installing module: {0}", currentModuleInstaller), ex); errors.Add(ex.Message); } } } if (Equals(errors.Count, 0)) { // Update db with version var versionUpdater = string.Format( "INSERT INTO [rb_Versions] ([Release],[Version],[ReleaseDate]) VALUES('{0}','{1}', CONVERT(datetime, '{2}/{3}/{4}', 101))", updateEntry.VersionNumber, updateEntry.Version, updateEntry.Date.Month, updateEntry.Date.Day, updateEntry.Date.Year); DBHelper.ExeSQL(versionUpdater); ErrorHandler.Publish( LogLevel.Info, string.Format("Version number: {0} applied successfully.", updateEntry.Version)); // Mark this update as done ErrorHandler.Publish( LogLevel.Info, string.Format("Successfully applied version: {0}", updateEntry.Version)); } } else { ErrorHandler.Publish( LogLevel.Info, string.Format( "CODE: {0} - DB: {1} - CURR: {2} - Skipping: {3}", Portal.CodeVersion, DatabaseVersion, updateEntry.VersionNumber, updateEntry.Version)); } } } } } catch (Exception exception) { ErrorHandler.Publish(LogLevel.Error, "An error occurred during the installation process.", exception); throw; } return(true); }
// const string strTOE = "Time of Error: "; // const string strSrvName = "SERVER_NAME"; // const string strSrc = "Source: "; // const string strErrMsg = "Error Message: "; // const string strTgtSite = "Target Site: "; // const string strStkTrace = "Stack Trace: "; /// <summary> /// Called only by Application_Error in global.asax.cs to deal with unhandled exceptions. /// </summary> public static void ProcessUnhandledException() { try { Exception e = HttpContext.Current.Server.GetLastError(); string _myGuid; string _auxMessage; string _redirectUrl = Config.SmartErrorRedirect; // default value LogLevel _logLevel = LogLevel.Fatal; // default value HttpStatusCode _httpStatusCode = HttpStatusCode.InternalServerError; // default value string myCacheKey = string.Empty; StringBuilder sb; if (HttpContext.Current.Request != null && HttpContext.Current.Request.Url.AbsolutePath.EndsWith(Config.SmartErrorRedirect.Substring(2))) { HttpContext.Current.Response.Write("Sorry - a critical error has occurred - unable to continue"); HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.End(); } try { if (e is DatabaseUnreachableException || e is SqlException) { _logLevel = LogLevel.Fatal; _redirectUrl = Config.DatabaseErrorRedirect; _httpStatusCode = Config.DatabaseErrorResponse; } else if (e is DatabaseVersionException) // db version is behind code version { _logLevel = LogLevel.Fatal; _httpStatusCode = Config.DatabaseUpdateResponse; _redirectUrl = Config.DatabaseUpdateRedirect; } else if (e is CodeVersionException) // code version is behind db version { _logLevel = LogLevel.Fatal; _httpStatusCode = Config.CodeUpdateResponse; _redirectUrl = Config.CodeUpdateRedirect; } else if (e is PortalsLockedException) // AllPortals lock is "on" { _logLevel = ((PortalsLockedException)e).Level; _auxMessage = "Attempt to access locked portal by non-keyholder."; _httpStatusCode = ((PortalsLockedException)e).StatusCode; _redirectUrl = Config.LockRedirect; e = null; } else if (e is RainbowRedirect) { _logLevel = ((RainbowRedirect)e).Level; _httpStatusCode = ((RainbowRedirect)e).StatusCode; _redirectUrl = ((RainbowRedirect)e).RedirectUrl; } else if (e is RainbowException) { _logLevel = ((RainbowException)e).Level; _httpStatusCode = ((RainbowException)e).StatusCode; } else if (e is HttpException) { _logLevel = LogLevel.Fatal; _httpStatusCode = (HttpStatusCode)((HttpException)e).GetHttpCode(); } else { _logLevel = LogLevel.Fatal; // default value _httpStatusCode = HttpStatusCode.InternalServerError; // default value } // create unique id _myGuid = Guid.NewGuid().ToString("N"); _auxMessage = string.Format("errorGUID: {0}", _myGuid); // log it StringWriter sw = new StringWriter(); PublishToLog(_logLevel, _auxMessage, e, sw); // bundle the info ArrayList storedError = new ArrayList(3); storedError.Add(_logLevel); storedError.Add(_myGuid); storedError.Add(sw); // cache it sb = new StringBuilder(Portal.UniqueID); sb.Append("_rb_error_"); sb.Append(_myGuid); myCacheKey = sb.ToString(); CurrentCache.Insert(myCacheKey, storedError); } catch { try { HttpContext.Current.Response.WriteFile(Config.CriticalErrorRedirect); HttpContext.Current.Response.StatusCode = (int)Config.CriticalErrorResponse; } catch { HttpContext.Current.Response.Write("Sorry - a critical error has occurred - unable to continue"); HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; } } finally { if (_redirectUrl.StartsWith("http://")) { HttpContext.Current.Response.Redirect(_redirectUrl, true); } else if (_redirectUrl.StartsWith("~/") && _redirectUrl.IndexOf(".aspx") > 0) { // append params to redirect url if (!_redirectUrl.StartsWith(@"http://")) { sb = new StringBuilder(); if (_redirectUrl.IndexOf("?") != -1) { sb.Append(_redirectUrl.Substring(0, _redirectUrl.IndexOf("?") + 1)); sb.Append(((int)_httpStatusCode).ToString()); sb.Append("&eid="); sb.Append(myCacheKey); sb.Append("&"); sb.Append(_redirectUrl.Substring(_redirectUrl.IndexOf("?") + 1)); _redirectUrl = sb.ToString(); } else { sb.Append(_redirectUrl); sb.Append("?"); sb.Append(((int)_httpStatusCode).ToString()); sb.Append("&eid="); sb.Append(myCacheKey); _redirectUrl = sb.ToString(); } } HttpContext.Current.Response.Redirect(_redirectUrl, true); } else if (_redirectUrl.StartsWith("~/") && _redirectUrl.IndexOf(".htm") > 0) { HttpContext.Current.Response.WriteFile(_redirectUrl); HttpContext.Current.Response.StatusCode = (int)_httpStatusCode; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.End(); } else { HttpContext.Current.Response.Write("Sorry - a critical error has occurred - unable to continue"); HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.End(); } } } catch (Exception ex) { Publish(LogLevel.Fatal, "Unexpected error in ErrorHandler", ex); } }