Skip to content

Commit 7771ede

Browse files
committed
2 parents aa520a8 + 8644b77 commit 7771ede

File tree

12 files changed

+249
-77
lines changed

12 files changed

+249
-77
lines changed

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,4 +3541,10 @@ Changes to this value will take effect after the application is restarted. Wheth
35413541
<data name="NewSubnetMask" xml:space="preserve">
35423542
<value>New subnet mask</value>
35433543
</data>
3544+
<data name="AddServer" xml:space="preserve">
3545+
<value>Add server</value>
3546+
</data>
3547+
<data name="SNTPServer" xml:space="preserve">
3548+
<value>SNTP server</value>
3549+
</data>
35443550
</root>

Source/NETworkManager.Models/Network/ServerConnectionInfoProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
23

34
namespace NETworkManager.Models.Network;
45

Source/NETworkManager/ViewModels/DNSLookupSettingsViewModel.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ public class DNSLookupSettingsViewModel : ViewModelBase
1717
{
1818
#region Variables
1919
private readonly bool _isLoading;
20+
private readonly ServerConnectionInfo _profileDialog_DefaultValues = new("10.0.0.1", 53, TransportProtocol.UDP);
2021

2122
private readonly IDialogCoordinator _dialogCoordinator;
2223

23-
private (string Server, int Port, TransportProtocol TransportProtocol) _profileDialog_NewItemsOptions = ("1.1.1.1", 53, TransportProtocol.UDP);
24-
2524
public ICollectionView DNSServers { get; }
2625

2726
private DNSServerConnectionInfoProfile _selectedDNSServer = new();
@@ -287,13 +286,13 @@ public async Task AddDNSServer()
287286
{
288287
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
289288

290-
SettingsManager.Current.DNSLookup_DNSServers_v2.Add(new DNSServerConnectionInfoProfile(instance.Name, instance.Servers));
289+
SettingsManager.Current.DNSLookup_DNSServers_v2.Add(new DNSServerConnectionInfoProfile(instance.Name, instance.Servers.ToList()));
291290
}, instance =>
292291
{
293292
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
294-
}, (ServerInfoProfileNames, false, true));
293+
}, (ServerInfoProfileNames, false, true), _profileDialog_DefaultValues);
295294

296-
customDialog.Content = new ServerConnectionInfoProfileDialog(_profileDialog_NewItemsOptions)
295+
customDialog.Content = new ServerConnectionInfoProfileDialog()
297296
{
298297
DataContext = viewModel
299298
};
@@ -313,13 +312,13 @@ public async Task EditDNSServer()
313312
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
314313

315314
SettingsManager.Current.DNSLookup_DNSServers_v2.Remove(SelectedDNSServer);
316-
SettingsManager.Current.DNSLookup_DNSServers_v2.Add(new DNSServerConnectionInfoProfile(instance.Name, instance.Servers));
315+
SettingsManager.Current.DNSLookup_DNSServers_v2.Add(new DNSServerConnectionInfoProfile(instance.Name, instance.Servers.ToList()));
317316
}, instance =>
318317
{
319318
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
320-
}, (ServerInfoProfileNames, true, true), SelectedDNSServer);
319+
}, (ServerInfoProfileNames, true, true), _profileDialog_DefaultValues, SelectedDNSServer);
321320

322-
customDialog.Content = new ServerConnectionInfoProfileDialog(_profileDialog_NewItemsOptions)
321+
customDialog.Content = new ServerConnectionInfoProfileDialog()
323322
{
324323
DataContext = viewModel
325324
};

