Add Test Connection String
This commit is contained in:
parent
9f55f78e86
commit
68dc46c6b4
@ -445,6 +445,10 @@
|
||||
<None Include="Resources\folder_go.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Controls.LookupGrid\LookupControl.vbproj">
|
||||
<Project>{3dcd6d1a-c830-4241-b7e4-27430e7ea483}</Project>
|
||||
<Name>LookupControl</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\EDMI_FILE_OPs\EDMIAPI.vbproj">
|
||||
<Project>{5b1171dc-fffe-4813-a20d-786aae47b320}</Project>
|
||||
<Name>EDMIAPI</Name>
|
||||
@ -453,10 +457,6 @@
|
||||
<Project>{991d0231-4623-496d-8bd0-9ca906029cbc}</Project>
|
||||
<Name>Filesystem</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\LookupGrid\LookupControl.vbproj">
|
||||
<Project>{3DCD6D1A-C830-4241-B7E4-27430E7EA483}</Project>
|
||||
<Name>LookupControl</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Modules.Config\Config.vbproj">
|
||||
<Project>{44982f9b-6116-44e2-85d0-f39650b1ef99}</Project>
|
||||
<Name>Config</Name>
|
||||
|
||||
@ -2,4 +2,8 @@
|
||||
Public Class ConnectionStringAttribute
|
||||
Inherits Attribute
|
||||
End Class
|
||||
|
||||
Public Class ConnectionStringTestAttribute
|
||||
Inherits Attribute
|
||||
End Class
|
||||
End Class
|
||||
|
||||
@ -14,7 +14,8 @@ Public Class ConfigManager(Of T)
|
||||
Private ReadOnly _UserPath As String
|
||||
Private ReadOnly _ComputerPath As String
|
||||
|
||||
Private _ForceUserConfig As Boolean
|
||||
Private _ForceUserConfig As Boolean = False
|
||||
Private _TestMode As Boolean = False
|
||||
|
||||
''' <summary>
|
||||
''' The blueprint class from which the default config is created
|
||||
@ -90,6 +91,14 @@ Public Class ConfigManager(Of T)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Copies all properties from Source to Target, except those who have an attribute
|
||||
''' listed in ExcludedAttributeTypes
|
||||
''' </summary>
|
||||
''' <typeparam name="T">Config Class</typeparam>
|
||||
''' <param name="Source">Source config object</param>
|
||||
''' <param name="Target">Target config object</param>
|
||||
''' <param name="ExcludedAttributeTypes">List of Attribute type to exclude</param>
|
||||
Private Sub CopyValues(Of T)(Source As T, Target As T, Optional ExcludedAttributeTypes As List(Of Type) = Nothing)
|
||||
Dim oType As Type = GetType(T)
|
||||
Dim oExcludedAttributeTypes = IIf(IsNothing(ExcludedAttributeTypes), New List(Of Type), ExcludedAttributeTypes)
|
||||
@ -126,12 +135,7 @@ Public Class ConfigManager(Of T)
|
||||
If File.Exists(_ComputerPath) Then
|
||||
Try
|
||||
Dim oComputerConfig = ReadFromFile(_ComputerPath)
|
||||
|
||||
' if a computer config exists, copy values
|
||||
' from computer config to final config
|
||||
If Not IsNothing(oComputerConfig) Then
|
||||
CopyValues(oComputerConfig, Config)
|
||||
End If
|
||||
CopyValues(oComputerConfig, Config)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("Computer config could not be loaded!")
|
||||
@ -151,12 +155,16 @@ Public Class ConfigManager(Of T)
|
||||
' if user config exists
|
||||
If Not IsNothing(oUserConfig) Then
|
||||
Dim oExcludedAttributes As New List(Of Type)
|
||||
If Not _ForceUserConfig Then
|
||||
oExcludedAttributes.Add(GetType(ConnectionStringAttribute))
|
||||
End If
|
||||
|
||||
' Copy values from user config to final config
|
||||
CopyValues(oUserConfig, Config, oExcludedAttributes)
|
||||
If _ForceUserConfig Then
|
||||
CopyValues(oUserConfig, Config, New List(Of Type))
|
||||
Else
|
||||
CopyValues(oUserConfig, Config, New List(Of Type) From {
|
||||
GetType(ConnectionStringAttribute),
|
||||
GetType(ConnectionStringTestAttribute)
|
||||
})
|
||||
End If
|
||||
End If
|
||||
|
||||
'Dim oConnectionProperty = TestHasAttribute(oConfig, GetType(ConnectionStringAttribute))
|
||||
@ -182,14 +190,14 @@ Public Class ConfigManager(Of T)
|
||||
Return oConfig
|
||||
End Function
|
||||
|
||||
Private Function TestHasAttribute(Config As T, AttributeType As Type) As String
|
||||
Private Function TestHasAttribute(Config As T, AttributeType As Type) As Boolean
|
||||
For Each oProperty As PropertyInfo In Config.GetType.GetProperties()
|
||||
If Attribute.IsDefined(oProperty, GetType(ConnectionStringAttribute)) Then
|
||||
Return oProperty.Name
|
||||
Return True
|
||||
End If
|
||||
Next
|
||||
|
||||
Return Nothing
|
||||
Return False
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
|
||||
@ -4,4 +4,7 @@ Public Class ConfigSample
|
||||
|
||||
<ConnectionString>
|
||||
Public Property ConnectionString As String
|
||||
|
||||
<ConnectionStringTest>
|
||||
Public Property ConnectionStringTest As String
|
||||
End Class
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user