Skip to content

Commit f4d5c49

Browse files
Merge pull request #6 from atc-net/hotfix/edit-defaultApplicationSettings-not-saved
Hotfix/edit default application settings not saved
2 parents 3481260 + c439fab commit f4d5c49

File tree

7 files changed

+94
-21
lines changed

7 files changed

+94
-21
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.9.0")]
9-
[assembly: AssemblyInformationalVersion("1.0.9.0")]
10-
[assembly: AssemblyFileVersion("1.0.9.0")]
8+
[assembly: AssemblyVersion("1.0.10.0")]
9+
[assembly: AssemblyInformationalVersion("1.0.10.0")]
10+
[assembly: AssemblyFileVersion("1.0.10.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/GlobalUsings.cs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
global using System.Diagnostics.CodeAnalysis;
44
global using System.IO;
55
global using System.Reflection;
6+
global using System.Runtime.CompilerServices;
67
global using System.Security.Cryptography;
78
global using System.Text.Json;
89
global using System.Windows;
@@ -38,6 +39,7 @@
3839
global using Atc.Wpf.Messaging;
3940
global using Atc.Wpf.Mvvm;
4041
global using Atc.Wpf.Theming.Themes.Dialogs;
42+
4143
global using ClosedXML.Excel;
4244
global using ControlzEx.Theming;
4345

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

+35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// ReSharper disable SuggestBaseTypeForParameter
22
// ReSharper disable PrivateFieldCanBeConvertedToLocalVariable
3+
// ReSharper disable SwitchStatementHandlesSomeKnownEnumValuesWithDefault
34
namespace Atc.Installer.Wpf.App;
45

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

124125
Messenger.Default.Register<ToastNotificationMessage>(this, HandleToastNotificationMessage);
125126
Messenger.Default.Register<RefreshSelectedComponentProviderMessage>(this, HandleRefreshSelectedComponentProviderMessage);
127+
Messenger.Default.Register<UpdateDefaultApplicationSettingsMessage>(this, HandleUpdateDefaultApplicationSettingsMessage);
126128

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

@@ -229,6 +231,39 @@ private void HandleRefreshSelectedComponentProviderMessage(
229231
RefreshSelectedComponentProviderMessage obj)
230232
=> RaisePropertyChanged(nameof(SelectedComponentProvider));
231233

234+
private void HandleUpdateDefaultApplicationSettingsMessage(
235+
UpdateDefaultApplicationSettingsMessage obj)
236+
{
237+
switch (obj.TriggerActionType)
238+
{
239+
case TriggerActionType.Insert:
240+
if (DefaultApplicationSettings.FirstOrDefault(x => x.Key == obj.KeyValueTemplateItem.Key) is null)
241+
{
242+
DefaultApplicationSettings.Add(obj.KeyValueTemplateItem);
243+
}
244+
245+
break;
246+
case TriggerActionType.Update:
247+
var itemToUpdate = DefaultApplicationSettings.FirstOrDefault(x => x.Key == obj.KeyValueTemplateItem.Key);
248+
if (itemToUpdate is not null)
249+
{
250+
itemToUpdate.Value = obj.KeyValueTemplateItem.Value;
251+
}
252+
253+
break;
254+
case TriggerActionType.Delete:
255+
var itemToDelete = DefaultApplicationSettings.FirstOrDefault(x => x.Key == obj.KeyValueTemplateItem.Key);
256+
if (itemToDelete is not null)
257+
{
258+
DefaultApplicationSettings.Remove(itemToDelete);
259+
}
260+
261+
break;
262+
default:
263+
throw new SwitchExpressionException(obj.TriggerActionType);
264+
}
265+
}
266+
232267
private async Task CheckForUpdates()
233268
{
234269
if (!NetworkInformationHelper.HasConnection())

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

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ await ConfigurationFileHelper
206206
{
207207
var json = JsonSerializer.Serialize(installationOption, App.JsonSerializerOptions);
208208
var dynamicJsonCustomSettings = new DynamicJson(json);
209+
dynamicJsonCustomSettings.RemovePath("Applications");
209210

210211
await ConfigurationFileHelper.SaveInstallationSettings(
211212
customSettingsFile,

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

+34-13
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,18 @@ private void NewCommandHandler()
219219

220220
if (isDefaultApplicationSettings)
221221
{
222-
Items.Add(
223-
new KeyValueTemplateItemViewModel(
224-
dataKey,
225-
dataValue,
226-
template: null,
227-
templateLocations: null));
222+
var item = new KeyValueTemplateItemViewModel(
223+
dataKey,
224+
dataValue,
225+
template: null,
226+
templateLocations: null);
227+
228+
Items.Add(item);
229+
230+
Messenger.Default.Send(
231+
new UpdateDefaultApplicationSettingsMessage(
232+
TriggerActionType.Insert,
233+
item));
228234
}
229235
else
230236
{
@@ -347,6 +353,14 @@ private void DeleteCommandHandler(
347353

348354
Items.Remove(item);
349355

356+
if (isDefaultApplicationSettings)
357+
{
358+
Messenger.Default.Send(
359+
new UpdateDefaultApplicationSettingsMessage(
360+
TriggerActionType.Delete,
361+
item));
362+
}
363+
350364
IsDirty = true;
351365
}
352366

@@ -376,8 +390,7 @@ private List<ILabelControlBase> CreateLabelControls(
376390
var labelTextBoxValue = new LabelTextBox
377391
{
378392
LabelText = "Value",
379-
IsMandatory = true,
380-
MinLength = 1,
393+
IsMandatory = false,
381394
};
382395

383396
if (updateItem is not null)
@@ -464,15 +477,15 @@ private void HandleEditDialogResult(
464477

465478
if (isDefaultApplicationSettings)
466479
{
467-
if (string.IsNullOrEmpty(dataValue))
468-
{
469-
return;
470-
}
471-
472480
updateItem.Value = dataValue;
473481
updateItem.Template = null;
474482
updateItem.TemplateLocations = null;
475483

484+
Messenger.Default.Send(
485+
new UpdateDefaultApplicationSettingsMessage(
486+
TriggerActionType.Update,
487+
updateItem));
488+
476489
UpdateComponentProviders(updateItem);
477490
}
478491
else
@@ -536,6 +549,14 @@ componentProvider.InstallationFolderPath.TemplateLocations is not null &&
536549
componentProvider.InstallationFolderPath.Value = ResolveTemplateValue(updateItem, componentProvider, componentProvider.InstallationFolderPath.Template);
537550
}
538551

552+
foreach (var item in componentProvider.DefaultApplicationSettings.Items)
553+
{
554+
if (item.Key == updateItem.Key)
555+
{
556+
item.Value = updateItem.Value;
557+
}
558+
}
559+
539560
foreach (var item in componentProvider.ApplicationSettings.Items)
540561
{
541562
if (item.Template is not null &&

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

-5
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,6 @@ private void HandleEditDialogResult(
586586
if (string.IsNullOrEmpty(dataTemplate) ||
587587
dataTemplate.Equals(Constants.ItemBlankIdentifier, StringComparison.Ordinal))
588588
{
589-
if (string.IsNullOrEmpty(dataValue))
590-
{
591-
return;
592-
}
593-
594589
updateItem.Value = dataValue;
595590
updateItem.Template = null;
596591
updateItem.TemplateLocations = null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Atc.Installer.Wpf.ComponentProvider.Messages;
2+
3+
public class UpdateDefaultApplicationSettingsMessage : MessageBase
4+
{
5+
public UpdateDefaultApplicationSettingsMessage(
6+
TriggerActionType triggerActionType,
7+
KeyValueTemplateItemViewModel keyValueTemplateItem)
8+
{
9+
TriggerActionType = triggerActionType;
10+
KeyValueTemplateItem = keyValueTemplateItem;
11+
}
12+
13+
public TriggerActionType TriggerActionType { get; }
14+
15+
public KeyValueTemplateItemViewModel KeyValueTemplateItem { get; }
16+
17+
public override string ToString()
18+
=> $"{nameof(TriggerActionType)}: {TriggerActionType}, {nameof(KeyValueTemplateItem)}: {KeyValueTemplateItem}";
19+
}

0 commit comments

Comments
 (0)