' provider constants - eliminates need for Reflection later
Private Const [ProviderType] As String = "data" ' maps to <sectionGroup> in web.config
' create a variable to store the reference to the instantiated object
Private Shared objProvider As DataProvider
Public Shared Function Instance() As DataProvider
' does the provider reference already exist?
If objProvider Is Nothing Then
Dim strCacheKey As String = [ProviderType] & "provider"
' use the cache because the reflection used later is expensive
Dim objType As Type = CType(DataCache.GetCache(strCacheKey), Type)
If objType Is Nothing Then
' Get the provider configuration based on the type
Dim objProviderConfiguration As ProviderConfiguration = ProviderConfiguration.GetProviderConfiguration([ProviderType])
' The assembly should be in \bin or GAC, so we simply need to get an instance of the type
Try
' Get the typename of the Core DataProvider from web.config
Dim strTypeName As String = CType(objProviderConfiguration.Providers(objProviderConfiguration.DefaultProvider), Provider).Type
' use reflection to get the type of the class that implements the provider
objType = Type.GetType(strTypeName, True)
' 把类型插入到缓存
DataCache.SetCache(strCacheKey, objType)
Catch e As Exception
' Could not load the provider - this is likely due to binary compatibility issues
End Try
End If
' 保存引用
objProvider = CType(Activator.CreateInstance(objType), DataProvider)
End If
Return objProvider
End Function
' 链接模块
Public MustOverride Function GetLinks(ByVal ModuleId As Integer) As IDataReader
Public MustOverride Function GetLink(ByVal ItemID As Integer, ByVal ModuleId As Integer) As IDataReader
Public MustOverride Sub DeleteLink(ByVal ItemID As Integer)
Public MustOverride Sub AddLink(ByVal ModuleId As Integer, ByVal UserName As String, ByVal Title As String, ByVal Url As String, ByVal MobileUrl As String, ByVal ViewOrder As String, ByVal Description As String, ByVal NewWindow As Boolean)
Public MustOverride Sub UpdateLink(ByVal ItemId As Integer, ByVal UserName As String, ByVal Title As String, ByVal Url As String, ByVal MobileUrl As String, ByVal ViewOrder As String, ByVal Description As String, ByVal NewWindow As Boolean)