Skip to content

Commit a491377

Browse files
Merge pull request #3 from atc-net/bugfix/Resolve-TemplateLookupin-refComponents
Bugfix - resolve template lookup in ref components
2 parents e1daa99 + 482a6f2 commit a491377

File tree

5 files changed

+103
-12
lines changed

5 files changed

+103
-12
lines changed

src/Atc.Installer.Wpf.App/AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
[assembly: AssemblyCompany("atc-net")]
66
[assembly: AssemblyProduct("Atc.Installer")]
77
[assembly: AssemblyTitle("Atc.Installer")]
8-
[assembly: AssemblyVersion("1.0.6.0")]
9-
[assembly: AssemblyInformationalVersion("1.0.6.0")]
10-
[assembly: AssemblyFileVersion("1.0.6.0")]
8+
[assembly: AssemblyVersion("1.0.7.0")]
9+
[assembly: AssemblyInformationalVersion("1.0.7.0")]
10+
[assembly: AssemblyFileVersion("1.0.7.0")]
1111
[assembly: System.Resources.NeutralResourcesLanguage("en")]
1212
[assembly: System.Runtime.Versioning.TargetPlatform("Windows7.0")]
1313
[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows7.0")]

src/Atc.Installer.Wpf.App/MainWindowViewModel.cs

+5
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ private void Populate(
429429
}
430430
}
431431

432+
foreach (var componentProvider in ComponentProviders)
433+
{
434+
componentProvider.ConfigurationSettingsFiles.ResolveValueAndTemplateReferences();
435+
}
436+
432437
ComponentProviders.SuppressOnChangedNotification = false;
433438

434439
if (ComponentProviders.Count > 0)

src/Atc.Installer.Wpf.ComponentProvider/Controls/ConfigurationSettingsFilesViewModel.cs

+19
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ public void ClearAllIsDirty()
108108
}
109109
}
110110

111+
public void ResolveValueAndTemplateReferences()
112+
{
113+
JsonItems.SuppressOnChangedNotification = true;
114+
XmlItems.SuppressOnChangedNotification = true;
115+
116+
foreach (var jsonItem in JsonItems)
117+
{
118+
jsonItem.ResolveValueAndTemplateLocations();
119+
}
120+
121+
foreach (var xmlItem in XmlItems)
122+
{
123+
xmlItem.ResolveValueAndTemplateLocations();
124+
}
125+
126+
JsonItems.SuppressOnChangedNotification = false;
127+
XmlItems.SuppressOnChangedNotification = false;
128+
}
129+
111130
public override string ToString()
112131
=> $"{nameof(JsonItems)}.Count: {JsonItems?.Count}, {nameof(XmlItems)}.Count: {XmlItems?.Count}";
113132

src/Atc.Installer.Wpf.ComponentProvider/ViewModels/ConfigurationSettingsJsonFileViewModel.cs

+35-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Atc.Installer.Wpf.ComponentProvider.ViewModels;
33

44
public class ConfigurationSettingsJsonFileViewModel : ViewModelBase
55
{
6+
private readonly ComponentProviderViewModel? refComponentProviderViewModel;
67
private string fileName = string.Empty;
78

89
public ConfigurationSettingsJsonFileViewModel()
@@ -13,7 +14,12 @@ public ConfigurationSettingsJsonFileViewModel(
1314
ComponentProviderViewModel refComponentProviderViewModel,
1415
ConfigurationSettingsFileOption configurationSettingsFileOption)
1516
{
16-
Populate(refComponentProviderViewModel, configurationSettingsFileOption);
17+
ArgumentNullException.ThrowIfNull(refComponentProviderViewModel);
18+
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);
19+
20+
this.refComponentProviderViewModel = refComponentProviderViewModel;
21+
22+
Populate(configurationSettingsFileOption);
1723
}
1824

1925
public string FileName
@@ -29,10 +35,8 @@ public string FileName
2935
public ObservableCollectionEx<KeyValueTemplateItemViewModel> Settings { get; init; } = new();
3036

