分享
 
 
 

Portal Starter 源码深入剖析(一)

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Portal Starter 源码深入剖析(一)

学ASP.net光看书看来是不行的,找一些经典的源代码来读读,对提升认识是很有帮助的。

在Microsoft的网站上找到几个范例,选择Portal是因为这个范例最大,可作为一个简单的门户站。

Portal的工作流程:

1、读取网站设置文件PortalCfg.xml至context中缓存起来,这个过程由Global.asax中的Application_BeginRequest()事件来完成的。

2、客户访问Portal站,执行Default.aspx,Default.aspx判断客户端是Mobile还是浏览器,如果是后者,引导客户至DesktopDefault.aspx

3、DesktopDefault.aspx完成网站各个栏目的展示以及各个栏目中相应模块的加载。

分析Global.asax中的Application_BeginRequest()事件:

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

'默认访问主页

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"))

End If

' Get TabID from querystring

If Not (Request.Params("tabid") Is Nothing) Then

tabId = CInt(Request.Params("tabid"))

End If

' Add the PortalSettings object to the context

' PortalSetting在Components\Configuration.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类在Components\Configuration中定义,其作用是操作Portal网站的设置文件PortalCfg.xml文件。

' 同样是将设置文件缓存到Context中,这样网站的任何部分都可以访问到这些设置。

Dim config As Configuration = New Configuration()

Context.Items.Add("SiteSettings", config.GetSiteSettings())

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

分析New PortalSettings(tabIndex, tabId),请看下面PortalSettings的构造函数:

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()

' 通过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

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 With

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

If Me.ActiveTab.TabId = 0 Then

Me.ActiveTab.TabId = CType(Me.DesktopTabs(0), TabStripDetails).TabId

End If

' 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

' 找到当前栏目,读取当前栏目中的模块信息。

Dim activeTab As SiteConfiguration.TabRow = siteSettings.Tab.FindByTabId(tabId)

Dim moduleRow As SiteConfiguration._ModuleRow

' 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

' 按模块ID找到该模块用户组件的路径。

Dim modDefRow As SiteConfiguration.ModuleDefinitionRow = siteSettings.ModuleDefinition.FindByModuleDefId(.ModuleDefId)

.DesktopSrc = modDefRow.DesktopSourceFile

.MobileSrc = modDefRow.MobileSourceFile

End With

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()方法:

Public 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 Is Nothing Then

' Create the dataset

siteSettings = New SiteConfiguration()

' Retrieve the location of the XML configuration file

Dim configFile As String = 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)

End With

' Store the dataset in the cache

' 基于PortalCfg.xml文件的Cache,当PortalCfg.xml文件有变动时,重新读入该文件。

HttpContext.Current.Cache.Insert("SiteSettings", siteSettings, New CacheDependency(configFile))

End If

Return siteSettings

End Function

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有