rework Settings in Pilz.Configuration
This commit is contained in:
40
Pilz.Configuration/Settings.vb
Normal file
40
Pilz.Configuration/Settings.vb
Normal file
@@ -0,0 +1,40 @@
|
||||
Imports System.Runtime
|
||||
|
||||
Imports Newtonsoft.Json
|
||||
|
||||
Public Class Settings
|
||||
Implements ISettings
|
||||
|
||||
<JsonProperty(NameOf(Settings))>
|
||||
Private ReadOnly mySettings As New Dictionary(Of String, IChildSettings)
|
||||
|
||||
<JsonIgnore>
|
||||
Public ReadOnly Property Settings As IReadOnlyCollection(Of IChildSettings) Implements ISettings.Settings
|
||||
Get
|
||||
Return mySettings.Values
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Function [Get](Of T As IChildSettings)() As T Implements ISettings.Get
|
||||
Return mySettings.Values.OfType(Of T).FirstOrDefault
|
||||
End Function
|
||||
|
||||
Public Sub Reset() Implements ISettings.Reset
|
||||
For Each s In mySettings.Values
|
||||
s.Reset()
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Public Sub Initialize(providers As List(Of ISettingsProvider)) Implements ISettings.Initialize
|
||||
For Each provider In providers
|
||||
For Each identifier In provider.GetSettingsIdentifiers
|
||||
If Not mySettings.ContainsKey(identifier) Then
|
||||
Dim s = provider.CreateInstance(identifier)
|
||||
s.Reset()
|
||||
mySettings.Add(identifier, s)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user