3137
public void Populate(
32-
ComponentProviderViewModel refComponentProviderViewModel,
3338
ConfigurationSettingsFileOption configurationSettingsFileOption)
3439
{
35-
ArgumentNullException.ThrowIfNull(refComponentProviderViewModel);
3640
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);
3741

3842
FileName = configurationSettingsFileOption.FileName;
@@ -46,6 +50,11 @@ public void Populate(
4650
var value = keyValuePair.Value.ToString()!;
4751
if (value.ContainsTemplateKeyBrackets())
4852
{
53+
if (refComponentProviderViewModel is null)
54+
{
55+
continue;
56+
}
57+
4958
var (resolvedValue, templateLocations) = refComponentProviderViewModel.ResolveValueAndTemplateLocations(value);
5059

5160
if (templateLocations.Count > 0)
@@ -72,6 +81,29 @@ public void Populate(
7281
Settings.SuppressOnChangedNotification = false;
7382
}
7483

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+
75107
public override string ToString()
76108
=> $"{nameof(FileName)}: {FileName}, {nameof(Settings)}.Count: {Settings?.Count}";
77109
}

src/Atc.Installer.Wpf.ComponentProvider/ViewModels/ConfigurationSettingsXmlFileViewModel.cs

+41-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ namespace Atc.Installer.Wpf.ComponentProvider.ViewModels;
33

44
public class ConfigurationSettingsXmlFileViewModel : ViewModelBase
55
{
6+
private readonly ComponentProviderViewModel? refComponentProviderViewModel;
67
private string fileName = string.Empty;
78

8-
public ConfigurationSettingsXmlFileViewModel()
9-
{
10-
}
11-
129
public ConfigurationSettingsXmlFileViewModel(
1310
ComponentProviderViewModel refComponentProviderViewModel,
1411
ConfigurationSettingsFileOption configurationSettingsFileOption)
1512
{
16-
Populate(refComponentProviderViewModel, configurationSettingsFileOption);
13+
ArgumentNullException.ThrowIfNull(refComponentProviderViewModel);
14+
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);
15+
16+
this.refComponentProviderViewModel = refComponentProviderViewModel;
17+
18+
Populate(configurationSettingsFileOption);
1719
}
1820

1921
public string FileName
@@ -29,7 +31,6 @@ public string FileName
2931
public ObservableCollectionEx<XmlElementViewModel> Settings { get; init; } = new();
3032

3133
public void Populate(
32-
ComponentProviderViewModel refComponentProviderViewModel,
3334
ConfigurationSettingsFileOption configurationSettingsFileOption)
3435
{
3536
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);
@@ -38,6 +39,11 @@ public void Populate(
3839

3940
Settings.Clear();
4041

42+
if (refComponentProviderViewModel is null)
43+
{
44+
return;
45+
}
46+
4147
Settings.SuppressOnChangedNotification = true;
4248

4349
foreach (var xmlSetting in configurationSettingsFileOption.XmlSettings)
@@ -48,6 +54,35 @@ public void Populate(
4854
Settings.SuppressOnChangedNotification = false;
4955
}
5056

57+
public void ResolveValueAndTemplateLocations()
58+
{
59+
if (refComponentProviderViewModel is null)
60+
{
61+
return;
62+
}
63+
64+
foreach (var xmlItem in Settings)
65+
{
66+
var attributeItem = xmlItem.Attributes.FirstOrDefault(x => x.Key == "value");
67+
if (attributeItem is null)
68+
{
69+
continue;
70+
}
71+
72+
var value = attributeItem.Value?.ToString()!;
73+
if (!value.ContainsTemplateKeyBrackets())
74+
{
75+
continue;
76+
}
77+
78+
var (resolvedValue, templateLocations) = refComponentProviderViewModel.ResolveValueAndTemplateLocations(value);
79+
if (templateLocations.Count > 0)
80+
{
81+
attributeItem.Value = resolvedValue;
82+
}
83+
}
84+
}
85+
5186
public override string ToString()
5287
=> $"{nameof(FileName)}: {FileName}, {nameof(Settings)}.Count: {Settings?.Count}";
5388
}

0 commit comments

Comments
 (0)