Skip to content

Commit bdf1e43

Browse files
committed
Closes #30
1 parent c60dbb7 commit bdf1e43

7 files changed

Lines changed: 325 additions & 144 deletions

File tree

Source/NETworkManager/Models/Settings/SettingsInfo.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,20 @@ public int IPScanner_Timeout
358358
SettingsChanged = true;
359359
}
360360
}
361+
362+
private bool _ipScanner_ExpandStatistics = true;
363+
public bool IPScanner_ExpandStatistics
364+
{
365+
get { return _ipScanner_ExpandStatistics; }
366+
set
367+
{
368+
if (value == _ipScanner_ExpandStatistics)
369+
return;
370+
371+
_ipScanner_ExpandStatistics = value;
372+
SettingsChanged = true;
373+
}
374+
}
361375
#endregion
362376

363377
#region NetworkInterface

Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@
219219
<system:String x:Key="String_Host">Host</system:String>
220220
<system:String x:Key="String_CouldNotResolveHostnameFor">Hostname konnte nicht aufgelöst werden für: "{0}"</system:String>
221221
<system:String x:Key="String_NothingToDoCheckYourInput">Nichts zu tun. Überprüfen Sie Ihre Eingabe!</system:String>
222+
<system:String x:Key="String_Scanned">Gescannt</system:String>
223+
<system:String x:Key="String_Found">Found</system:String>
222224

223225
<!-- Buttons -->
224226
<system:String x:Key="String_Button_Change">Wechseln</system:String>

Source/NETworkManager/Resources/Localization/Resources.en-US.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@
221221
<system:String x:Key="String_Host">Host</system:String>
222222
<system:String x:Key="String_CouldNotResolveHostnameFor">Could not resolve hostname for: "{0}"</system:String>
223223
<system:String x:Key="String_NothingToDoCheckYourInput">Nothing to do. Check your input!</system:String>
224+
<system:String x:Key="String_Scanned">Scanned</system:String>
225+
<system:String x:Key="String_Found">Found</system:String>
224226

225227
<!-- Buttons -->
226228
<system:String x:Key="String_Button_Change">Change</system:String>

Source/NETworkManager/ViewModels/Applications/IPScannerViewModel.cs

Lines changed: 131 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using System.Collections.Generic;
1010
using NETworkManager.Models.Network;
1111
using NETworkManager.Helpers;
12+
using System.Windows.Threading;
13+
using System.Diagnostics;
1214

1315
namespace NETworkManager.ViewModels.Applications
1416
{
@@ -20,6 +22,9 @@ public class IPScannerViewModel : ViewModelBase
2022

2123
CancellationTokenSource cancellationTokenSource;
2224

25+
DispatcherTimer dispatcherTimer = new DispatcherTimer();
26+
Stopwatch stopwatch = new Stopwatch();
27+
2328
private bool _isLoading = true;
2429

2530
private string _ipRange;
@@ -104,30 +109,44 @@ public bool ResolveMACAddress
104109
get { return SettingsManager.Current.IPScanner_ResolveMACAddress; }
105110
}
106111

107-
private int _progressBarMaximum;
108-
public int ProgressBarMaximum
112+
private int _ipAddressesToScan;
113+
public int IPAddressesToScan
114+
{
115+
get { return _ipAddressesToScan; }
116+
set
117+
{
118+
if (value == _ipAddressesToScan)
119+
return;
120+
121+
_ipAddressesToScan = value;
122+
OnPropertyChanged();
123+
}
124+
}
125+
126+
private int _ipAddressesScanned;
127+
public int IPAddressesScanned
109128
{
110-
get { return _progressBarMaximum; }
129+
get { return _ipAddressesScanned; }
111130
set
112131
{
113-
if (value == _progressBarMaximum)
132+
if (value == _ipAddressesScanned)
114133
return;
115134

116-
_progressBarMaximum = value;
135+
_ipAddressesScanned = value;
117136
OnPropertyChanged();
118137
}
119138
}
120139

121-
private int _progressBarValue;
122-
public int ProgressBarValue
140+
private int _hostsFound;
141+
public int HostsFound
123142
{
124-
get { return _progressBarValue; }
143+
get { return _hostsFound; }
125144
set
126145
{
127-
if (value == _progressBarValue)
146+
if (value == _hostsFound)
128147
return;
129148

130-
_progressBarValue = value;
149+
_hostsFound = value;
131150
OnPropertyChanged();
132151
}
133152
}
@@ -145,6 +164,65 @@ public bool PreparingScan
145164
OnPropertyChanged();
146165
}
147166
}
167+
168+
private DateTime? _startTime;
169+
public DateTime? StartTime
170+
{
171+
get { return _startTime; }
172+
set
173+
{
174+
if (value == _startTime)
175+
return;
176+
177+
_startTime = value;
178+
OnPropertyChanged();
179+
}
180+
}
181+
182+
private TimeSpan _duration;
183+
public TimeSpan Duration
184+
{
185+
get { return _duration; }
186+
set
187+
{
188+
if (value == _duration)
189+
return;
190+
191+
_duration = value;
192+
OnPropertyChanged();
193+
}
194+
}
195+
196+
private DateTime? _endTime;
197+
public DateTime? EndTime
198+
{
199+
get { return _endTime; }
200+
set
201+
{
202+
if (value == _endTime)
203+
return;
204+
205+
_endTime = value;
206+
OnPropertyChanged();
207+
}
208+
}
209+
210+
private bool _expandStatistics;
211+
public bool ExpandStatistics
212+
{
213+
get { return _expandStatistics; }
214+
set
215+
{
216+
if (value == _expandStatistics)
217+
return;
218+
219+
if (!_isLoading)
220+
SettingsManager.Current.IPScanner_ExpandStatistics = value;
221+
222+
_expandStatistics = value;
223+
OnPropertyChanged();
224+
}
225+
}
148226
#endregion
149227

