@@ -36,8 +36,6 @@ public class PortScannerViewModel : ViewModelBase
36
36
37
37
private string _lastSortDescriptionAscending = string . Empty ;
38
38
39
- private bool _isLoading ;
40
-
41
39
private string _hosts ;
42
40
public string Hosts
43
41
{
@@ -70,16 +68,16 @@ public string Ports
70
68
71
69
public ICollectionView PortsHistoryView { get ; }
72
70
73
- private bool _isScanRunning ;
74
- public bool IsScanRunning
71
+ private bool _isRunning ;
72
+ public bool IsRunning
75
73
{
76
- get => _isScanRunning ;
74
+ get => _isRunning ;
77
75
set
78
76
{
79
- if ( value == _isScanRunning )
77
+ if ( value == _isRunning )
80
78
return ;
81
79
82
- _isScanRunning = value ;
80
+ _isRunning = value ;
83
81
84
82
OnPropertyChanged ( ) ;
85
83
}
@@ -141,9 +139,7 @@ public IList SelectedResults
141
139
OnPropertyChanged ( ) ;
142
140
}
143
141
}
144
-
145
- public bool ResolveHostname => SettingsManager . Current . PortScanner_ResolveHostname ;
146
-
142
+
147
143
private int _portsToScan ;
148
144
public int PortsToScan
149
145
{
@@ -204,7 +200,7 @@ public bool IsStatusMessageDisplayed
204
200
public string StatusMessage
205
201
{
206
202
get => _statusMessage ;
207
- set
203
+ private set
208
204
{
209
205
if ( value == _statusMessage )
210
206
return ;
@@ -218,8 +214,6 @@ public string StatusMessage
218
214
#region Constructor, load settings, shutdown
219
215
public PortScannerViewModel ( IDialogCoordinator instance , int tabId , string host , string port )
220
216
{
221
- _isLoading = true ;
222
-
223
217
_dialogCoordinator = instance ;
224
218
225
219
_tabId = tabId ;
@@ -236,11 +230,6 @@ public PortScannerViewModel(IDialogCoordinator instance, int tabId, string host,
236
230
ResultsView . SortDescriptions . Add ( new SortDescription ( nameof ( PortScannerPortInfo . IPAddressInt32 ) , ListSortDirection . Descending ) ) ;
237
231
238
232
LoadSettings ( ) ;
239
-
240
- // Detect if settings have changed...
241
- SettingsManager . Current . PropertyChanged += SettingsManager_PropertyChanged ;
242
-
243
- _isLoading = false ;
244
233
}
245
234
246
235
private void LoadSettings ( )
@@ -254,27 +243,27 @@ public void OnLoaded()
254
243
return ;
255
244
256
245
if ( ! string . IsNullOrEmpty ( Hosts ) && ! string . IsNullOrEmpty ( Ports ) )
257
- StartScan ( ) ;
246
+ StartScan ( ) . ConfigureAwait ( false ) ;
258
247
259
248
_firstLoad = false ;
260
249
}
261
250
262
251
public void OnClose ( )
263
252
{
264
253
// Stop scan
265
- if ( IsScanRunning )
254
+ if ( IsRunning )
266
255
StopScan ( ) ;
267
256
}
268
257
#endregion
269
258
270
259
#region ICommands & Actions
271
- public ICommand OpenPortProfileSelectionCommand => new RelayCommand ( p => OpenPortProfileSelectionAction ( ) , OpenPortProfileSelection_CanExecute ) ;
260
+ public ICommand OpenPortProfileSelectionCommand => new RelayCommand ( _ => OpenPortProfileSelectionAction ( ) , OpenPortProfileSelection_CanExecute ) ;
272
261
273
262
private bool OpenPortProfileSelection_CanExecute ( object parameter ) => Application . Current . MainWindow != null && ! ( ( MetroWindow ) Application . Current . MainWindow ) . IsAnyDialogOpen ;
274
263
275
264
private void OpenPortProfileSelectionAction ( )
276
265
{
277
- OpenPortProfileSelection ( ) ;
266
+ OpenPortProfileSelection ( ) . ConfigureAwait ( false ) ;
278
267
}
279
268
280
269
public ICommand ScanCommand => new RelayCommand ( _ => ScanAction ( ) , Scan_CanExecute ) ;
@@ -283,10 +272,10 @@ private void OpenPortProfileSelectionAction()
283
272
284
273
private void ScanAction ( )
285
274
{
286
- if ( IsScanRunning )
275
+ if ( IsRunning )
287
276
StopScan ( ) ;
288
277
else
289
- StartScan ( ) ;
278
+ StartScan ( ) . ConfigureAwait ( false ) ;
290
279
}
291
280
292
281
public ICommand CopySelectedIPAddressCommand => new RelayCommand ( _ => CopySelectedIPAddressAction ( ) ) ;
@@ -342,7 +331,7 @@ private void CopySelectedDescriptionAction()
342
331
343
332
private void ExportAction ( )
344
333
{
345
- Export ( ) ;
334
+ Export ( ) . ConfigureAwait ( false ) ;
346
335
}
347
336
#endregion
348
337
@@ -359,7 +348,7 @@ private async Task OpenPortProfileSelection()
359
348
await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
360
349
361
350
Ports = string . Join ( "; " , instance . GetSelectedPortProfiles ( ) . Select ( x => x . Ports ) ) ;
362
- } , async instance =>
351
+ } , async _ =>
363
352
{
364
353
await _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
365
354
} ) ;
@@ -374,12 +363,10 @@ private async Task OpenPortProfileSelection()
374
363
375
364
private async Task StartScan ( )
376
365
{
377
- _isLoading = true ;
378
-
379
366
IsStatusMessageDisplayed = false ;
380
367
StatusMessage = string . Empty ;
381
368
382
- IsScanRunning = true ;
369
+ IsRunning = true ;
383
370
PreparingScan = true ;
384
371
385
372
Results . Clear ( ) ;
@@ -465,7 +452,7 @@ private void StopScan()
465
452
private void ScanFinished ( )
466
453
{
467
454
CancelScan = false ;
468
- IsScanRunning = false ;
455
+ IsRunning = false ;
469
456
}
470
457
471
458
private async Task Export ( )
@@ -493,7 +480,7 @@ private async Task Export()
493
480
494
481
SettingsManager . Current . PortScanner_ExportFileType = instance . FileType ;
495
482
SettingsManager . Current . PortScanner_ExportFilePath = instance . FilePath ;
496
- } , instance => { _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ; } , new ExportFileType [ ] { ExportFileType . Csv , ExportFileType . Xml , ExportFileType . Json } , true , SettingsManager . Current . PortScanner_ExportFileType , SettingsManager . Current . PortScanner_ExportFilePath ) ;
483
+ } , _ => { _dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ; } , new [ ] { ExportFileType . Csv , ExportFileType . Xml , ExportFileType . Json } , true , SettingsManager . Current . PortScanner_ExportFileType , SettingsManager . Current . PortScanner_ExportFilePath ) ;
497
484
498
485
customDialog . Content = new ExportDialog
499
486
{
@@ -581,15 +568,6 @@ private void PortScanned(object sender, PortScannerPortScannedArgs e)
581
568
Results . Add ( e . Args ) ;
582
569
} ) ) ;
583
570
}
584
-
585
- private void SettingsManager_PropertyChanged ( object sender , PropertyChangedEventArgs e )
586
- {
587
- switch ( e . PropertyName )
588
- {
589
- case nameof ( SettingsInfo . PortScanner_ResolveHostname ) :
590
- OnPropertyChanged ( nameof ( ResolveHostname ) ) ;
591
- break ;
592
- }
593
- }
571
+
594
572
#endregion
595
573
}
0 commit comments