Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/edit default application settings not saved #6

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9.0")]
[assembly: AssemblyInformationalVersion("1.0.9.0")]
[assembly: AssemblyFileVersion("1.0.9.0")]
[assembly: AssemblyVersion("1.0.10.0")]
[assembly: AssemblyInformationalVersion("1.0.10.0")]
[assembly: AssemblyFileVersion("1.0.10.0")]
[assembly: System.Resources.NeutralResourcesLanguage("en")]
[assembly: System.Runtime.Versioning.TargetPlatform("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows7.0")]
2 changes: 2 additions & 0 deletions src/Atc.Installer.Wpf.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
global using System.Diagnostics.CodeAnalysis;
global using System.IO;
global using System.Reflection;
global using System.Runtime.CompilerServices;
global using System.Security.Cryptography;
global using System.Text.Json;
global using System.Windows;
Expand Down Expand Up @@ -38,6 +39,7 @@
global using Atc.Wpf.Messaging;
global using Atc.Wpf.Mvvm;
global using Atc.Wpf.Theming.Themes.Dialogs;

global using ClosedXML.Excel;
global using ControlzEx.Theming;

Expand Down
35 changes: 35 additions & 0 deletions src/Atc.Installer.Wpf.App/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ReSharper disable SuggestBaseTypeForParameter
// ReSharper disable PrivateFieldCanBeConvertedToLocalVariable
// ReSharper disable SwitchStatementHandlesSomeKnownEnumValuesWithDefault
namespace Atc.Installer.Wpf.App;

[SuppressMessage("Design", "MA0051:Method is too long", Justification = "OK.")]
Expand Down Expand Up @@ -123,6 +124,7 @@ public MainWindowViewModel(

Messenger.Default.Register<ToastNotificationMessage>(this, HandleToastNotificationMessage);
Messenger.Default.Register<RefreshSelectedComponentProviderMessage>(this, HandleRefreshSelectedComponentProviderMessage);
Messenger.Default.Register<UpdateDefaultApplicationSettingsMessage>(this, HandleUpdateDefaultApplicationSettingsMessage);

loggerComponentProvider.Log(LogLevel.Trace, $"{AssemblyHelper.GetSystemName()} is started");

Expand Down Expand Up @@ -229,6 +231,39 @@ private void HandleRefreshSelectedComponentProviderMessage(
RefreshSelectedComponentProviderMessage obj)
=> RaisePropertyChanged(nameof(SelectedComponentProvider));

private void HandleUpdateDefaultApplicationSettingsMessage(
UpdateDefaultApplicationSettingsMessage obj)
{
switch (obj.TriggerActionType)
{
case TriggerActionType.Insert:
if (DefaultApplicationSettings.FirstOrDefault(x => x.Key == obj.KeyValueTemplateItem.Key) is null)
{
DefaultApplicationSettings.Add(obj.KeyValueTemplateItem);
}

break;
case TriggerActionType.Update:
var itemToUpdate = DefaultApplicationSettings.FirstOrDefault(x => x.Key == obj.KeyValueTemplateItem.Key);
if (itemToUpdate is not null)
{
itemToUpdate.Value = obj.KeyValueTemplateItem.Value;
}

break;
case TriggerActionType.Delete:
var itemToDelete = DefaultApplicationSettings.FirstOrDefault(x => x.Key == obj.KeyValueTemplateItem.Key);
if (itemToDelete is not null)
{
DefaultApplicationSettings.Remove(itemToDelete);
}

break;
default:
throw new SwitchExpressionException(obj.TriggerActionType);
}
}

private async Task CheckForUpdates()
{
if (!NetworkInformationHelper.HasConnection())
Expand Down
1 change: 1 addition & 0 deletions src/Atc.Installer.Wpf.App/MainWindowViewModel_LogicBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ await ConfigurationFileHelper
{
var json = JsonSerializer.Serialize(installationOption, App.JsonSerializerOptions);
var dynamicJsonCustomSettings = new DynamicJson(json);
dynamicJsonCustomSettings.RemovePath("Applications");

await ConfigurationFileHelper.SaveInstallationSettings(
customSettingsFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,18 @@ private void NewCommandHandler()

if (isDefaultApplicationSettings)
{
Items.Add(
new KeyValueTemplateItemViewModel(
dataKey,
dataValue,
template: null,
templateLocations: null));
var item = new KeyValueTemplateItemViewModel(
dataKey,
dataValue,
template: null,
templateLocations: null);

Items.Add(item);

Messenger.Default.Send(
new UpdateDefaultApplicationSettingsMessage(
TriggerActionType.Insert,
item));
}
else
{
Expand Down Expand Up @@ -347,6 +353,14 @@ private void DeleteCommandHandler(

Items.Remove(item);

if (isDefaultApplicationSettings)
{
Messenger.Default.Send(
new UpdateDefaultApplicationSettingsMessage(
TriggerActionType.Delete,
item));
}

IsDirty = true;
}

Expand Down Expand Up @@ -376,8 +390,7 @@ private List<ILabelControlBase> CreateLabelControls(
var labelTextBoxValue = new LabelTextBox
{
LabelText = "Value",
IsMandatory = true,
MinLength = 1,
IsMandatory = false,
};

if (updateItem is not null)
Expand Down Expand Up @@ -464,15 +477,15 @@ private void HandleEditDialogResult(

if (isDefaultApplicationSettings)
{
if (string.IsNullOrEmpty(dataValue))
{
return;
}

updateItem.Value = dataValue;
updateItem.Template = null;
updateItem.TemplateLocations = null;

Messenger.Default.Send(
new UpdateDefaultApplicationSettingsMessage(
TriggerActionType.Update,
updateItem));

UpdateComponentProviders(updateItem);
}
else
Expand Down Expand Up @@ -536,6 +549,14 @@ componentProvider.InstallationFolderPath.TemplateLocations is not null &&
componentProvider.InstallationFolderPath.Value = ResolveTemplateValue(updateItem, componentProvider, componentProvider.InstallationFolderPath.Template);
}

foreach (var item in componentProvider.DefaultApplicationSettings.Items)
{
if (item.Key == updateItem.Key)
{
item.Value = updateItem.Value;
}
}

foreach (var item in componentProvider.ApplicationSettings.Items)
{
if (item.Template is not null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,6 @@ private void HandleEditDialogResult(
if (string.IsNullOrEmpty(dataTemplate) ||
dataTemplate.Equals(Constants.ItemBlankIdentifier, StringComparison.Ordinal))
{
if (string.IsNullOrEmpty(dataValue))
{
return;
}

updateItem.Value = dataValue;
updateItem.Template = null;
updateItem.TemplateLocations = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Atc.Installer.Wpf.ComponentProvider.Messages;

public class UpdateDefaultApplicationSettingsMessage : MessageBase
{
public UpdateDefaultApplicationSettingsMessage(
TriggerActionType triggerActionType,
KeyValueTemplateItemViewModel keyValueTemplateItem)
{
TriggerActionType = triggerActionType;
KeyValueTemplateItem = keyValueTemplateItem;
}

public TriggerActionType TriggerActionType { get; }

public KeyValueTemplateItemViewModel KeyValueTemplateItem { get; }

public override string ToString()
=> $"{nameof(TriggerActionType)}: {TriggerActionType}, {nameof(KeyValueTemplateItem)}: {KeyValueTemplateItem}";
}
Loading