Improve Config
This commit is contained in:
parent
914ba9dc90
commit
191b3010bb
@ -1,3 +1,43 @@
|
|||||||
Public Class ClassConfig
|
Imports System.ComponentModel
|
||||||
Public Property ServiceConnection As String = String.Empty
|
Imports System.Runtime.CompilerServices
|
||||||
|
Imports System.Xml.Serialization
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' --- User Config for EDMI ---
|
||||||
|
'''
|
||||||
|
''' All settings are simple properties that should have a default value where possible
|
||||||
|
'''
|
||||||
|
''' More complex properties (for example, ServiceConnection) are built from simple ones,
|
||||||
|
''' should be readonly and have an `XmlIgnore` Attribute to prevent them from being saved to the config file.
|
||||||
|
'''
|
||||||
|
''' They can make saving and loading complex properties more easy.
|
||||||
|
'''
|
||||||
|
''' The config is loaded with `ConfigManager` which is initialized in ApplicationEvents
|
||||||
|
''' to ensure that the config is loaded before any of the forms (that might need a config)
|
||||||
|
'''
|
||||||
|
''' The config object can be accessed in two ways:
|
||||||
|
'''
|
||||||
|
''' - My.ConfigManager.Config
|
||||||
|
''' - My.Config (which simply points to My.ConfigManager.Config)
|
||||||
|
'''
|
||||||
|
''' After changing a config value, My.ConfigManager.Save() must be called to persist the change in the config file
|
||||||
|
''' </summary>
|
||||||
|
Public Class ClassConfig
|
||||||
|
' === Complex/Readonly Config Properties
|
||||||
|
<XmlIgnore>
|
||||||
|
Public ReadOnly Property ServiceConnection As String
|
||||||
|
Get
|
||||||
|
If ServiceIP = String.Empty Or ServicePort = -1 Then
|
||||||
|
Return String.Empty
|
||||||
|
Else
|
||||||
|
Return $"net.tcp://{ServiceIP}:{ServicePort}/DigitalData/Services/Main"
|
||||||
|
End If
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
|
' === Simple/Actual Config Properties ===
|
||||||
|
Public Property ServiceIP As String = String.Empty
|
||||||
|
Public Property ServicePort As Integer = -1
|
||||||
|
Public Property LogDebug As Boolean = False
|
||||||
|
Public Property UserLanguage As String = "de-DE"
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -12,6 +12,11 @@ Namespace My
|
|||||||
<HideModuleName()>
|
<HideModuleName()>
|
||||||
Module Extension
|
Module Extension
|
||||||
Property ConfigManager As ConfigManager(Of ClassConfig)
|
Property ConfigManager As ConfigManager(Of ClassConfig)
|
||||||
|
ReadOnly Property Config As ClassConfig
|
||||||
|
Get
|
||||||
|
Return ConfigManager.Config
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
Property LogConfig As LogConfig
|
Property LogConfig As LogConfig
|
||||||
Property ChannelFactory As ChannelFactory(Of IEDMServiceChannel)
|
Property ChannelFactory As ChannelFactory(Of IEDMServiceChannel)
|
||||||
Property Channel As IEDMServiceChannel
|
Property Channel As IEDMServiceChannel
|
||||||
|
|||||||
@ -6,6 +6,11 @@ Public Class frmConfigService
|
|||||||
Private Sub frmServiceConfig_Load(sender As Object, e As EventArgs) Handles Me.Load
|
Private Sub frmServiceConfig_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||||
_Init = New ClassInit()
|
_Init = New ClassInit()
|
||||||
|
|
||||||
|
If My.ConfigManager.Config.ServiceConnection <> String.Empty Then
|
||||||
|
txtIPAddress.Text = My.ConfigManager.Config.ServiceIP
|
||||||
|
txtPort.Text = My.ConfigManager.Config.ServicePort
|
||||||
|
End If
|
||||||
|
|
||||||
txtIPAddress.Focus()
|
txtIPAddress.Focus()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
@ -15,12 +20,14 @@ Public Class frmConfigService
|
|||||||
Dim oEndpointURL = $"net.tcp://{oIPAddress}:{oPort}/DigitalData/Services/Main"
|
Dim oEndpointURL = $"net.tcp://{oIPAddress}:{oPort}/DigitalData/Services/Main"
|
||||||
Dim oResult As ConnectionTestResult
|
Dim oResult As ConnectionTestResult
|
||||||
|
|
||||||
|
My.Config.ServiceIP = oIPAddress
|
||||||
|
My.Config.ServicePort = Integer.Parse(oPort)
|
||||||
|
|
||||||
lblStatus.Text = "Verbindung wird hergestellt..."
|
lblStatus.Text = "Verbindung wird hergestellt..."
|
||||||
oResult = Await _Init.TestConnectionAsync(oEndpointURL)
|
oResult = Await _Init.TestConnectionAsync(My.ConfigManager.Config.ServiceConnection)
|
||||||
|
|
||||||
If oResult = ConnectionTestResult.Successful Then
|
If oResult = ConnectionTestResult.Successful Then
|
||||||
' Save Endpoint URL
|
' Save Endpoint URL
|
||||||
My.ConfigManager.Config.ServiceConnection = oEndpointURL
|
|
||||||
My.ConfigManager.Save()
|
My.ConfigManager.Save()
|
||||||
'My.Settings.ICMServiceAddress = oEndpointURL
|
'My.Settings.ICMServiceAddress = oEndpointURL
|
||||||
lblStatus.Text = "Verbindung hergestellt."
|
lblStatus.Text = "Verbindung hergestellt."
|
||||||
|
|||||||
22
EDMI_ClientSuite/frmConfigUser.Designer.vb
generated
22
EDMI_ClientSuite/frmConfigUser.Designer.vb
generated
@ -1,9 +1,9 @@
|
|||||||
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
|
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
||||||
Partial Class frmConfigUser
|
Partial Class frmConfigUser
|
||||||
Inherits System.Windows.Forms.Form
|
Inherits System.Windows.Forms.Form
|
||||||
|
|
||||||
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
|
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
|
||||||
<System.Diagnostics.DebuggerNonUserCode()> _
|
<System.Diagnostics.DebuggerNonUserCode()>
|
||||||
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
||||||
Try
|
Try
|
||||||
If disposing AndAlso components IsNot Nothing Then
|
If disposing AndAlso components IsNot Nothing Then
|
||||||
@ -20,11 +20,10 @@ Partial Class frmConfigUser
|
|||||||
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
|
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
|
||||||
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
|
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
|
||||||
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
|
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
|
||||||
<System.Diagnostics.DebuggerStepThrough()> _
|
<System.Diagnostics.DebuggerStepThrough()>
|
||||||
Private Sub InitializeComponent()
|
Private Sub InitializeComponent()
|
||||||
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmConfigUser))
|
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmConfigUser))
|
||||||
Me.TabPageSupport = New DevExpress.XtraTab.XtraTabPage()
|
Me.TabPageSupport = New DevExpress.XtraTab.XtraTabPage()
|
||||||
Me.SimpleButton1 = New DevExpress.XtraEditors.SimpleButton()
|
|
||||||
Me.btnAppFolder = New DevExpress.XtraEditors.SimpleButton()
|
Me.btnAppFolder = New DevExpress.XtraEditors.SimpleButton()
|
||||||
Me.btnLogFolder = New DevExpress.XtraEditors.SimpleButton()
|
Me.btnLogFolder = New DevExpress.XtraEditors.SimpleButton()
|
||||||
Me.Button4 = New System.Windows.Forms.Button()
|
Me.Button4 = New System.Windows.Forms.Button()
|
||||||
@ -43,7 +42,6 @@ Partial Class frmConfigUser
|
|||||||
'
|
'
|
||||||
'TabPageSupport
|
'TabPageSupport
|
||||||
'
|
'
|
||||||
Me.TabPageSupport.Controls.Add(Me.SimpleButton1)
|
|
||||||
Me.TabPageSupport.Controls.Add(Me.btnAppFolder)
|
Me.TabPageSupport.Controls.Add(Me.btnAppFolder)
|
||||||
Me.TabPageSupport.Controls.Add(Me.btnLogFolder)
|
Me.TabPageSupport.Controls.Add(Me.btnLogFolder)
|
||||||
Me.TabPageSupport.Controls.Add(Me.Button4)
|
Me.TabPageSupport.Controls.Add(Me.Button4)
|
||||||
@ -51,18 +49,9 @@ Partial Class frmConfigUser
|
|||||||
Me.TabPageSupport.Controls.Add(Me.chkLogErrorsOnly)
|
Me.TabPageSupport.Controls.Add(Me.chkLogErrorsOnly)
|
||||||
Me.TabPageSupport.ImageOptions.Image = CType(resources.GetObject("TabPageSupport.ImageOptions.Image"), System.Drawing.Image)
|
Me.TabPageSupport.ImageOptions.Image = CType(resources.GetObject("TabPageSupport.ImageOptions.Image"), System.Drawing.Image)
|
||||||
Me.TabPageSupport.Name = "TabPageSupport"
|
Me.TabPageSupport.Name = "TabPageSupport"
|
||||||
Me.TabPageSupport.Size = New System.Drawing.Size(703, 448)
|
Me.TabPageSupport.Size = New System.Drawing.Size(700, 444)
|
||||||
Me.TabPageSupport.Text = "Support"
|
Me.TabPageSupport.Text = "Support"
|
||||||
'
|
'
|
||||||
'SimpleButton1
|
|
||||||
'
|
|
||||||
Me.SimpleButton1.ImageOptions.Image = CType(resources.GetObject("SimpleButton1.ImageOptions.Image"), System.Drawing.Image)
|
|
||||||
Me.SimpleButton1.Location = New System.Drawing.Point(349, 100)
|
|
||||||
Me.SimpleButton1.Name = "SimpleButton1"
|
|
||||||
Me.SimpleButton1.Size = New System.Drawing.Size(164, 36)
|
|
||||||
Me.SimpleButton1.TabIndex = 21
|
|
||||||
Me.SimpleButton1.Text = "AppData Ordner öffnen"
|
|
||||||
'
|
|
||||||
'btnAppFolder
|
'btnAppFolder
|
||||||
'
|
'
|
||||||
Me.btnAppFolder.ImageOptions.Image = CType(resources.GetObject("btnAppFolder.ImageOptions.Image"), System.Drawing.Image)
|
Me.btnAppFolder.ImageOptions.Image = CType(resources.GetObject("btnAppFolder.ImageOptions.Image"), System.Drawing.Image)
|
||||||
@ -135,7 +124,7 @@ Partial Class frmConfigUser
|
|||||||
Me.TabPageMain.Controls.Add(Me.cmbLanguage)
|
Me.TabPageMain.Controls.Add(Me.cmbLanguage)
|
||||||
Me.TabPageMain.ImageOptions.Image = CType(resources.GetObject("TabPageMain.ImageOptions.Image"), System.Drawing.Image)
|
Me.TabPageMain.ImageOptions.Image = CType(resources.GetObject("TabPageMain.ImageOptions.Image"), System.Drawing.Image)
|
||||||
Me.TabPageMain.Name = "TabPageMain"
|
Me.TabPageMain.Name = "TabPageMain"
|
||||||
Me.TabPageMain.Size = New System.Drawing.Size(703, 448)
|
Me.TabPageMain.Size = New System.Drawing.Size(700, 444)
|
||||||
Me.TabPageMain.Text = "Allgemein"
|
Me.TabPageMain.Text = "Allgemein"
|
||||||
'
|
'
|
||||||
'Label1
|
'Label1
|
||||||
@ -197,5 +186,4 @@ Partial Class frmConfigUser
|
|||||||
Friend WithEvents cmbLanguage As ComboBox
|
Friend WithEvents cmbLanguage As ComboBox
|
||||||
Friend WithEvents btnLogFolder As DevExpress.XtraEditors.SimpleButton
|
Friend WithEvents btnLogFolder As DevExpress.XtraEditors.SimpleButton
|
||||||
Friend WithEvents btnAppFolder As DevExpress.XtraEditors.SimpleButton
|
Friend WithEvents btnAppFolder As DevExpress.XtraEditors.SimpleButton
|
||||||
Friend WithEvents SimpleButton1 As DevExpress.XtraEditors.SimpleButton
|
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -118,15 +118,6 @@
|
|||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||||
<data name="SimpleButton1.ImageOptions.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>
|
|
||||||
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m
|
|
||||||
dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAArdEVYdFRpdGxlAE9wZW47Rm9sZGVyO0JhcnM7Umli
|
|
||||||
Ym9uO1N0YW5kYXJkO0xvYWTxw8RjAAAAb0lEQVQ4T6XQ0Q2AIAwEUBbsMs7Q0ZzHFeqVRIJ6VQof7+fC
|
|
||||||
XUiLmS2hYQYNM4qqChjhOS31fICVL8JKvb+BSBueHUB3cQCGB+oxmWjgVjj2TcAC8hzwx1+Fl34gXYb2
|
|
||||||
g6ky1BtMl1295AoajrNyArCYwjN4ThJYAAAAAElFTkSuQmCC
|
|
||||||
</value>
|
|
||||||
</data>
|
|
||||||
<data name="btnAppFolder.ImageOptions.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="btnAppFolder.ImageOptions.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m
|
||||||
|
|||||||
@ -13,6 +13,8 @@ Public Class frmConfigUser
|
|||||||
|
|
||||||
Private Sub frmUserBasics_Load(sender As Object, e As EventArgs) Handles Me.Load
|
Private Sub frmUserBasics_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||||
_Logger = My.LogConfig.GetLogger()
|
_Logger = My.LogConfig.GetLogger()
|
||||||
|
|
||||||
|
chkLogErrorsOnly.Checked = Not My.Config.LogDebug
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub btnLogFolder_Click(sender As Object, e As EventArgs) Handles btnLogFolder.Click
|
Private Sub btnLogFolder_Click(sender As Object, e As EventArgs) Handles btnLogFolder.Click
|
||||||
@ -23,8 +25,10 @@ Public Class frmConfigUser
|
|||||||
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
|
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
|
Private Sub chkLogErrorsOnly_CheckedChanged(sender As Object, e As EventArgs) Handles chkLogErrorsOnly.CheckedChanged
|
||||||
Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
|
Dim oLogDebug = Not chkLogErrorsOnly.Checked
|
||||||
MessageBox.Show(config.FilePath)
|
My.LogConfig.Debug = oLogDebug
|
||||||
|
My.Config.LogDebug = oLogDebug
|
||||||
|
My.ConfigManager.Save()
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
Loading…
x
Reference in New Issue
Block a user