DOTNETNUKE 配置文件类有:

   ProviderConfigurationHandler类

   Provider类

   ProviderConfiguration类

web.config文件中引用ProviderConfigurationHandler,该类继承.NET FrameWork接口IConfigurationSectionHandler

 

   <configSections>
    
<sectionGroup name="dotnetnuke">
      
<section name="data" requirePermission="false" type="DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke" />
    
</sectionGroup>
  
</configSections>

 

实现Create方法如下:

 

       Public Overridable Overloads Function Create(ByVal parent As Object, ByVal context As Object, ByVal node As System.Xml.XmlNode) As Object Implements IConfigurationSectionHandler.Create
            Dim objProviderConfiguration As New ProviderConfiguration
            objProviderConfiguration.LoadValuesFromConfigurationXml(node)
            Return objProviderConfiguration
        End Function

 

主要是使用了ProviderConfiguration得LoadValuesFromConfiguration()方法

该方法主要对Providers hashtable值进行操作,通过读取web.config文件中得<data>子节点值,装载到Providers中

主要代码如下:

怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?Friend Sub LoadValuesFromConfigurationXml(ByVal node As XmlNode)
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   Dim attributeCollection As XmlAttributeCollection 
= node.Attributes
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   
' Get the default provider
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
   _DefaultProvider = attributeCollection("defaultProvider").Value
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   
' Read child nodes
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
   Dim child As XmlNode
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   For Each child In node.ChildNodes
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?    If child.Name 
= "providers" Then
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?                    GetProviders(child)
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?                End If
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   Next child
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?  End Sub
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?  Friend Sub GetProviders(ByVal node As XmlNode)
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   Dim Provider As XmlNode
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   For Each Provider In node.ChildNodes
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?    Select Case Provider.Name
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?     Case 
"add"
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?      Providers.Add(Provider.Attributes(
"name").Value, New Provider(Provider.Attributes))
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?     Case 
"remove"
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?      Providers.Remove(Provider.Attributes(
"name").Value)
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?     Case 
"clear"
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?      Providers.Clear()
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?    End Select
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?   Next Provider
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?  End Sub
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?


当其子节点为“add”时,新建一个Provider实体,并放入Providers 哈西表中。

怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?Public Shared Function GetProviderConfiguration(ByVal strProvider As String) As ProviderConfiguration
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            Return CType(Config.GetSection(
"dotnetnuke/" & strProvider), ProviderConfiguration)
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?  End Function
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?


GetProviderConfiguration(strProvider)方法作用是获取web.config节点信息,并装入到ProviderConfiguration类实体当中。

所以该类的操作都是围绕着providers哈西表来得,即把取得的provider数据都放入该哈西表中。

下面介绍Provider类

其有两个属性:

   Public Readonly property Name()as string

   public ReadOnly property Type() as string

一个New(XmlattributeCollection)方法

该方法做了一些设置属性值得操作,从XmlattributeCollection中获取值。

并且做了把一些其他该xml属性集合放入到一个NameValueCollection集合当中。

web.config 节点如下:

 

怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?<data defaultProvider="SqlDataProvider">
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?      
<providers>
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?        
<clear />
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?        
<add name="SqlDataProvider" type="DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="" templateFile="DotNetNuke_template.mdf" databaseOwner="dbo" />
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?      
</providers>
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
</data>

 

 

应用:

 

怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?Public Function GetApplicationName(ByVal PortalID As Integer) As String
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            Dim appName As String
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            
'Get the Data Provider Configuration
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
            Dim _providerConfiguration As ProviderConfiguration = ProviderConfiguration.GetProviderConfiguration("data")
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
//装入ProviderConfiguration类实体
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?

怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            
' Read the configuration specific information for the current Provider
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
            Dim objProvider As Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Provider)
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
//读取Providers哈西表中的DefaultProvider值
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?

怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            
'Get the Object Qualifier frm the Provider Configuration
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
            Dim _objectQualifier As String = objProvider.Attributes("objectQualifier")
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            If _objectQualifier 
<> "" And _objectQualifier.EndsWith("_"= False Then
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?                _objectQualifier 
+= "_"
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            End If
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            appName 
= _objectQualifier + Convert.ToString(PortalID)
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?            Return appName
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?        End Function
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?
怎样写自己的ConfigurationHandler(DOTNETNUKE 研究)?


 以上三个类究竟在一个系统中有什么用呢?我个人理解认为是为了灵活性,我们可以直接在config文件修改provider值,就可实现我们究竟需要使用哪一个provider,而不需要重新编译,对于一个系统比较好维护,灵活性比较高。

设计技术点:

   configManager类(Getsection()方法的使用)

  IConfigurationSectionHandler接口 - ProviderconfigurationHandler继承该接口

  hashtable、NamevalueCollection、XmlattributeCollection、xmlNode类型的使用

相关文章: