move config project to Modules.Config folder
This commit is contained in:
126
Modules.Config/Config.vbproj
Normal file
126
Modules.Config/Config.vbproj
Normal file
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{44982F9B-6116-44E2-85D0-F39650B1EF99}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>DigitalData.Modules.Config</RootNamespace>
|
||||
<AssemblyName>DigitalData.Modules.Config</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>DigitalData.Modules.Config.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>DigitalData.Modules.Config.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionStrict>Off</OptionStrict>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
<Import Include="System.Collections" />
|
||||
<Import Include="System.Collections.Generic" />
|
||||
<Import Include="System.Data" />
|
||||
<Import Include="System.Diagnostics" />
|
||||
<Import Include="System.Linq" />
|
||||
<Import Include="System.Xml.Linq" />
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConfigAttributes.vb" />
|
||||
<Compile Include="ConfigManager.vb" />
|
||||
<Compile Include="ConfigSample.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Filesystem\Filesystem.vbproj">
|
||||
<Project>{991d0231-4623-496d-8bd0-9ca906029cbc}</Project>
|
||||
<Name>Filesystem</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
|
||||
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
|
||||
<Name>Logging</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
5
Modules.Config/ConfigAttributes.vb
Normal file
5
Modules.Config/ConfigAttributes.vb
Normal file
@@ -0,0 +1,5 @@
|
||||
Public Class ConfigAttributes
|
||||
Public Class ConnectionStringAttribute
|
||||
Inherits Attribute
|
||||
End Class
|
||||
End Class
|
||||
260
Modules.Config/ConfigManager.vb
Normal file
260
Modules.Config/ConfigManager.vb
Normal file
@@ -0,0 +1,260 @@
|
||||
Imports System.IO
|
||||
Imports System.Reflection
|
||||
Imports System.Xml.Serialization
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Config.ConfigAttributes
|
||||
|
||||
Public Class ConfigManager(Of T)
|
||||
Private Const USER_CONFIG_NAME As String = "UserConfig.xml"
|
||||
Private Const COMPUTER_CONFIG_NAME As String = "ComputerConfig.xml"
|
||||
|
||||
Private ReadOnly _LogConfig As LogConfig
|
||||
Private ReadOnly _Logger As Logger
|
||||
Private ReadOnly _File As Filesystem.File
|
||||
Private ReadOnly _UserPath As String
|
||||
Private ReadOnly _ComputerPath As String
|
||||
|
||||
Private _ForceUserConfig As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' The blueprint class from which the default config is created
|
||||
''' </summary>
|
||||
Private ReadOnly _Blueprint As T
|
||||
Private ReadOnly _Serializer As XmlSerializer
|
||||
|
||||
Public ReadOnly Property Config As T
|
||||
|
||||
''' <summary>
|
||||
''' Creates a new instance of the ConfigManager
|
||||
''' </summary>
|
||||
''' <seealso cref="ConfigSample"/>
|
||||
''' <param name="LogConfig">LogConfig instance</param>
|
||||
''' <param name="UserConfigPath">The path to check for a user config file, eg. AppData</param>
|
||||
''' <param name="ComputerConfigPath">The path to check for a computer config file, eg. ProgramData</param>
|
||||
''' <param name="ForceUserConfig">Override values from ComputerConfig with UserConfig</param>
|
||||
Public Sub New(LogConfig As LogConfig, UserConfigPath As String, ComputerConfigPath As String, Optional ForceUserConfig As Boolean = False)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_File = New Filesystem.File(_LogConfig)
|
||||
|
||||
_UserPath = Path.Combine(UserConfigPath, USER_CONFIG_NAME)
|
||||
_ComputerPath = Path.Combine(ComputerConfigPath, COMPUTER_CONFIG_NAME)
|
||||
_ForceUserConfig = ForceUserConfig
|
||||
|
||||
_Blueprint = Activator.CreateInstance(Of T)
|
||||
_Serializer = New XmlSerializer(_Blueprint.GetType)
|
||||
|
||||
If Not Directory.Exists(UserConfigPath) Then
|
||||
_Logger.Debug("UserConfigPath {0} did not exist and was created", UserConfigPath)
|
||||
Directory.CreateDirectory(UserConfigPath)
|
||||
End If
|
||||
|
||||
If Not _File.TestPathIsDirectory(UserConfigPath) Then
|
||||
_Logger.Warn("UserConfigPath {0} is not a directory", UserConfigPath)
|
||||
Throw New ArgumentException($"Path {UserConfigPath} is not a directory!")
|
||||
End If
|
||||
|
||||
If Not Directory.Exists(ComputerConfigPath) Then
|
||||
_Logger.Debug("ComputerConfigPath {0} did not exist and was created", ComputerConfigPath)
|
||||
Directory.CreateDirectory(ComputerConfigPath)
|
||||
End If
|
||||
|
||||
If Not _File.TestPathIsDirectory(ComputerConfigPath) Then
|
||||
_Logger.Warn("ComputerConfigPath {0} is not a directory", ComputerConfigPath)
|
||||
Throw New ArgumentException($"Path {ComputerConfigPath} is not a directory!")
|
||||
End If
|
||||
|
||||
_Config = LoadConfig()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Creates a new ConfigManager with a single (user)config path
|
||||
''' </summary>
|
||||
''' <param name="LogConfig"></param>
|
||||
''' <param name="ConfigPath"></param>
|
||||
Public Sub New(LogConfig As LogConfig, ConfigPath As String)
|
||||
MyClass.New(LogConfig, ConfigPath, ConfigPath, ForceUserConfig:=True)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Save the current config object to `UserConfigPath`
|
||||
''' </summary>
|
||||
''' <returns>True if save was successful, False otherwise</returns>
|
||||
Public Function Save() As Boolean
|
||||
Try
|
||||
WriteToFile(_Config, _UserPath)
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
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)
|
||||
Dim oProperties = oType.GetProperties().
|
||||
Where(Function(p) p.CanRead And p.CanWrite).
|
||||
Where(Function(p)
|
||||
For Each oAttributeType As Type In oExcludedAttributeTypes
|
||||
If Attribute.IsDefined(p, oAttributeType) Then
|
||||
Return False
|
||||
End If
|
||||
Next
|
||||
Return True
|
||||
End Function)
|
||||
|
||||
For Each oProperty As PropertyInfo In oProperties
|
||||
Dim oValue = oProperty.GetValue(Source, Nothing)
|
||||
If Not IsNothing(oValue) Then
|
||||
oProperty.SetValue(Target, oValue, Nothing)
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Function LoadConfig() As T
|
||||
' first create an empty/default config object
|
||||
Dim oConfig = Activator.CreateInstance(_Blueprint.GetType)
|
||||
' then Try to load computer config
|
||||
oConfig = LoadComputerConfig(oConfig)
|
||||
' now try to load userconfig
|
||||
oConfig = LoadUserConfig(oConfig)
|
||||
Return oConfig
|
||||
End Function
|
||||
|
||||
Private Function LoadComputerConfig(ByVal Config As T) As 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
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("Computer config could not be loaded!")
|
||||
End Try
|
||||
Else
|
||||
_ForceUserConfig = True
|
||||
End If
|
||||
|
||||
Return Config
|
||||
End Function
|
||||
|
||||
Private Function LoadUserConfig(ByVal Config As T) As T
|
||||
If File.Exists(_UserPath) Then
|
||||
Try
|
||||
Dim oUserConfig = ReadFromFile(_UserPath)
|
||||
|
||||
' 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)
|
||||
End If
|
||||
|
||||
'Dim oConnectionProperty = TestHasAttribute(oConfig, GetType(ConnectionStringAttribute))
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("User config could not be loaded!")
|
||||
End Try
|
||||
End If
|
||||
|
||||
Return Config
|
||||
End Function
|
||||
|
||||
Private Function LoadDefaultConfig() As T
|
||||
_Logger.Debug("Creating default config in UserPath: {0}", _UserPath)
|
||||
Dim oConfig = Activator.CreateInstance(_Blueprint.GetType)
|
||||
|
||||
Try
|
||||
WriteToFile(oConfig, _UserPath)
|
||||
Catch ex As Exception
|
||||
_Logger.Warn("Could not create default config in UserPath: {0}", _UserPath)
|
||||
End Try
|
||||
|
||||
Return oConfig
|
||||
End Function
|
||||
|
||||
Private Function TestHasAttribute(Config As T, AttributeType As Type) As String
|
||||
For Each oProperty As PropertyInfo In Config.GetType.GetProperties()
|
||||
If Attribute.IsDefined(oProperty, GetType(ConnectionStringAttribute)) Then
|
||||
Return oProperty.Name
|
||||
End If
|
||||
Next
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Serialize a config object to byte array
|
||||
''' </summary>
|
||||
''' <param name="Data"></param>
|
||||
''' <returns></returns>
|
||||
Private Function Serialize(Data As T) As Byte()
|
||||
Try
|
||||
_Logger.Debug("Serializing config object")
|
||||
|
||||
Using oStream = New MemoryStream()
|
||||
_Serializer.Serialize(oStream, Data)
|
||||
Return oStream.ToArray()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Write an object to disk as xml
|
||||
''' </summary>
|
||||
''' <param name="Data">The object to write</param>
|
||||
''' <param name="Path">The file name to write to</param>
|
||||
Private Sub WriteToFile(Data As T, Path As String)
|
||||
Try
|
||||
_Logger.Debug("Saving config to: {0}", Path)
|
||||
Dim oBytes = Serialize(Data)
|
||||
|
||||
Using oFileStream = New FileStream(Path, FileMode.Create, FileAccess.Write)
|
||||
oFileStream.Write(oBytes, 0, oBytes.Length)
|
||||
oFileStream.Flush()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Reads an xml from disk and deserializes to object
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Private Function ReadFromFile(Path As String) As T
|
||||
Try
|
||||
_Logger.Debug("Loading config from: {0}", Path)
|
||||
Dim oConfig As T
|
||||
|
||||
Using oReader As New StreamReader(Path)
|
||||
oConfig = _Serializer.Deserialize(oReader)
|
||||
End Using
|
||||
|
||||
' If oConfig is Nothing, a config file was created but nothing was written to it.
|
||||
' In this case we need to create oConfig from defaults so we have at least some config object
|
||||
If oConfig Is Nothing Then
|
||||
_Logger.Debug("Config file is valid but empty. Loading default values")
|
||||
oConfig = Activator.CreateInstance(_Blueprint.GetType)
|
||||
End If
|
||||
|
||||
Return oConfig
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
7
Modules.Config/ConfigSample.vb
Normal file
7
Modules.Config/ConfigSample.vb
Normal file
@@ -0,0 +1,7 @@
|
||||
Imports DigitalData.Modules.Config.ConfigAttributes
|
||||
|
||||
Public Class ConfigSample
|
||||
|
||||
<ConnectionString>
|
||||
Public Property ConnectionString As String
|
||||
End Class
|
||||
13
Modules.Config/My Project/Application.Designer.vb
generated
Normal file
13
Modules.Config/My Project/Application.Designer.vb
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
10
Modules.Config/My Project/Application.myapp
Normal file
10
Modules.Config/My Project/Application.myapp
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<MySubMain>false</MySubMain>
|
||||
<SingleInstance>false</SingleInstance>
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<ApplicationType>1</ApplicationType>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
||||
35
Modules.Config/My Project/AssemblyInfo.vb
Normal file
35
Modules.Config/My Project/AssemblyInfo.vb
Normal file
@@ -0,0 +1,35 @@
|
||||
Imports System
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
' die einer Assembly zugeordnet sind.
|
||||
|
||||
' Werte der Assemblyattribute überprüfen
|
||||
|
||||
<Assembly: AssemblyTitle("Modules.Config")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("Modules.Config")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2019")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
|
||||
<Assembly: Guid("6e67fba4-81d1-44bb-81f4-16ad52822192")>
|
||||
|
||||
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
'
|
||||
' Hauptversion
|
||||
' Nebenversion
|
||||
' Buildnummer
|
||||
' Revision
|
||||
'
|
||||
' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("0.0.3.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
63
Modules.Config/My Project/Resources.Designer.vb
generated
Normal file
63
Modules.Config/My Project/Resources.Designer.vb
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Imports System
|
||||
|
||||
Namespace My.Resources
|
||||
|
||||
'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||
'-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||
'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||
'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||
'''<summary>
|
||||
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
|
||||
Get
|
||||
If Object.ReferenceEquals(resourceMan, Nothing) Then
|
||||
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("DigitalData.Modules.Config.Resources", GetType(Resources).Assembly)
|
||||
resourceMan = temp
|
||||
End If
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
117
Modules.Config/My Project/Resources.resx
Normal file
117
Modules.Config/My Project/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
73
Modules.Config/My Project/Settings.Designer.vb
generated
Normal file
73
Modules.Config/My Project/Settings.Designer.vb
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Partial Friend NotInheritable Class MySettings
|
||||
Inherits Global.System.Configuration.ApplicationSettingsBase
|
||||
|
||||
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
|
||||
|
||||
#Region "Automatische My.Settings-Speicherfunktion"
|
||||
#If _MyType = "WindowsForms" Then
|
||||
Private Shared addedHandler As Boolean
|
||||
|
||||
Private Shared addedHandlerLockObject As New Object
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
|
||||
If My.Application.SaveMySettingsOnExit Then
|
||||
My.Settings.Save()
|
||||
End If
|
||||
End Sub
|
||||
#End If
|
||||
#End Region
|
||||
|
||||
Public Shared ReadOnly Property [Default]() As MySettings
|
||||
Get
|
||||
|
||||
#If _MyType = "WindowsForms" Then
|
||||
If Not addedHandler Then
|
||||
SyncLock addedHandlerLockObject
|
||||
If Not addedHandler Then
|
||||
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
|
||||
addedHandler = True
|
||||
End If
|
||||
End SyncLock
|
||||
End If
|
||||
#End If
|
||||
Return defaultInstance
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.DigitalData.Modules.Config.My.MySettings
|
||||
Get
|
||||
Return Global.DigitalData.Modules.Config.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
7
Modules.Config/My Project/Settings.settings
Normal file
7
Modules.Config/My Project/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
70
Modules.Config/SampleConfig.vb
Normal file
70
Modules.Config/SampleConfig.vb
Normal file
@@ -0,0 +1,70 @@
|
||||
Imports Config
|
||||
Imports NLog
|
||||
|
||||
''' <summary>
|
||||
''' Sample Config Class inheriting from BaseConfig
|
||||
'''
|
||||
'''
|
||||
'''
|
||||
''' Things this class should do:
|
||||
'''
|
||||
''' - Provide defaults for all values
|
||||
''' - Load the current config using the LoadConfig method of BaseConfig
|
||||
''' - If no configfile was found, it should create a new datatable with only default values
|
||||
''' - If a configfile was found, it should merge the values from this file with the defaults from this class
|
||||
''' - For each propertyname defined in PropertyNames
|
||||
''' - Check for existing value in datatable
|
||||
''' - If a value is present, use it
|
||||
''' - If no value is exists, use the default value
|
||||
''' - Assign the resulting values to class properties
|
||||
''' - Save the new config to disk
|
||||
''' </summary>
|
||||
Public Class SampleConfig
|
||||
Inherits BaseConfig
|
||||
|
||||
Private _logger As Logger
|
||||
|
||||
Public ReadOnly ConnectionString As String
|
||||
Public ReadOnly UniversalViewer As String
|
||||
|
||||
Public Overloads ReadOnly Property PropertyNames As Dictionary(Of String, String)
|
||||
Get
|
||||
Return New Dictionary(Of String, String) From {
|
||||
{"ConnectionString", ""},
|
||||
{"UniversalViewer", ""}
|
||||
}
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub New(LogFactory As LogFactory)
|
||||
MyBase.New(LogFactory)
|
||||
|
||||
_logger = LogFactory.GetCurrentClassLogger()
|
||||
|
||||
' Load the existing values from the config file into PropertyNames
|
||||
' overwriting the default values
|
||||
Dim oDataTable = LoadConfig()
|
||||
|
||||
For Each oRow As DataRow In oDataTable.Rows
|
||||
Dim oValue = oRow.Item(_configValue)
|
||||
Dim oKey = oRow.Item(_configKey)
|
||||
|
||||
PropertyNames.Item(oKey) = oValue
|
||||
Next
|
||||
|
||||
' Assign the merged properties to class properties, optionally converting them beforehand
|
||||
For Each oProperty As KeyValuePair(Of String, String) In PropertyNames
|
||||
Select Case oProperty.Key
|
||||
Case "ConnectionString"
|
||||
ConnectionString = oProperty.Value
|
||||
Case "UniversalViewer"
|
||||
UniversalViewer = oProperty.Value
|
||||
Case Else
|
||||
_logger.Warn("Property {0} was found in PropertyNames but was not assigned to a config property", oProperty.Key)
|
||||
End Select
|
||||
Next
|
||||
|
||||
' Convert the dictionary back to a datatable and save it
|
||||
SaveConfig(ConvertToDataTable(PropertyNames))
|
||||
End Sub
|
||||
End Class
|
||||
4
Modules.Config/packages.config
Normal file
4
Modules.Config/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="4.5.11" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user