Sub Application_BeginRequest()Sub Application_BeginRequest(ByVal sender AsObject, ByVal e As EventArgs) '默认访问主页 Dim tabIndex AsInteger=0 Dim tabId AsInteger=1 ' Get TabIndex from querystring IfNot (Request.Params("tabindex") IsNothing) Then tabIndex =CInt(Request.Params("tabindex")) EndIf ' Get TabID from querystring IfNot (Request.Params("tabid") IsNothing) Then tabId =CInt(Request.Params("tabid")) EndIf ' Add the PortalSettings object to the context ' PortalSetting在ComponentsConfiguration.vb中定义,其作用是根据传入的tabIndex,tabId加载相应栏目的元素。 ' Context用来缓存相应栏目的设置。 Context.Items.Add("PortalSettings", New PortalSettings(tabIndex, tabId)) ' Read the configuration info from the XML file or retrieve from Cache ' and add to the context ' Configuration类在ComponentsConfiguration中定义,其作用是操作Portal网站的设置文件PortalCfg.xml文件。 ' 同样是将设置文件缓存到Context中,这样网站的任何部分都可以访问到这些设置。 Dim config As Configuration =New Configuration() Context.Items.Add("SiteSettings", config.GetSiteSettings()) Try IfNot (Request.UserLanguages IsNothing) Then Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0)) ' Default to English if there are no user languages Else Thread.CurrentThread.CurrentCulture =New CultureInfo("en-us") EndIf Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture Catch ex As Exception Thread.CurrentThread.CurrentCulture =New CultureInfo("en-us") EndTry End Sub
PublicClass PortalSettingsClass PortalSettings Public PortalId AsInteger Public PortalName AsString Public AlwaysShowEditButton AsBoolean Public DesktopTabs AsNew ArrayList() Public MobileTabs AsNew ArrayList() Public ActiveTab AsNew TabSettings() ...... PublicSub New()SubNew(ByVal tabIndex AsInteger, ByVal tabId AsInteger) ' Get the configuration data Dim config As Configuration =New Configuration() ' 通过Configuration类中的GetSiteSettings()将PortalCfg.xml文件导入到Context中, ' 随后通过返回值赋值给siteSettings,siteSettings被定义为一个增强型的Dataset类。 Dim siteSettings As SiteConfiguration = config.GetSiteSettings() ' Read the Desktop Tab Information, and sort by Tab Order ' 读取Tab信息,也就是Portal网站的栏目信息,放到DesktopTabs中。 Dim tRow As SiteConfiguration.TabRow ForEach tRow In siteSettings.Tab.Select("", "TabOrder") Dim tabDetails AsNew TabStripDetails() With tabDetails .TabId = tRow.TabId .TabName = tRow.TabName .TabOrder = tRow.TabOrder .AuthorizedRoles = tRow.AccessRoles EndWith Me.DesktopTabs.Add(tabDetails) Next ' If the PortalSettings.ActiveTab property is set to 0, change it to ' the TabID of the first tab in the DesktopTabs collection IfMe.ActiveTab.TabId =0Then Me.ActiveTab.TabId =CType(Me.DesktopTabs(0), TabStripDetails).TabId EndIf ' Read the Mobile Tab Information, and sort by Tab Order Dim mRow As SiteConfiguration.TabRow ForEach mRow In siteSettings.Tab.Select("ShowMobile='true'", "TabOrder") Dim tabDetails AsNew TabStripDetails() With tabdetails .TabId = mRow.TabId .TabName = mRow.MobileTabName .AuthorizedRoles = mRow.AccessRoles EndWith Me.MobileTabs.Add(tabDetails) Next ' Read the Module Information for the current (Active) tab ' 找到当前栏目,读取当前栏目中的模块信息。 Dim activeTab As SiteConfiguration.TabRow = siteSettings.Tab.FindByTabId(tabId) Dim moduleRow As SiteConfiguration._ModuleRow ' Get Modules for this Tab based on the Data Relation ForEach moduleRow In activeTab.GetModuleRows() Dim moduleSettings AsNew moduleSettings() With moduleSettings .ModuleTitle = moduleRow.ModuleTitle .ModuleId = moduleRow.ModuleId .ModuleDefId = moduleRow.ModuleDefId .ModuleOrder = moduleRow.ModuleOrder .TabId = tabId .PaneName = moduleRow.PaneName .AuthorizedEditRoles = moduleRow.EditRoles .CacheTime = moduleRow.CacheTimeout .ShowMobile = moduleRow.ShowMobile ' ModuleDefinition data ' 按模块ID找到该模块用户组件的路径。 Dim modDefRow As SiteConfiguration.ModuleDefinitionRow = siteSettings.ModuleDefinition.FindByModuleDefId(.ModuleDefId) .DesktopSrc = modDefRow.DesktopSourceFile .MobileSrc = modDefRow.MobileSourceFile EndWith Me.ActiveTab.Modules.Add(moduleSettings) Next ' Sort the modules in order of ModuleOrder Me.ActiveTab.Modules.Sort() ' Get the first row in the Global table Dim globalSettings As SiteConfiguration.GlobalRow = siteSettings.Global.Rows(0) ' Read Portal global settings Me.PortalId = globalSettings.PortalId Me.PortalName = globalSettings.PortalName Me.AlwaysShowEditButton = globalSettings.AlwaysShowEditButton Me.ActiveTab.TabIndex = tabIndex Me.ActiveTab.TabId = tabId Me.ActiveTab.TabOrder = activeTab.TabOrder Me.ActiveTab.MobileTabName = activeTab.MobileTabName Me.ActiveTab.AuthorizedRoles = activeTab.AccessRoles Me.ActiveTab.TabName = activeTab.TabName Me.ActiveTab.ShowMobile = activeTab.ShowMobile End Sub 分析Configuration类中的GetSiteSettings()方法:
PublicFunction GetSiteSettings()Function GetSiteSettings() As SiteConfiguration Dim siteSettings As SiteConfiguration =CType(HttpContext.Current.Cache("SiteSettings"), SiteConfiguration) ' If the SiteConfiguration isn't cached, load it from the XML file and add it into the cache. If siteSettings IsNothingThen ' Create the dataset siteSettings =New SiteConfiguration() ' Retrieve the location of the XML configuration file Dim configFile AsString= HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings("configFile")) With siteSettings ' Set the AutoIncrement property to true for easier adding of rows .Tab.TabIdColumn.AutoIncrement =True ._Module.ModuleIdColumn.AutoIncrement =True .ModuleDefinition.ModuleDefIdColumn.AutoIncrement =True ' Load the XML data into the DataSet siteSettings.ReadXml(configFile) EndWith ' Store the dataset in the cache ' 基于PortalCfg.xml文件的Cache,当PortalCfg.xml文件有变动时,重新读入该文件。 HttpContext.Current.Cache.Insert("SiteSettings", siteSettings, New CacheDependency(configFile)) EndIf Return siteSettings End Function