Source/NETworkManager/ViewModels/SNTPLookupSettingsViewModel.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ public class SNTPLookupSettingsViewModel : ViewModelBase
1616
{
1717
#region Variables
1818
private readonly bool _isLoading;
19-
19+
private readonly ServerConnectionInfo _profileDialog_DefaultValues = new("time.example.com", 123, TransportProtocol.TCP);
20+
2021
private readonly IDialogCoordinator _dialogCoordinator;
2122

22-
private (string Server, int Port, TransportProtocol TransportProtocol) _profileDialog_NewItemsOptions = ("time.example.com", 123, TransportProtocol.TCP);
23-
2423
private ICollectionView _sntpServers;
2524
public ICollectionView SNTPServers
2625
{
@@ -130,13 +129,13 @@ public async Task AddServer()
130129
{
131130
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
132131

133-
SettingsManager.Current.SNTPLookup_SNTPServers.Add(new ServerConnectionInfoProfile(instance.Name, instance.Servers));
132+
SettingsManager.Current.SNTPLookup_SNTPServers.Add(new ServerConnectionInfoProfile(instance.Name, instance.Servers.ToList()));
134133
}, instance =>
135134
{
136135
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
137-
}, (ServerInfoProfileNames, false, false));
136+
}, (ServerInfoProfileNames, false, false), _profileDialog_DefaultValues);
138137

139-
customDialog.Content = new ServerConnectionInfoProfileDialog(_profileDialog_NewItemsOptions)
138+
customDialog.Content = new ServerConnectionInfoProfileDialog()
140139
{
141140
DataContext = viewModel
142141
};
@@ -156,13 +155,13 @@ public async Task EditServer()
156155
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
157156

158157
SettingsManager.Current.SNTPLookup_SNTPServers.Remove(SelectedSNTPServer);
159-
SettingsManager.Current.SNTPLookup_SNTPServers.Add(new ServerConnectionInfoProfile(instance.Name, instance.Servers));
158+
SettingsManager.Current.SNTPLookup_SNTPServers.Add(new ServerConnectionInfoProfile(instance.Name, instance.Servers.ToList()));
160159
}, instance =>
161160
{
162161
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
163-
}, (ServerInfoProfileNames, true, false), SelectedSNTPServer);
162+
}, (ServerInfoProfileNames, true, false), _profileDialog_DefaultValues, SelectedSNTPServer);
164163

165-
customDialog.Content = new ServerConnectionInfoProfileDialog(_profileDialog_NewItemsOptions)
164+
customDialog.Content = new ServerConnectionInfoProfileDialog()
166165
{
167166
DataContext = viewModel
168167
};

Source/NETworkManager/ViewModels/ServerConnectionInfoProfileViewModel.cs

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
using System.Windows.Input;
44
using NETworkManager.Models.Network;
55
using System.Collections.Generic;
6-
using System.Windows.Controls;
7-
using System.Windows;
6+
using System.Collections.ObjectModel;
7+
using System.Collections;
88
using System.Linq;
9-
using System.Diagnostics;
109

1110
namespace NETworkManager.ViewModels;
1211

1312
public class ServerConnectionInfoProfileViewModel : ViewModelBase
1413
{
1514
private readonly bool _isLoading;
1615

16+
private ServerConnectionInfo _defaultValues;
17+
1718
#region Commands
1819
public ICommand SaveCommand { get; }
1920

@@ -90,13 +91,12 @@ public string Name
9091
return;
9192

9293
_name = value;
93-
9494
OnPropertyChanged();
9595
}
9696
}
9797

98-
private List<ServerConnectionInfo> _servers;
99-
public List<ServerConnectionInfo> Servers
98+
private ObservableCollection<ServerConnectionInfo> _servers;
99+
public ObservableCollection<ServerConnectionInfo> Servers
100100
{
101101
get => _servers;
102102
set
@@ -108,9 +108,55 @@ public List<ServerConnectionInfo> Servers
108108
OnPropertyChanged();
109109
}
110110
}
111+
112+
private IList _selectedServers = new ArrayList();
113+
public IList SelectedServers
114+
{
115+
get => _selectedServers;
116+
set
117+
{
118+
if (Equals(value, _selectedServers))
119+
return;
120+
121+
_selectedServers = value;
122+
OnPropertyChanged();
123+
}
124+
}
125+
126+
public string ServerWatermark { get; private set; }
127+
128+
private string _server;
129+
public string Server
130+
{
131+
get => _server;
132+
set
133+
{
134+
if (_server == value)
135+
return;
136+
137+
_server = value;
138+
OnPropertyChanged();
139+
}
140+
}
141+
142+
public string PortWatermark { get; private set; }
143+
144+
private int _port;
145+
public int Port
146+
{
147+
get => _port;
148+
set
149+
{
150+
if (_port == value)
151+
return;
152+
153+
_port = value;
154+
OnPropertyChanged();
155+
}
156+
}
111157
#endregion
112158