150228
#region Constructor, load settings
@@ -165,12 +243,12 @@ public IPScannerViewModel(IDialogCoordinator instance)
165243
_isLoading = false;
166244
}
167245

168-
169-
170246
private void LoadSettings()
171247
{
172248
if (SettingsManager.Current.IPScanner_IPRangeHistory != null)
173249
IPRangeHistory = new List<string>(SettingsManager.Current.IPScanner_IPRangeHistory);
250+
251+
ExpandStatistics = SettingsManager.Current.IPScanner_ExpandStatistics;
174252
}
175253

176254
private void SettingsManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -204,7 +282,16 @@ private async void StartScan()
204282
IsScanRunning = true;
205283
PreparingScan = true;
206284

285+
// Measure the time
286+
StartTime = DateTime.Now;
287+
stopwatch.Start();
288+
dispatcherTimer.Tick += DispatcherTimer_Tick;
289+
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
290+
dispatcherTimer.Start();
291+
EndTime = null;
292+
207293
IPScanResult.Clear();
294+
HostsFound = 0;
208295

209296
IPAddress[] ipAddresses;
210297

@@ -221,8 +308,8 @@ private async void StartScan()
221308
return;
222309
}
223310

224-
ProgressBarMaximum = ipAddresses.Length;
225-
ProgressBarValue = 0;
311+
IPAddressesToScan = ipAddresses.Length;
312+
IPAddressesScanned = 0;
226313

227314
PreparingScan = false;
228315

@@ -254,6 +341,26 @@ private void StopScan()
254341
CancelScan = true;
255342
cancellationTokenSource.Cancel();
256343
}
344+
345+
private void ScanFinished()
346+
{
347+
IsScanRunning = false;
348+
349+
// Stop timer and stopwatch
350+
stopwatch.Stop();
351+
dispatcherTimer.Stop();
352+
353+
Duration = stopwatch.Elapsed;
354+
EndTime = DateTime.Now;
355+
356+
stopwatch.Reset();
357+
}
358+
359+
public void OnShutdown()
360+
{
361+
if (IsScanRunning)
362+
StopScan();
363+
}
257364
#endregion
258365

259366
#region Events
@@ -265,32 +372,32 @@ private void IpScanner_HostFound(object sender, IPScannerHostFoundArgs e)
265372
{
266373
IPScanResult.Add(ipScannerHostInfo);
267374
}));
375+
376+
HostsFound++;
268377
}
269378

270-
private void IpScanner_ScanComplete(object sender, System.EventArgs e)
379+
private void IpScanner_ScanComplete(object sender, EventArgs e)
271380
{
272-
IsScanRunning = false;
381+
ScanFinished();
273382
}
274383

275384
private void IpScanner_ProgressChanged(object sender, ProgressChangedArgs e)
276385
{
277-
ProgressBarValue = e.Value;
386+
IPAddressesScanned = e.Value;
278387
}
279388

280-
private async void UserHasCanceled(object sender, System.EventArgs e)
389+
private async void UserHasCanceled(object sender, EventArgs e)
281390
{
282391
CancelScan = false;
283-
IsScanRunning = false;
392+
393+
ScanFinished();
284394

285395
await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_CanceledByUser"] as string, Application.Current.Resources["String_CanceledByUserMessage"] as string, MessageDialogStyle.Affirmative, dialogSettings);
286396
}
287-
#endregion
288397

289-
#region OnShutdown
290-
public void OnShutdown()
398+
private void DispatcherTimer_Tick(object sender, EventArgs e)
291399
{
292-
if (IsScanRunning)
293-
StopScan();
400+
Duration = stopwatch.Elapsed;
294401
}
295402
#endregion
296403
}

Source/NETworkManager/ViewModels/Applications/PingViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,6 @@ private async void StartPing()
379379
ping.SendAsync(ipAddress, pingOptions, cancellationTokenSource.Token);
380380
}
381381

382-
private void DispatcherTimer_Tick(object sender, EventArgs e)
383-
{
384-
Duration = stopwatch.Elapsed;
385-
}
386-
387382
private void StopPing()
388383
{
389384
CancelPing = true;
@@ -449,7 +444,7 @@ private void Ping_PingReceived(object sender, PingReceivedArgs e)
449444
}
450445
}
451446

452-
private void Ping_PingCompleted(object sender, System.EventArgs e)
447+
private void Ping_PingCompleted(object sender, EventArgs e)
453448
{
454449
PingFinished();
455450
}
@@ -482,6 +477,11 @@ private void Ping_UserHasCanceled(object sender, EventArgs e)
482477

483478
PingFinished();
484479
}
480+
481+
private void DispatcherTimer_Tick(object sender, EventArgs e)
482+
{
483+
Duration = stopwatch.Elapsed;
484+
}
485485
#endregion
486486
}
487487
}

0 commit comments

Comments
 (0)