Skip to content

Commit

Permalink
Merge pull request #3 from atc-net/bugfix/Resolve-TemplateLookupin-re…
Browse files Browse the repository at this point in the history
…fComponents

Bugfix - resolve template lookup in ref components
  • Loading branch information
davidkallesen authored Sep 14, 2023
2 parents e1daa99 + 482a6f2 commit a491377
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Atc.Installer.Wpf.App/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[assembly: AssemblyCompany("atc-net")]
[assembly: AssemblyProduct("Atc.Installer")]
[assembly: AssemblyTitle("Atc.Installer")]
[assembly: AssemblyVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6.0")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7.0")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: System.Resources.NeutralResourcesLanguage("en")]
[assembly: System.Runtime.Versioning.TargetPlatform("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows7.0")]
5 changes: 5 additions & 0 deletions src/Atc.Installer.Wpf.App/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ private void Populate(
}
}

foreach (var componentProvider in ComponentProviders)
{
componentProvider.ConfigurationSettingsFiles.ResolveValueAndTemplateReferences();
}

ComponentProviders.SuppressOnChangedNotification = false;

if (ComponentProviders.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ public void ClearAllIsDirty()
}
}

public void ResolveValueAndTemplateReferences()
{
JsonItems.SuppressOnChangedNotification = true;
XmlItems.SuppressOnChangedNotification = true;

foreach (var jsonItem in JsonItems)
{
jsonItem.ResolveValueAndTemplateLocations();
}

foreach (var xmlItem in XmlItems)
{
xmlItem.ResolveValueAndTemplateLocations();
}

JsonItems.SuppressOnChangedNotification = false;
XmlItems.SuppressOnChangedNotification = false;
}

public override string ToString()
=> $"{nameof(JsonItems)}.Count: {JsonItems?.Count}, {nameof(XmlItems)}.Count: {XmlItems?.Count}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Atc.Installer.Wpf.ComponentProvider.ViewModels;

public class ConfigurationSettingsJsonFileViewModel : ViewModelBase
{
private readonly ComponentProviderViewModel? refComponentProviderViewModel;
private string fileName = string.Empty;

public ConfigurationSettingsJsonFileViewModel()
Expand All @@ -13,7 +14,12 @@ public ConfigurationSettingsJsonFileViewModel(
ComponentProviderViewModel refComponentProviderViewModel,
ConfigurationSettingsFileOption configurationSettingsFileOption)
{
Populate(refComponentProviderViewModel, configurationSettingsFileOption);
ArgumentNullException.ThrowIfNull(refComponentProviderViewModel);
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);

this.refComponentProviderViewModel = refComponentProviderViewModel;

Populate(configurationSettingsFileOption);
}

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

public void Populate(
ComponentProviderViewModel refComponentProviderViewModel,
ConfigurationSettingsFileOption configurationSettingsFileOption)
{
ArgumentNullException.ThrowIfNull(refComponentProviderViewModel);
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);

FileName = configurationSettingsFileOption.FileName;
Expand All @@ -46,6 +50,11 @@ public void Populate(
var value = keyValuePair.Value.ToString()!;
if (value.ContainsTemplateKeyBrackets())
{
if (refComponentProviderViewModel is null)
{
continue;
}

var (resolvedValue, templateLocations) = refComponentProviderViewModel.ResolveValueAndTemplateLocations(value);

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

public void ResolveValueAndTemplateLocations()
{
if (refComponentProviderViewModel is null)
{
return;
}

foreach (var keyValuePair in Settings)
{
var value = keyValuePair.Value.ToString()!;
if (!value.ContainsTemplateKeyBrackets())
{
continue;
}

var (resolvedValue, templateLocations) = refComponentProviderViewModel.ResolveValueAndTemplateLocations(value);
if (templateLocations.Count > 0)
{
keyValuePair.Value = resolvedValue;
}
}
}

public override string ToString()
=> $"{nameof(FileName)}: {FileName}, {nameof(Settings)}.Count: {Settings?.Count}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ namespace Atc.Installer.Wpf.ComponentProvider.ViewModels;

public class ConfigurationSettingsXmlFileViewModel : ViewModelBase
{
private readonly ComponentProviderViewModel? refComponentProviderViewModel;
private string fileName = string.Empty;

public ConfigurationSettingsXmlFileViewModel()
{
}

public ConfigurationSettingsXmlFileViewModel(
ComponentProviderViewModel refComponentProviderViewModel,
ConfigurationSettingsFileOption configurationSettingsFileOption)
{
Populate(refComponentProviderViewModel, configurationSettingsFileOption);
ArgumentNullException.ThrowIfNull(refComponentProviderViewModel);
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);

this.refComponentProviderViewModel = refComponentProviderViewModel;

Populate(configurationSettingsFileOption);
}

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

public void Populate(
ComponentProviderViewModel refComponentProviderViewModel,
ConfigurationSettingsFileOption configurationSettingsFileOption)
{
ArgumentNullException.ThrowIfNull(configurationSettingsFileOption);
Expand All @@ -38,6 +39,11 @@ public void Populate(

Settings.Clear();

if (refComponentProviderViewModel is null)
{
return;
}

Settings.SuppressOnChangedNotification = true;

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

public void ResolveValueAndTemplateLocations()
{
if (refComponentProviderViewModel is null)
{
return;
}

foreach (var xmlItem in Settings)
{
var attributeItem = xmlItem.Attributes.FirstOrDefault(x => x.Key == "value");
if (attributeItem is null)
{
continue;
}

var value = attributeItem.Value?.ToString()!;
if (!value.ContainsTemplateKeyBrackets())
{
continue;
}

var (resolvedValue, templateLocations) = refComponentProviderViewModel.ResolveValueAndTemplateLocations(value);
if (templateLocations.Count > 0)
{
attributeItem.Value = resolvedValue;
}
}
}

public override string ToString()
=> $"{nameof(FileName)}: {FileName}, {nameof(Settings)}.Count: {Settings?.Count}";
}

0 comments on commit a491377

Please sign in to comment.