diff --git a/src/Atc.Installer.Wpf.App/AssemblyInfo.cs b/src/Atc.Installer.Wpf.App/AssemblyInfo.cs index 39dba76..2b19052 100644 --- a/src/Atc.Installer.Wpf.App/AssemblyInfo.cs +++ b/src/Atc.Installer.Wpf.App/AssemblyInfo.cs @@ -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")] \ No newline at end of file diff --git a/src/Atc.Installer.Wpf.App/GlobalUsings.cs b/src/Atc.Installer.Wpf.App/GlobalUsings.cs index 7ddd0bc..1d59958 100644 --- a/src/Atc.Installer.Wpf.App/GlobalUsings.cs +++ b/src/Atc.Installer.Wpf.App/GlobalUsings.cs @@ -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; @@ -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; diff --git a/src/Atc.Installer.Wpf.App/MainWindowViewModel.cs b/src/Atc.Installer.Wpf.App/MainWindowViewModel.cs index fbad545..ee80cc8 100644 --- a/src/Atc.Installer.Wpf.App/MainWindowViewModel.cs +++ b/src/Atc.Installer.Wpf.App/MainWindowViewModel.cs @@ -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.")] @@ -123,6 +124,7 @@ public MainWindowViewModel( Messenger.Default.Register(this, HandleToastNotificationMessage); Messenger.Default.Register(this, HandleRefreshSelectedComponentProviderMessage); + Messenger.Default.Register(this, HandleUpdateDefaultApplicationSettingsMessage); loggerComponentProvider.Log(LogLevel.Trace, $"{AssemblyHelper.GetSystemName()} is started"); @@ -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()) diff --git a/src/Atc.Installer.Wpf.App/MainWindowViewModel_LogicBase.cs b/src/Atc.Installer.Wpf.App/MainWindowViewModel_LogicBase.cs index 5a08266..921bbd0 100644 --- a/src/Atc.Installer.Wpf.App/MainWindowViewModel_LogicBase.cs +++ b/src/Atc.Installer.Wpf.App/MainWindowViewModel_LogicBase.cs @@ -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, diff --git a/src/Atc.Installer.Wpf.ComponentProvider/Controls/ApplicationSettingsViewModel.cs b/src/Atc.Installer.Wpf.ComponentProvider/Controls/ApplicationSettingsViewModel.cs index 0b881e5..26d5394 100644 --- a/src/Atc.Installer.Wpf.ComponentProvider/Controls/ApplicationSettingsViewModel.cs +++ b/src/Atc.Installer.Wpf.ComponentProvider/Controls/ApplicationSettingsViewModel.cs @@ -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 { @@ -347,6 +353,14 @@ private void DeleteCommandHandler( Items.Remove(item); + if (isDefaultApplicationSettings) + { + Messenger.Default.Send( + new UpdateDefaultApplicationSettingsMessage( + TriggerActionType.Delete, + item)); + } + IsDirty = true; } @@ -376,8 +390,7 @@ private List CreateLabelControls( var labelTextBoxValue = new LabelTextBox { LabelText = "Value", - IsMandatory = true, - MinLength = 1, + IsMandatory = false, }; if (updateItem is not null) @@ -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 @@ -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 && diff --git a/src/Atc.Installer.Wpf.ComponentProvider/Controls/ConfigurationSettingsFilesViewModel.cs b/src/Atc.Installer.Wpf.ComponentProvider/Controls/ConfigurationSettingsFilesViewModel.cs index 4aed654..a4a5b09 100644 --- a/src/Atc.Installer.Wpf.ComponentProvider/Controls/ConfigurationSettingsFilesViewModel.cs +++ b/src/Atc.Installer.Wpf.ComponentProvider/Controls/ConfigurationSettingsFilesViewModel.cs @@ -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; diff --git a/src/Atc.Installer.Wpf.ComponentProvider/Messages/UpdateDefaultApplicationSettingsMessage.cs b/src/Atc.Installer.Wpf.ComponentProvider/Messages/UpdateDefaultApplicationSettingsMessage.cs new file mode 100644 index 0000000..a94179e --- /dev/null +++ b/src/Atc.Installer.Wpf.ComponentProvider/Messages/UpdateDefaultApplicationSettingsMessage.cs @@ -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}"; +}