Skip to content

Commit 708159c

Browse files
committed
ping history now saved correctly, code quality improved
1 parent 8b2e268 commit 708159c

32 files changed

Lines changed: 494 additions & 494 deletions

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
408408
TracerouteView tracerouteView;
409409
DNSLookupView dnsLookupView;
410410
RemoteDesktopView remoteDesktopView;
411-
SNMPView snmpView;
411+
SNMPHostView snmpHostView;
412412
WakeOnLANView wakeOnLANView;
413413
SubnetCalculatorHostView subnetCalculatorHostView;
414414
HTTPHeadersView httpHeadersView;
@@ -467,10 +467,10 @@ private void ChangeApplicationView(ApplicationViewManager.Name name)
467467
contentControlApplication.Content = remoteDesktopView;
468468
break;
469469
case ApplicationViewManager.Name.SNMP:
470-
if (snmpView == null)
471-
snmpView = new SNMPView();
470+
if (snmpHostView == null)
471+
snmpHostView = new SNMPHostView();
472472

473-
contentControlApplication.Content = snmpView;
473+
contentControlApplication.Content = snmpHostView;
474474
break;
475475
case ApplicationViewManager.Name.WakeOnLAN:
476476
if (wakeOnLANView == null)

Source/NETworkManager/Models/Settings/SettingsInfo.cs

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Lextm.SharpSnmpLib.Messaging;
33
using NETworkManager.Views;
44
using System.Collections.Generic;
5+
using System.Collections.ObjectModel;
56
using System.ComponentModel;
67
using System.Runtime.CompilerServices;
78
using System.Xml.Serialization;
@@ -333,8 +334,8 @@ public int IPScanner_Threads
333334
}
334335
}
335336

336-
private List<string> _ipScanner_IPRangeHistory = new List<string>();
337-
public List<string> IPScanner_IPRangeHistory
337+
private ObservableCollection<string> _ipScanner_IPRangeHistory = new ObservableCollection<string>();
338+
public ObservableCollection<string> IPScanner_IPRangeHistory
338339
{
339340
get { return _ipScanner_IPRangeHistory; }
340341
set
@@ -497,8 +498,8 @@ public bool Ping_DontFragment
497498
}
498499
}
499500

500-
private List<string> _ping_HostHistory = new List<string>();
501-
public List<string> Ping_HostHistory
501+
private ObservableCollection<string> _ping_HostHistory = new ObservableCollection<string>();
502+
public ObservableCollection<string> Ping_HostHistory
502503
{
503504
get { return _ping_HostHistory; }
504505
set
@@ -597,16 +598,16 @@ public bool Ping_ExpandStatistics
597598
#endregion
598599

599600
#region Traceroute
600-
private List<string> _traceroute_HostnameHistory = new List<string>();
601-
public List<string> Traceroute_HostnameHistory
601+
private ObservableCollection<string> _traceroute_HostHistory;
602+
public ObservableCollection<string> Traceroute_HostHistory
602603
{
603-
get { return _traceroute_HostnameHistory; }
604+
get { return _traceroute_HostHistory; }
604605
set
605606
{
606-
if (value == _traceroute_HostnameHistory)
607+
if (value == _traceroute_HostHistory)
607608
return;
608609

609-
_traceroute_HostnameHistory = value;
610+
_traceroute_HostHistory = value;
610611
SettingsChanged = true;
611612
}
612613
}
@@ -700,8 +701,8 @@ public bool Traceroute_ExpandStatistics
700701
#endregion
701702

702703
#region Lookup
703-
private List<string> _lookup_OUI_MACAddressOrVendorHistory = new List<string>();
704-
public List<string> Lookup_OUI_MACAddressOrVendorHistory
704+
private ObservableCollection<string> _lookup_OUI_MACAddressOrVendorHistory = new ObservableCollection<string>();
705+
public ObservableCollection<string> Lookup_OUI_MACAddressOrVendorHistory
705706
{
706707
get { return _lookup_OUI_MACAddressOrVendorHistory; }
707708
set
@@ -714,8 +715,8 @@ public List<string> Lookup_OUI_MACAddressOrVendorHistory
714715
}
715716
}
716717

