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">
<value>True</value>
</setting>
<setting name="UserConfig_Prefix" serializeAs="String">
<value>TEST</value>
</setting>
</DD_ProcessManager.My.MySettings>
<DevExpress.LookAndFeel.Design.AppSettings>
<setting name="DefaultAppSkin" serializeAs="String">

View File

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

View File

@ -42,15 +42,32 @@ Public Class ClassInit
<STAThread()>
Public Sub InitUserConfig()
Try
Dim AppdataPath = Application.UserAppDataPath
Dim CommonAppDataPath = Application.CommonAppDataPath
Dim StartupPath = Application.StartupPath
If My.Settings.UseAppConfigConString = True Then
AppdataPath = StartupPath
CommonAppDataPath = StartupPath
Dim oUserAppDataPath As String = Application.UserAppDataPath
Dim oLegacyAppDataPath As String = Application.UserAppDataPath
Dim oCommonAppDataPath = Application.CommonAppDataPath
Dim oStartupPath = Application.StartupPath
Dim oConfigPrefix As String = My.Settings.UserConfig_Prefix
' 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
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")
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)
End Get
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 Namespace

View File

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