113-
public ServerConnectionInfoProfileViewModel(Action<ServerConnectionInfoProfileViewModel> saveCommand, Action<ServerConnectionInfoProfileViewModel> cancelHandler, (List<string> UsedNames, bool IsEdited, bool allowOnlyIPAddress) options, ServerConnectionInfoProfile info = null)
159+
public ServerConnectionInfoProfileViewModel(Action<ServerConnectionInfoProfileViewModel> saveCommand, Action<ServerConnectionInfoProfileViewModel> cancelHandler, (List<string> UsedNames, bool IsEdited, bool allowOnlyIPAddress) options, ServerConnectionInfo defaultValues, ServerConnectionInfoProfile info = null)
114160
{
115161
_isLoading = true;
116162

@@ -120,15 +166,42 @@ public ServerConnectionInfoProfileViewModel(Action<ServerConnectionInfoProfileVi
120166
UsedNames = options.UsedNames;
121167
AllowOnlyIPAddress = options.allowOnlyIPAddress;
122168
IsEdited = options.IsEdited;
169+
170+
_defaultValues = defaultValues;
171+
123172
CurrentProfile = info ?? new ServerConnectionInfoProfile();
124173

125174
// Remove the current profile name from the list
126175
if (IsEdited)
127176
UsedNames.Remove(CurrentProfile.Name);
128177

129178
Name = _currentProfile.Name;
130-
Servers = _currentProfile.Servers;
179+
Servers = new ObservableCollection<ServerConnectionInfo>(_currentProfile.Servers);
180+
181+
ServerWatermark = _defaultValues.Server;
182+
PortWatermark = _defaultValues.Port.ToString();
183+
Port = _defaultValues.Port;
131184

132185
_isLoading = false;
133186
}
187+
188+
public ICommand AddServerCommand => new RelayCommand(p => AddServerAction());
189+
190+
private void AddServerAction()
191+
{
192+
Servers.Add(new ServerConnectionInfo(Server, Port, _defaultValues.TransportProtocol));
193+
194+
Server = string.Empty;
195+
}
196+
197+
public ICommand DeleteServerCommand => new RelayCommand(p => DeleteServerAction());
198+
199+
private void DeleteServerAction()
200+
{
201+
// Cast to list to avoid exception: Collection was modified; enumeration operation may not execute.
202+
// This will create a copy of the list and allow us to remove items from the original list (SelectedServers
203+
// is modified when Servers changes).
204+
foreach (var item in SelectedServers.Cast<ServerConnectionInfo>().ToList())
205+
Servers.Remove(item);
206+
}
134207
}

Source/NETworkManager/Views/SNTPLookupSettingsView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</UserControl.Resources>
1818
<StackPanel>
1919
<TextBlock Text="{x:Static localization:Strings.SNTPLookup}" Style="{StaticResource HeaderTextBlock}" />
20-
<TextBlock Text="{x:Static localization:Strings.SNTPServers}" Style="{DynamicResource DefaultTextBlock}" Margin="0,0,0,10" />
20+
<TextBlock Text="{x:Static localization:Strings.SNTPServer}" Style="{DynamicResource DefaultTextBlock}" Margin="0,0,0,10" />
2121
<DataGrid x:Name="DataGridSNTPServers" ItemsSource="{Binding SNTPServers}" SelectionMode="Single" SelectedItem="{Binding SelectedSNTPServer}" Height="200" Margin="0,0,0,10">
2222
<DataGrid.Resources>
2323
<Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource DataGridScrollBar}" />

0 commit comments

Comments
 (0)