Portal Starter Source Code In-depth Analysis (1)

xiaoxiao2021-03-06  36

PORTAL STARTER Source Code In-depth analysis (1) Learn ASP.NET light reading seems to be, find some classic source code to read, and it is very helpful for improvement. Several examples in Microsoft's website, select Portal because this example is the largest, as a simple portal. Portal's workflow: 1. Read the website setting file portalcfg.xml to CONTEXT, which is done by the Application_BeginRequest () event in Global.asax. 2, customer access portal station, execute default.aspx, Default.aspx determines that the client is a mobile or browser. If it is the latter, guide the customer to DesktopDefault.aspx3, DesktopDefault.aspx to complete the display of the various columns of the website and the corresponding columns The load of the module. Analyze the Application_BeginRequest () event in Global.asax:

Sub Application_BeginRequest (Byval E AS Object, BYVAL E as Eventargs) 'Default Access Home DIM Tabindex As Integer = 0 DIM Tabid AS Integer = 1

'Get tabindex from querystring if not (Request.Params ("TabINDEX") IS Nothing) THEN TABINDEX = CINT (Request.Params ("Tabindex")) Endiff

'Get Tabid from querystring if not (Request.Params ("Tabid") IS Nothing) THEN Tabid = CINT (Request.Params ("Tabid") Endiff

'Add the portalSettings Object to the context' PortalSetting is defined in Components / Configuration.vb, which is based on the incoming TabIndex, TabID loads the elements of the corresponding column. 'Context is used to cache the settings of the corresponding column. 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 class defines in the Components / Configuration, which is the role of setting the file portalcfg.xml file for the Portal website. 'The same is to cache the setup file into the Context so that any part of the website can access these settings. DIM config as configuration = new configuration () Context.Items.Add ("SitESETTINGS", config.getsitsettings ())

Try If Not (Request.UserLanguages ​​Is Nothing) 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 ") End If Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture Catch ex As Exception Thread.CurrentThread.CurrentCulture = New CultureInfo (" en-us ") End Try End Sub analysis New PortalSettings (tabIndex, tabId), please See below PortalSettings constructor: Public Class PortalSettings Public PortalId As Integer Public PortalName As String Public AlwaysShowEditButton As Boolean Public DesktopTabs As New ArrayList () Public MobileTabs As New ArrayList () Public ActiveTab As New TabSettings () ...... Public Sub New (Byval TabIndex As Integer, Byval Tabid As Integer "Get The Configuration Data Dim Config As Configuration = New configuration () The portalcfg.xml file is imported into the context through the CONFIGURATION class, 'SubsetsTings is defined as a enhanced DataSet class by assigning the value to SitESETTINGS. DIM Sitesettings as SiteConfiguration = config.getsitesettings ()

'Read the desktop tab information, and sort by tab order' reads TAB information, that is, the portal website, put it in DesktopTabs. Dim Trow As SiteConfiguration.tabrow for Each Trow in Sitesettings.tab.Select ("", "Taborder") DIM TabDetails as new tabstripdetails ()

WITH TABDETAILS .TABID = TROW.TABID .TABNAME = Trow.TabName .taborder = Trow.taborder .authorizedroles = Trow.accessRoles End withme.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 If Me.ActiveTab.TabId = 0 Then Me.ActiveTab.TabId = CType (Me.DesktopTabs (0), Tabstripdetails) .tabid endiff

'Read the Mobile Tab Information, and sort by Tab Order Dim mRow As SiteConfiguration.TabRow For Each mRow In siteSettings.Tab.Select ( "ShowMobile =' true '", "TabOrder") Dim tabDetails As New TabStripDetails ()

With TabDetails .tabid = MROW.TABID .TABNAME = MROW.MOBILETABNAME .AUTHORIZEDROLES = MROW.ACCESSROLES End With

Me.mobiletabs.add (tabdetails) Next

'Read The Module Information for the Current (Active) Tab' Find the current column, read the module information in the current column. DIM ACTIVETAB As SiteConfiguration.tabrow = SiteSettings.Tab.FindBytabid (Tabid) Dim Modulerow As SiteConfiguration._ModuLOW

'Get modules for this Tab Based on the Data Relation for Each Modulerow in ActiveTab.getModulerows () DIM MODULESETTINGS AS New 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' Find the path of the module user component by module ID. Dim Moddefrow as Siteconfiguration.ModuledEfinitionRow = Sitesettings.ModuledEfinition.FindBymoduledEfId (.ModuledEfID)

.Desktopsrc = moddefrow.desktopsourcefile.mobilesrc = moddefrow.mobilesourcefile end

Me.ActiveTab.Modules.Add (Modulesettings) Next

'Sort the modules in Order of ModuleRder 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 Analysis Configuration class GetSiteSettings () method: Public Function GetSiteSettings () As SiteConfiguration Dim siteSettings As SiteConfiguration = CType (HttpContext.Current.Cache ( "SiteSettings"), SiteConfiguration) 'If the SiteConfiguration is not cached, load it From the xml file and add it keto the cache. if Sitsettings is nothing the

'Create the dataset sitesettings = new siteconfiguration ()

'Retrieve the location of the xml configuration file dim configfile as string = httpContext.current.server.mappath ("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

'Loading the xml data into the dataset sitesettings.readxml (configfile) end with

'Store The DataSet In The Cache' Cache based on portalcfg.xml files, rereading the file when the portalcfg.xml file changes. HttpContext.current.cache.insert ("Sitesettings", SiteSettings, New CachedPendency (Configfile)

END IF

Return Sitesettings

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-64019.html

New Post(0)