717-
private List<string> _lookup_Port_PortsHistory = new List<string>();
718-
public List<string> Lookup_Port_PortsHistory
718+
private ObservableCollection<string> _lookup_Port_PortsHistory = new ObservableCollection<string>();
719+
public ObservableCollection<string> Lookup_Port_PortsHistory
719720
{
720721
get { return _lookup_Port_PortsHistory; }
721722
set
@@ -730,30 +731,30 @@ public List<string> Lookup_Port_PortsHistory
730731
#endregion
731732

732733
#region PortScanner
733-
private List<string> _portScanner_HostnameHistory = new List<string>();
734-
public List<string> PortScanner_HostnameHistory
734+
private ObservableCollection<string> _portScanner_HostHistory = new ObservableCollection<string>();
735+
public ObservableCollection<string> PortScanner_HostHistory
735736
{
736-
get { return _portScanner_HostnameHistory; }
737+
get { return _portScanner_HostHistory; }
737738
set
738739
{
739-
if (value == _portScanner_HostnameHistory)
740+
if (value == _portScanner_HostHistory)
740741
return;
741742

742-
_portScanner_HostnameHistory = value;
743+
_portScanner_HostHistory = value;
743744
SettingsChanged = true;
744745
}
745746
}
746747

747-
private List<string> _portScanner_PortsHistory = new List<string>();
748-
public List<string> PortScanner_PortsHistory
748+
private ObservableCollection<string> _portScanner_PortHistory = new ObservableCollection<string>();
749+
public ObservableCollection<string> PortScanner_PortHistory
749750
{
750-
get { return _portScanner_PortsHistory; }
751+
get { return _portScanner_PortHistory; }
751752
set
752753
{
753-
if (value == _portScanner_PortsHistory)
754+
if (value == _portScanner_PortHistory)
754755
return;
755756

756-
_portScanner_PortsHistory = value;
757+
_portScanner_PortHistory = value;
757758
SettingsChanged = true;
758759
}
759760
}
@@ -874,8 +875,8 @@ public bool WakeOnLAN_ExpandClientView
874875
#endregion
875876

876877
#region DNS Lookup
877-
private List<string> _dnsLookup_HostHistory = new List<string>();
878-
public List<string> DNSLookup_HostHistory
878+
private ObservableCollection<string> _dnsLookup_HostHistory = new ObservableCollection<string>();
879+
public ObservableCollection<string> DNSLookup_HostHistory
879880
{
880881
get { return _dnsLookup_HostHistory; }
881882
set
@@ -1087,8 +1088,8 @@ public bool DNSLookup_ExpandStatistics
10871088

10881089
#region Subnet Calculator
10891090
#region IPv4 Calculator
1090-
private List<string> _subnetCalculator_IPv4Calculator_SubnetHistory = new List<string>();
1091-
public List<string> SubnetCalculator_IPv4Calculator_SubnetHistory
1091+
private ObservableCollection<string> _subnetCalculator_IPv4Calculator_SubnetHistory = new ObservableCollection<string>();
1092+
public ObservableCollection<string> SubnetCalculator_IPv4Calculator_SubnetHistory
10921093
{
10931094
get { return _subnetCalculator_IPv4Calculator_SubnetHistory; }
10941095
set
@@ -1388,8 +1389,8 @@ public bool RemoteDesktop_ExpandSessionView
13881389
#endregion
13891390

13901391
#region HTTP Headers
1391-
private List<string> _httpHeaders_WebsiteUriHistory = new List<string>();
1392-
public List<string> HTTPHeaders_WebsiteUriHistory
1392+
private ObservableCollection<string> _httpHeaders_WebsiteUriHistory = new ObservableCollection<string>();
1393+
public ObservableCollection<string> HTTPHeaders_WebsiteUriHistory
13931394
{
13941395
get { return _httpHeaders_WebsiteUriHistory; }
13951396
set
@@ -1489,22 +1490,22 @@ public bool SNMP_ResolveHostnamePreferIPv4
14891490
}
14901491
}
14911492

1492-
private List<string> _snmp_v1v2c_HostnameHistory = new List<string>();
1493-
public List<string> SNMP_v1v2c_HostnameHistory
1493+
private ObservableCollection<string> _snmp_v1v2c_HostHistory = new ObservableCollection<string>();
1494+
public ObservableCollection<string> SNMP_v1v2c_HostHistory
14941495
{
1495-
get { return _snmp_v1v2c_HostnameHistory; }
1496+
get { return _snmp_v1v2c_HostHistory; }
14961497
set
14971498
{
1498-
if (value == _snmp_v1v2c_HostnameHistory)
1499+
if (value == _snmp_v1v2c_HostHistory)
14991500
return;
15001501

1501-
_snmp_v1v2c_HostnameHistory = value;
1502+
_snmp_v1v2c_HostHistory = value;
15021503
SettingsChanged = true;
15031504
}
15041505
}
15051506

1506-
private List<string> _snmp_v1v2c_OIDHistory = new List<string>();
1507-
public List<string> SNMP_v1v2c_OIDHistory
1507+
private ObservableCollection<string> _snmp_v1v2c_OIDHistory = new ObservableCollection<string>();
1508+
public ObservableCollection<string> SNMP_v1v2c_OIDHistory
15081509
{
15091510
get { return _snmp_v1v2c_OIDHistory; }
15101511
set
@@ -1559,22 +1560,22 @@ public bool SNMP_v1v2c_ExpandStatistics
15591560
}
15601561
}
15611562

1562-
private List<string> _snmp_v3_HostnameHistory = new List<string>();
1563-
public List<string> SNMP_v3_HostnameHistory
1563+
private ObservableCollection<string> _snmp_v3_HostHistory = new ObservableCollection<string>();
1564+
public ObservableCollection<string> SNMP_v3_HostHistory
15641565
{
1565-
get { return _snmp_v3_HostnameHistory; }
1566+
get { return _snmp_v3_HostHistory; }
15661567
set
15671568
{
1568-
if (value == _snmp_v3_HostnameHistory)
1569+
if (value == _snmp_v3_HostHistory)
15691570
return;
15701571

1571-
_snmp_v3_HostnameHistory = value;
1572+
_snmp_v3_HostHistory = value;
15721573
SettingsChanged = true;
15731574
}
15741575
}
15751576

1576-
private List<string> _snmp_v3_OIDHistory = new List<string>();
1577-
public List<string> SNMP_v3_OIDHistory
1577+
private ObservableCollection<string> _snmp_v3_OIDHistory = new ObservableCollection<string>();
1578+
public ObservableCollection<string> SNMP_v3_OIDHistory
15781579
{
15791580
get { return _snmp_v3_OIDHistory; }
15801581
set

Source/NETworkManager/NETworkManager.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@
272272
<Compile Include="Views\Applications\SNMPv1v2cView.xaml.cs">
273273
<DependentUpon>SNMPv1v2cView.xaml</DependentUpon>
274274
</Compile>
275-
<Compile Include="Views\Applications\SNMPView.xaml.cs">
276-
<DependentUpon>SNMPView.xaml</DependentUpon>
275+
<Compile Include="Views\Applications\SNMPHostView.xaml.cs">
276+
<DependentUpon>SNMPHostView.xaml</DependentUpon>
277277
</Compile>
278278
<Compile Include="Views\Applications\HTTPHeadersView.xaml.cs">
279279
<DependentUpon>HTTPHeadersView.xaml</DependentUpon>
@@ -457,7 +457,7 @@
457457
<Generator>MSBuild:Compile</Generator>
458458
<SubType>Designer</SubType>
459459
</Page>
460-
<Page Include="Views\Applications\SNMPView.xaml">
460+
<Page Include="Views\Applications\SNMPHostView.xaml">
461461
<Generator>MSBuild:Compile</Generator>
462462
<SubType>Designer</SubType>
463463
</Page>

Source/NETworkManager/ViewModels/Applications/ARPTableViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public ARPTableViewModel(IDialogCoordinator instance)
117117
dialogCoordinator = instance;
118118

119119
_arpTableView = CollectionViewSource.GetDefaultView(ARPTable);
120-
_arpTableView.SortDescriptions.Add(new SortDescription("IPAddressInt32", ListSortDirection.Ascending));
120+
_arpTableView.SortDescriptions.Add(new SortDescription(nameof(ARPTableInfo.IPAddressInt32), ListSortDirection.Ascending));
121121
_arpTableView.Filter = o =>
122122
{
123123
if (string.IsNullOrEmpty(Search))

Source/NETworkManager/ViewModels/Applications/DNSLookupViewModel.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,10 @@ public string Host
3838
}
3939
}
4040

41-
private List<string> _hostHistory = new List<string>();
42-
public List<string> HostHistory
41+
private ICollectionView _hostHistoryView;
42+
public ICollectionView HostHistoryView
4343
{
44-
get { return _hostHistory; }
45-
set
46-
{
47-
if (value == _hostHistory)
48-
return;
49-
50-
if (!_isLoading)
51-
SettingsManager.Current.DNSLookup_HostHistory = value;
52-
53-
_hostHistory = value;
54-
OnPropertyChanged();
55-
}
44+
get { return _hostHistoryView; }
5645
}
5746

5847
public List<QType> Types { get; set; }
@@ -115,7 +104,7 @@ public DNSLookupRecordInfo SelectedLookupResult
115104
{
116105
if (value == _selectedLookupResult)
117106
return;
118-
107+
119108
_selectedLookupResult = value;
120109
OnPropertyChanged();
121110
}
@@ -296,6 +285,7 @@ public bool ExpandStatistics
296285
#region Contructor, load settings
297286
public DNSLookupViewModel()
298287
{
288+
_hostHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.DNSLookup_HostHistory);
299289
_lookupResultView = CollectionViewSource.GetDefaultView(LookupResult);
300290

301291
LoadSettings();
@@ -305,9 +295,6 @@ public DNSLookupViewModel()
305295

306296
private void LoadSettings()
307297
{
308-
if (SettingsManager.Current.DNSLookup_HostHistory != null)
309-
HostHistory = new List<string>(SettingsManager.Current.DNSLookup_HostHistory);
310-
311298
Types = Enum.GetValues(typeof(QType)).Cast<QType>().OrderBy(x => x.ToString()).ToList();
312299
Type = Types.First(x => x == SettingsManager.Current.DNSLookup_Type);
313300

@@ -403,7 +390,7 @@ private void StartLookup()
403390
// Reset the latest results
404391
LookupResult.Clear();
405392

406-
HostHistory = new List<string>(HistoryListHelper.Modify(HostHistory, Host, SettingsManager.Current.General_HistoryListEntries));
393+
AddHostToHistory(Host);
407394

408395
DNSLookupOptions DNSLookupOptions = new DNSLookupOptions();
409396

@@ -471,6 +458,20 @@ private void LookupFinished()
471458

472459
IsLookupRunning = false;
473460
}
461+
462+
// Modify history list
463+
private void AddHostToHistory(string host)
464+
{
465+
// Create the new list
466+
List<string> list = HistoryListHelper.Modify(SettingsManager.Current.DNSLookup_HostHistory.ToList(), host, SettingsManager.Current.General_HistoryListEntries);
467+
468+
// Clear the old items
469+
SettingsManager.Current.DNSLookup_HostHistory.Clear();
470+
OnPropertyChanged(nameof(Host)); // Raise property changed again, after the collection has been cleared
471+
472+
// Fill with the new items
473+
list.ForEach(x => SettingsManager.Current.DNSLookup_HostHistory.Add(x));
474+
}
474475
#endregion
475476

476477
#region Events

0 commit comments

Comments
 (0)