@@ -3,6 +3,7 @@ namespace Atc.Installer.Wpf.ComponentProvider.ViewModels;
3
3
4
4
public class ConfigurationSettingsJsonFileViewModel : ViewModelBase
5
5
{
6
+ private readonly ComponentProviderViewModel ? refComponentProviderViewModel ;
6
7
private string fileName = string . Empty ;
7
8
8
9
public ConfigurationSettingsJsonFileViewModel ( )
@@ -13,7 +14,12 @@ public ConfigurationSettingsJsonFileViewModel(
13
14
ComponentProviderViewModel refComponentProviderViewModel ,
14
15
ConfigurationSettingsFileOption configurationSettingsFileOption )
15
16
{
16
- Populate ( refComponentProviderViewModel , configurationSettingsFileOption ) ;
17
+ ArgumentNullException . ThrowIfNull ( refComponentProviderViewModel ) ;
18
+ ArgumentNullException . ThrowIfNull ( configurationSettingsFileOption ) ;
19
+
20
+ this . refComponentProviderViewModel = refComponentProviderViewModel ;
21
+
22
+ Populate ( configurationSettingsFileOption ) ;
17
23
}
18
24
19
25
public string FileName
@@ -29,10 +35,8 @@ public string FileName
29
35
public ObservableCollectionEx < KeyValueTemplateItemViewModel > Settings { get ; init ; } = new ( ) ;
30
36
31
37
public void Populate (
32
- ComponentProviderViewModel refComponentProviderViewModel ,
33
38
ConfigurationSettingsFileOption configurationSettingsFileOption )
34
39
{
35
- ArgumentNullException . ThrowIfNull ( refComponentProviderViewModel ) ;
36
40
ArgumentNullException . ThrowIfNull ( configurationSettingsFileOption ) ;
37
41
38
42
FileName = configurationSettingsFileOption . FileName ;
@@ -46,6 +50,11 @@ public void Populate(
46
50
var value = keyValuePair . Value . ToString ( ) ! ;
47
51
if ( value . ContainsTemplateKeyBrackets ( ) )
48
52
{
53
+ if ( refComponentProviderViewModel is null )
54
+ {
55
+ continue ;
56
+ }
57
+
49
58
var ( resolvedValue , templateLocations ) = refComponentProviderViewModel . ResolveValueAndTemplateLocations ( value ) ;
50
59
51
60
if ( templateLocations . Count > 0 )
@@ -72,6 +81,29 @@ public void Populate(
72
81
Settings . SuppressOnChangedNotification = false ;
73
82
}
74
83
84
+ public void ResolveValueAndTemplateLocations ( )
85
+ {
86
+ if ( refComponentProviderViewModel is null )
87
+ {
88
+ return ;
89
+ }
90
+
91
+ foreach ( var keyValuePair in Settings )
92
+ {
93
+ var value = keyValuePair . Value . ToString ( ) ! ;
94
+ if ( ! value . ContainsTemplateKeyBrackets ( ) )
95
+ {
96
+ continue ;
97
+ }
98
+
99
+ var ( resolvedValue , templateLocations ) = refComponentProviderViewModel . ResolveValueAndTemplateLocations ( value ) ;
100
+ if ( templateLocations . Count > 0 )
101
+ {
102
+ keyValuePair . Value = resolvedValue ;
103
+ }
104
+ }
105
+ }
106
+
75
107
public override string ToString ( )
76
108
=> $ "{ nameof ( FileName ) } : { FileName } , { nameof ( Settings ) } .Count: { Settings ? . Count } ";
77
109
}
0 commit comments