Dotnetnuke configuration file classes include:
Providerconfigurationhandler class
Provider class
Providerconfiguration class
The Web. config file references providerconfigurationhandler, which inherits the. NET Framework interface iconfigurationsectionhandler.
<Configsections>
<Sectiongroup name = "dotnetnuke">
<Section name = "data" requirepermission = "false" type = "dotnetnuke. Framework. providers. providerconfigurationhandler, dotnetnuke"/>
</Sectiongroup>
</Configsections>
The create method is as follows:
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
The loadvaluesfromconfiguration () method of providerconfiguration is used.
This method operates on the value of providers hashtable. by reading the value of <DATA> subnode in the web. config file, it is loaded to providers.
The main code is as follows:
Friend sub loadvaluesfromconfigurationxml (byval node as xmlnode)
Dim attributecollection as xmlattributecollection = node. Attributes
'Get the default provider
_ Defaultprovider = attributecollection ("defaultprovider"). Value
'Read Child Nodes
Dim child as xmlnode
For each child in node. childnodes
If child. Name = "providers" then
Getproviders (child)
End if
Next child
End sub
Friend sub getproviders (byval node as xmlnode)
Dim provider as xmlnode
For each provider in node. childnodes
Select case provider. Name
Case "add"
Providers. Add (provider. attributes ("name"). Value, new provider (provider. attributes ))
Case "Remove"
Providers. Remove (provider. attributes ("name"). value)
Case "clear"
Providers. Clear ()
End select
Next provider
End sub
When its subnode is "add", create a provider object and put it in the providers Hasse table.
Public shared function getproviderconfiguration (byval strprovider as string) as providerconfiguration
Return ctype (config. getsection ("dotnetnuke/" & strprovider), providerconfiguration)
End Function
The getproviderconfiguration (strprovider) method is used to obtain information about the web. config node and load it into the providerconfiguration class object.
Therefore, the operations of this class are centered around the providers Hasse table, that is, the provider data obtained is put into this Hasse table.
The following describes the provider class
It has two attributes:
Public readonly property name () as string
Public readonly property type () as string
A new (xmlattributecollection) Method
This method performs some attribute value setting operations to obtain the value from xmlattributecollection.
In addition, some other XML Attribute Sets are put into a namevaluecollection set.
The Web. config node is as follows:
<Data defaultprovider = "sqldataprovider">
<Providers>
<Clear/>
<Add name = "sqldataprovider" type = "dotnetnuke. Data. sqldataprovider, dotnetnuke. Handler" connectionstringname = "sitesqlserver" upgradeconnectionstring = "" providerpath = "~ \ Providers \ dataproviders \ sqldataprovider \ "objectqualifier =" "templatefile =" dotnetnuke_template.mdf "databaseowner =" DBO "/>
</Providers>
</Data>
Application:
Public Function getapplicationname (byval portalid as integer) as string
Dim appname as string
'Get the data provider Configuration
Dim _ providerconfiguration as providerconfiguration = providerconfiguration. getproviderconfiguration ("data ")
// Load the providerconfiguration Class Object
'Read the configuration specific information for the current provider
Dim objprovider as provider = ctype (_ providerconfiguration. Providers (_ providerconfiguration. defaultprovider), provider)
// Read the defaultprovider value in the providers Hasse table
'Get the object qualifier frm the provider Configuration
Dim _ objectqualifier as string = objprovider. attributes ("objectqualifier ")
If _ objectqualifier <> "" And _ objectqualifier. endswith ("_") = false then
_ Objectqualifier + = "_"
End if
Appname = _ objectqualifier + convert. tostring (portalid)
Return appname
End Function
What are the functions of the above three classes in a system? I personally think it is for flexibility. We can directly modify the provider value in the config file to realize which provider we need instead of re-compiling, A system is well maintained and flexible.
Design technical points:
Configmanager class (use of the getsection () method)
Iconfigurationsectionhandler interface-providerconfigurationhandler inherits this interface
Use of hashtable, namevaluecollection, xmlattributecollection, and xmlnode