/// <summary> /// Convert the module list to dictionary. /// </summary> /// <param name="modules"></param> /// <returns>A dictionary</returns> /// <exception cref="Exception"></exception> private static Dictionary<string, List<Control>> ConvertModuleListToDictionary(List<IModuleSettings> modules) { var settings = (PortalSettings)HttpContext.Current.Items["PortalSettings"]; var dictionary = new Dictionary<string, List<Control>>(); dynamic faultyModule = null; var modErrKey = HttpContext.Current.Request.Params["modErr"]; //we receive this param if in the Application_Error it was discovered that a module is broken if (!string.IsNullOrEmpty(modErrKey)) { faultyModule = HttpContext.Current.Cache.Get(modErrKey); HttpContext.Current.Cache.Remove(modErrKey); } if (modules.Count > 0) { var page = new Page(); foreach (ModuleSettings settings2 in modules) { if (!settings2.Cacheable) { settings2.CacheTime = -1; } if (PortalSecurity.IsInRoles(settings2.AuthorizedViewRoles)) { List<Control> list; Exception exception; var str = settings2.PaneName.ToLower(); if (!string.IsNullOrEmpty(str)) { if (!dictionary.ContainsKey(str)) { dictionary.Add(str, new List<Control>()); } list = dictionary[str]; } else { if (!dictionary.ContainsKey("contentpane")) { dictionary.Add("contentpane", new List<Control>()); } list = dictionary["contentpane"]; } if (!settings2.Admin && (settings2.CacheTime == 0)) { var moduleOverrideCache = Config.ModuleOverrideCache; if (moduleOverrideCache > 0) { settings2.CacheTime = moduleOverrideCache; } } if ((((settings2.CacheTime <= 0) || PortalSecurity.HasEditPermissions(settings2.ModuleID)) || (PortalSecurity.HasPropertiesPermissions(settings2.ModuleID) || PortalSecurity.HasAddPermissions(settings2.ModuleID))) || PortalSecurity.HasDeletePermissions(settings2.ModuleID)) { try { PortalModuleControl control; var virtualPath = Path.ApplicationRoot + "/" + settings2.DesktopSrc; if (virtualPath.ToLowerInvariant().Trim().EndsWith(".ascx")) { if (faultyModule != null && faultyModule.ModuleDefID == settings2.ModuleDefID) { throw new Exception(faultyModule.Message); //if this was the module that was generating the error, we then show the error. } control = (PortalModuleControl)page.LoadControl(virtualPath); } else { var strArray = virtualPath.Split( new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); int index = 1; if (!Path.ApplicationRoot.Equals(string.Empty)) { index++; } var areaName = (strArray[index].ToLower() == "views") ? string.Empty : strArray[index]; var controllerName = strArray[strArray.Length - 2]; var actionName = strArray[strArray.Length - 1]; // var ns = strArray[2]; control = (PortalModuleControl) page.LoadControl("~/DesktopModules/CoreModules/MVC/MVCModule.ascx"); ((MVCModuleControl)control).ControllerName = controllerName; ((MVCModuleControl)control).ActionName = actionName; ((MVCModuleControl)control).AreaName = areaName; ((MVCModuleControl)control).ModID = settings2.ModuleID; ((MVCModuleControl)control).Initialize(); } control.PortalID = settings.PortalID; control.ModuleConfiguration = settings2; if ((control.Cultures == string.Empty) || ((control.Cultures + ";").IndexOf(settings.PortalContentLanguage.Name + ";") >= 0)) { list.Add(control); } } catch (Exception exception1) { exception = exception1; ErrorHandler.Publish( LogLevel.Error, string.Format("DesktopPanes: Unable to load control '{0}'!", settings2.DesktopSrc), exception); if (PortalSecurity.IsInRoles("Admins")) { list.Add( new LiteralControl( string.Format("<br><span class=NormalRed>Unable to load control '{0}'! (Full Error Logged)<br />Error Message: {1}", settings2.DesktopSrc, exception.Message))); } else { list.Add( new LiteralControl( string.Format("<br><span class=NormalRed>Unable to load control '{0}'!", settings2.DesktopSrc))); } } } else { try { using (var control2 = new CachedPortalModuleControl()) { control2.PortalID = settings.PortalID; control2.ModuleConfiguration = settings2; list.Add(control2); } } catch (Exception exception2) { exception = exception2; ErrorHandler.Publish( LogLevel.Error, string.Format("DesktopPanes: Unable to load cached control '{0}'!", settings2.DesktopSrc), exception); if (PortalSecurity.IsInRoles("Admins")) { list.Add( new LiteralControl( string.Format("<br><span class=NormalRed>Unable to load cached control '{0}'! (Full Error Logged)<br />Error Message: {1}", settings2.DesktopSrc, exception.Message))); } else { list.Add( new LiteralControl( string.Format("<br><span class=NormalRed>Unable to load cached control '{0}'!", settings2.DesktopSrc))); } } } } } } return dictionary; }
/// <summary> /// Initialize internal data source /// </summary> public void InitializeDataSource() { innerDataSource = new ArrayList(); // Obtain PortalSettings from Current Context PortalSettings PortalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"]; // Loop through each entry in the configuration system for this tab // Ensure that the visiting user has access to view the module foreach (ModuleSettings _moduleSettings in PortalSettings.ActivePage.Modules) { if (_moduleSettings.PaneName.ToLower() == Content.ToLower() && PortalSecurity.IsInRoles(_moduleSettings.AuthorizedViewRoles)) { //Cache. If == 0 then override with default cache in web.config if (ConfigurationManager.AppSettings["ModuleOverrideCache"] != null && !_moduleSettings.Admin && _moduleSettings.CacheTime == 0) { int mCache = Int32.Parse(ConfigurationManager.AppSettings["ModuleOverrideCache"]); if (mCache > 0) _moduleSettings.CacheTime = mCache; } // added security settings to condition test so that a user who has // edit or properties permission will not cause the module output to be cached. if ( ((_moduleSettings.CacheTime) <= 0) || (PortalSecurity.HasEditPermissions(_moduleSettings.ModuleID)) || (PortalSecurity.HasPropertiesPermissions(_moduleSettings.ModuleID)) || (PortalSecurity.HasAddPermissions(_moduleSettings.ModuleID)) || (PortalSecurity.HasDeletePermissions(_moduleSettings.ModuleID)) ) { try { string portalModuleName = string.Concat(Path.ApplicationRoot, "/", _moduleSettings.DesktopSrc); PortalModuleControl portalModule = (PortalModuleControl) Page.LoadControl(portalModuleName); portalModule.PortalID = PortalSettings.PortalID; portalModule.ModuleConfiguration = _moduleSettings; //TODO: This is not the best place: should be done early if ((portalModule.Cultures != null && portalModule.Cultures.Length == 0) || (portalModule.Cultures + ";").IndexOf(PortalSettings.PortalContentLanguage.Name + ";") >= 0) innerDataSource.Add(portalModule); } catch (Exception ex) { ErrorHandler.Publish(LogLevel.Error, "ZenLayout: Unable to load control '" + _moduleSettings.DesktopSrc + "'!", ex); innerDataSource.Add( new LiteralControl("<br><span class=\"NormalRed\">" + "ZenLayout: Unable to load control '" + _moduleSettings.DesktopSrc + "'!")); } } else { try { CachedPortalModuleControl portalModule = new CachedPortalModuleControl(); portalModule.PortalID = PortalSettings.PortalID; portalModule.ModuleConfiguration = _moduleSettings; innerDataSource.Add(portalModule); } catch (Exception ex) { ErrorHandler.Publish(LogLevel.Error, "ZenLayout: Unable to load cached control '" + _moduleSettings.DesktopSrc + "'!", ex); innerDataSource.Add( new LiteralControl("<br><span class=\"NormalRed\">" + "ZenLayout: Unable to load cached control '" + _moduleSettings.DesktopSrc + "'!")); } } } } }
/// <summary> /// Initialize internal data source /// </summary> public void InitializeDataSource() { innerDataSource = new ArrayList(); // Obtain PortalSettings from Current Context PortalSettings PortalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"]; // Loop through each entry in the configuration system for this tab // Ensure that the visiting user has access to view the module foreach (ModuleSettings _moduleSettings in PortalSettings.ActivePage.Modules) { if (_moduleSettings.PaneName.ToLower() == Content.ToLower() && PortalSecurity.IsInRoles(_moduleSettings.AuthorizedViewRoles)) { //Cache. If == 0 then override with default cache in web.config if (ConfigurationManager.AppSettings["ModuleOverrideCache"] != null && !_moduleSettings.Admin && _moduleSettings.CacheTime == 0) { int mCache = Int32.Parse(ConfigurationManager.AppSettings["ModuleOverrideCache"]); if (mCache > 0) { _moduleSettings.CacheTime = mCache; } } // added security settings to condition test so that a user who has // edit or properties permission will not cause the module output to be cached. if ( ((_moduleSettings.CacheTime) <= 0) || (PortalSecurity.HasEditPermissions(_moduleSettings.ModuleID)) || (PortalSecurity.HasPropertiesPermissions(_moduleSettings.ModuleID)) || (PortalSecurity.HasAddPermissions(_moduleSettings.ModuleID)) || (PortalSecurity.HasDeletePermissions(_moduleSettings.ModuleID)) ) { try { string portalModuleName = string.Concat(Path.ApplicationRoot, "/", _moduleSettings.DesktopSrc); PortalModuleControl portalModule = (PortalModuleControl)Page.LoadControl(portalModuleName); portalModule.PortalID = PortalSettings.PortalID; portalModule.ModuleConfiguration = _moduleSettings; //TODO: This is not the best place: should be done early if ((portalModule.Cultures != null && portalModule.Cultures.Length == 0) || (portalModule.Cultures + ";").IndexOf(PortalSettings.PortalContentLanguage.Name + ";") >= 0) { innerDataSource.Add(portalModule); } } catch (Exception ex) { ErrorHandler.Publish(LogLevel.Error, "ZenLayout: Unable to load control '" + _moduleSettings.DesktopSrc + "'!", ex); innerDataSource.Add( new LiteralControl("<br><span class=\"NormalRed\">" + "ZenLayout: Unable to load control '" + _moduleSettings.DesktopSrc + "'!")); } } else { try { CachedPortalModuleControl portalModule = new CachedPortalModuleControl(); portalModule.PortalID = PortalSettings.PortalID; portalModule.ModuleConfiguration = _moduleSettings; innerDataSource.Add(portalModule); } catch (Exception ex) { ErrorHandler.Publish(LogLevel.Error, "ZenLayout: Unable to load cached control '" + _moduleSettings.DesktopSrc + "'!", ex); innerDataSource.Add( new LiteralControl("<br><span class=\"NormalRed\">" + "ZenLayout: Unable to load cached control '" + _moduleSettings.DesktopSrc + "'!")); } } } } }