Add UserConfig Prefix and Config Migration

This commit is contained in:
Jonathan Jenne 2020-12-17 16:55:17 +01:00
parent 82897a2f12
commit 651c5bc2d6
5 changed files with 40 additions and 8 deletions

View File

@ -14,6 +14,9 @@
<setting name="UseAppConfigConString" serializeAs="String"> <setting name="UseAppConfigConString" serializeAs="String">
<value>True</value> <value>True</value>
</setting> </setting>
<setting name="UserConfig_Prefix" serializeAs="String">
<value>TEST</value>
</setting>
</DD_ProcessManager.My.MySettings> </DD_ProcessManager.My.MySettings>
<DevExpress.LookAndFeel.Design.AppSettings> <DevExpress.LookAndFeel.Design.AppSettings>
<setting name="DefaultAppSkin" serializeAs="String"> <setting name="DefaultAppSkin" serializeAs="String">

View File

@ -8,7 +8,7 @@ Public Class ClassConfig
Public Property ConnectionStringTest As String = "" Public Property ConnectionStringTest As String = ""
<ConnectionStringAppServer> <ConnectionStringAppServer>
Public Property ConnectionStringAppServer As String = "" Public Property ConnectionStringAppServer As String = ""
<AppServerConfig> <ConnectionStringAppServer>
Public Property AppServerConfig As String = "" Public Property AppServerConfig As String = ""
Public Property TestMode As Boolean = False Public Property TestMode As Boolean = False

View File

@ -42,15 +42,32 @@ Public Class ClassInit
<STAThread()> <STAThread()>
Public Sub InitUserConfig() Public Sub InitUserConfig()
Try Try
Dim AppdataPath = Application.UserAppDataPath Dim oUserAppDataPath As String = Application.UserAppDataPath
Dim CommonAppDataPath = Application.CommonAppDataPath Dim oLegacyAppDataPath As String = Application.UserAppDataPath
Dim StartupPath = Application.StartupPath Dim oCommonAppDataPath = Application.CommonAppDataPath
If My.Settings.UseAppConfigConString = True Then Dim oStartupPath = Application.StartupPath
AppdataPath = StartupPath Dim oConfigPrefix As String = My.Settings.UserConfig_Prefix
CommonAppDataPath = StartupPath
' If prefix is configured, use it to create a subfolder in app data and migrate existing data
If oConfigPrefix.Length > 0 Then
oUserAppDataPath = IO.Path.Combine(Application.UserAppDataPath, oConfigPrefix)
Dim oConfigUtils As New ConfigUtils(LOGCONFIG)
If oConfigUtils.TestMigrationNeeded(oUserAppDataPath) Then
LOGCONFIG.Debug = True
oConfigUtils.MigrateConfig(oLegacyAppDataPath, oUserAppDataPath)
LOGCONFIG.Debug = False
End If
End If End If
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, AppdataPath, CommonAppDataPath, StartupPath) ' If AppConfig from Startup Path should be forced, rewrite the common app data path
If My.Settings.UseAppConfigConString = True Then
' UserAppDataPath = StartupPath
oCommonAppDataPath = oStartupPath
End If
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, oUserAppDataPath, oCommonAppDataPath, oStartupPath)
LOGGER.Info("Config loaded") LOGGER.Info("Config loaded")
If CONFIG.Config.ConnectionStringTest <> String.Empty And CONFIG.Config.TestMode = True Then If CONFIG.Config.ConnectionStringTest <> String.Empty And CONFIG.Config.TestMode = True Then

View File

@ -297,6 +297,15 @@ Namespace My
Return CType(Me("UseAppConfigConString"),Boolean) Return CType(Me("UseAppConfigConString"),Boolean)
End Get End Get
End Property End Property
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("TEST")> _
Public ReadOnly Property UserConfig_Prefix() As String
Get
Return CType(Me("UserConfig_Prefix"),String)
End Get
End Property
End Class End Class
End Namespace End Namespace

View File

@ -67,5 +67,8 @@
<Setting Name="UseAppConfigConString" Type="System.Boolean" Scope="Application"> <Setting Name="UseAppConfigConString" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">True</Value> <Value Profile="(Default)">True</Value>
</Setting> </Setting>
<Setting Name="UserConfig_Prefix" Type="System.String" Scope="Application">
<Value Profile="(Default)">TEST</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>