Add Test Connection String

This commit is contained in:
Jonathan Jenne 2019-04-15 16:40:02 +02:00
parent 9f55f78e86
commit 68dc46c6b4
4 changed files with 33 additions and 18 deletions

View File

@ -445,6 +445,10 @@
<None Include="Resources\folder_go.png" /> <None Include="Resources\folder_go.png" />
</ItemGroup> </ItemGroup>
<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"> <ProjectReference Include="..\EDMI_FILE_OPs\EDMIAPI.vbproj">
<Project>{5b1171dc-fffe-4813-a20d-786aae47b320}</Project> <Project>{5b1171dc-fffe-4813-a20d-786aae47b320}</Project>
<Name>EDMIAPI</Name> <Name>EDMIAPI</Name>
@ -453,10 +457,6 @@
<Project>{991d0231-4623-496d-8bd0-9ca906029cbc}</Project> <Project>{991d0231-4623-496d-8bd0-9ca906029cbc}</Project>
<Name>Filesystem</Name> <Name>Filesystem</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\LookupGrid\LookupControl.vbproj">
<Project>{3DCD6D1A-C830-4241-B7E4-27430E7EA483}</Project>
<Name>LookupControl</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Config\Config.vbproj"> <ProjectReference Include="..\Modules.Config\Config.vbproj">
<Project>{44982f9b-6116-44e2-85d0-f39650b1ef99}</Project> <Project>{44982f9b-6116-44e2-85d0-f39650b1ef99}</Project>
<Name>Config</Name> <Name>Config</Name>

View File

@ -2,4 +2,8 @@
Public Class ConnectionStringAttribute Public Class ConnectionStringAttribute
Inherits Attribute Inherits Attribute
End Class End Class
Public Class ConnectionStringTestAttribute
Inherits Attribute
End Class
End Class End Class

View File

@ -14,7 +14,8 @@ Public Class ConfigManager(Of T)
Private ReadOnly _UserPath As String Private ReadOnly _UserPath As String
Private ReadOnly _ComputerPath As String Private ReadOnly _ComputerPath As String
Private _ForceUserConfig As Boolean Private _ForceUserConfig As Boolean = False
Private _TestMode As Boolean = False
''' <summary> ''' <summary>
''' The blueprint class from which the default config is created ''' The blueprint class from which the default config is created
@ -90,6 +91,14 @@ Public Class ConfigManager(Of T)
End Try End Try
End Function 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) 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 oType As Type = GetType(T)
Dim oExcludedAttributeTypes = IIf(IsNothing(ExcludedAttributeTypes), New List(Of Type), ExcludedAttributeTypes) Dim oExcludedAttributeTypes = IIf(IsNothing(ExcludedAttributeTypes), New List(Of Type), ExcludedAttributeTypes)
@ -126,12 +135,7 @@ Public Class ConfigManager(Of T)
If File.Exists(_ComputerPath) Then If File.Exists(_ComputerPath) Then
Try Try
Dim oComputerConfig = ReadFromFile(_ComputerPath) Dim oComputerConfig = ReadFromFile(_ComputerPath)
CopyValues(oComputerConfig, Config)
' if a computer config exists, copy values
' from computer config to final config
If Not IsNothing(oComputerConfig) Then
CopyValues(oComputerConfig, Config)
End If
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
_Logger.Warn("Computer config could not be loaded!") _Logger.Warn("Computer config could not be loaded!")
@ -151,12 +155,16 @@ Public Class ConfigManager(Of T)
' if user config exists ' if user config exists
If Not IsNothing(oUserConfig) Then If Not IsNothing(oUserConfig) Then
Dim oExcludedAttributes As New List(Of Type) 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 ' 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 End If
'Dim oConnectionProperty = TestHasAttribute(oConfig, GetType(ConnectionStringAttribute)) 'Dim oConnectionProperty = TestHasAttribute(oConfig, GetType(ConnectionStringAttribute))
@ -182,14 +190,14 @@ Public Class ConfigManager(Of T)
Return oConfig Return oConfig
End Function 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() For Each oProperty As PropertyInfo In Config.GetType.GetProperties()
If Attribute.IsDefined(oProperty, GetType(ConnectionStringAttribute)) Then If Attribute.IsDefined(oProperty, GetType(ConnectionStringAttribute)) Then
Return oProperty.Name Return True
End If End If
Next Next
Return Nothing Return False
End Function End Function
''' <summary> ''' <summary>

View File

@ -4,4 +4,7 @@ Public Class ConfigSample
<ConnectionString> <ConnectionString>
Public Property ConnectionString As String Public Property ConnectionString As String
<ConnectionStringTest>
Public Property ConnectionStringTest As String
End Class End Class