1414using System . ComponentModel ;
1515using System . Windows . Data ;
1616using MahApps . Metro . Controls . Dialogs ;
17+ using NETworkManager . ViewModels . Dialogs ;
18+ using NETworkManager . Views . Dialogs ;
1719
1820namespace NETworkManager . ViewModels . Applications
1921{
@@ -281,6 +283,22 @@ public ICollectionView PortScannerProfiles
281283 get { return _portScannerProfiles ; }
282284 }
283285
286+ public List < string > PortScannerProfileGroups
287+ {
288+ get
289+ {
290+ List < string > list = new List < string > ( ) ;
291+
292+ foreach ( PortScannerProfileInfo profile in PortScannerProfileManager . Profiles )
293+ {
294+ if ( ! list . Contains ( profile . Group ) )
295+ list . Add ( profile . Group ) ;
296+ }
297+
298+ return list ;
299+ }
300+ }
301+
284302 private PortScannerProfileInfo _selectedProfile = new PortScannerProfileInfo ( ) ;
285303 public PortScannerProfileInfo SelectedProfile
286304 {
@@ -291,7 +309,10 @@ public PortScannerProfileInfo SelectedProfile
291309 return ;
292310
293311 if ( value != null )
312+ {
313+ HostnameOrIPAddress = value . HostnameOrIPAddress ;
294314 Ports = value . Ports ;
315+ }
295316
296317 _selectedProfile = value ;
297318 OnPropertyChanged ( ) ;
@@ -327,10 +348,11 @@ public PortScannerViewModel(IDialogCoordinator instance)
327348 PortScannerProfileManager . Load ( ) ;
328349
329350 _portScannerProfiles = CollectionViewSource . GetDefaultView ( PortScannerProfileManager . Profiles ) ;
351+ _portScannerProfiles . GroupDescriptions . Add ( new PropertyGroupDescription ( "Group" ) ) ;
330352 _portScannerProfiles . SortDescriptions . Add ( new SortDescription ( "Name" , ListSortDirection . Ascending ) ) ;
331353
332354 LoadSettings ( ) ;
333-
355+
334356 _isLoading = false ;
335357 }
336358
@@ -379,23 +401,113 @@ public ICommand AddProfileCommand
379401
380402 private async void AddProfileAction ( )
381403 {
382- MetroDialogSettings settings = AppearanceManager . MetroDialog ;
404+ CustomDialog customDialog = new CustomDialog ( )
405+ {
406+ Title = Application . Current . Resources [ "String_Header_AddProfile" ] as string
407+ } ;
383408
384- settings . AffirmativeButtonText = Application . Current . Resources [ "String_Button_Add" ] as string ;
385- settings . NegativeButtonText = Application . Current . Resources [ "String_Button_Cancel" ] as string ;
409+ PortScannerProfileViewModel portScannerProfileViewModel = new PortScannerProfileViewModel ( instance =>
410+ {
411+ dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
412+
413+ PortScannerProfileInfo portScannerProfileInfo = new PortScannerProfileInfo
414+ {
415+ Name = instance . Name ,
416+ HostnameOrIPAddress = instance . HostnameOrIPAddress ,
417+ Ports = instance . Ports ,
418+ Group = instance . Group
419+ } ;
386420
387- string name = await dialogCoordinator . ShowInputAsync ( this , Application . Current . Resources [ "String_Header_AddProfile" ] as string , Application . Current . Resources [ "String_EnterNameForProfile" ] as string , settings ) ;
421+ PortScannerProfileManager . AddProfile ( portScannerProfileInfo ) ;
422+ } , instance =>
423+ {
424+ dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
425+ } , PortScannerProfileGroups , new PortScannerProfileInfo ( ) { HostnameOrIPAddress = HostnameOrIPAddress , Ports = Ports } ) ;
388426
389- if ( string . IsNullOrEmpty ( name ) )
390- return ;
427+ customDialog . Content = new PortScannerProfileDialog
428+ {
429+ DataContext = portScannerProfileViewModel
430+ } ;
431+
432+ await dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
433+ }
434+
435+ public ICommand EditProfileCommand
436+ {
437+ get { return new RelayCommand ( p => EditProfileAction ( ) ) ; }
438+ }
439+
440+ private async void EditProfileAction ( )
441+ {
442+ CustomDialog customDialog = new CustomDialog ( )
443+ {
444+ Title = Application . Current . Resources [ "String_Header_EditProfile" ] as string
445+ } ;
446+
447+ PortScannerProfileViewModel portScannerProfileViewModel = new PortScannerProfileViewModel ( instance =>
448+ {
449+ dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
450+
451+ PortScannerProfileManager . RemoveProfile ( SelectedProfile ) ;
452+
453+ PortScannerProfileInfo portScannerProfileInfo = new PortScannerProfileInfo
454+ {
455+ Name = instance . Name ,
456+ HostnameOrIPAddress = instance . HostnameOrIPAddress ,
457+ Ports = instance . Ports ,
458+ Group = instance . Group
459+ } ;
460+
461+ PortScannerProfileManager . AddProfile ( portScannerProfileInfo ) ;
462+ } , instance =>
463+ {
464+ dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
465+ } , PortScannerProfileGroups , SelectedProfile ) ;
466+
467+ customDialog . Content = new PortScannerProfileDialog
468+ {
469+ DataContext = portScannerProfileViewModel
470+ } ;
471+
472+ await dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
473+ }
474+
475+ public ICommand CopyAsProfileCommand
476+ {
477+ get { return new RelayCommand ( p => CopyAsProfileAction ( ) ) ; }
478+ }
479+
480+ private async void CopyAsProfileAction ( )
481+ {
482+ CustomDialog customDialog = new CustomDialog ( )
483+ {
484+ Title = Application . Current . Resources [ "String_Header_CopyProfile" ] as string
485+ } ;
486+
487+ PortScannerProfileViewModel portScannerProfileViewModel = new PortScannerProfileViewModel ( instance =>
488+ {
489+ dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
490+
491+ PortScannerProfileInfo portScannerProfileInfo = new PortScannerProfileInfo
492+ {
493+ Name = instance . Name ,
494+ HostnameOrIPAddress = instance . HostnameOrIPAddress ,
495+ Ports = instance . Ports ,
496+ Group = instance . Group
497+ } ;
498+
499+ PortScannerProfileManager . AddProfile ( portScannerProfileInfo ) ;
500+ } , instance =>
501+ {
502+ dialogCoordinator . HideMetroDialogAsync ( this , customDialog ) ;
503+ } , PortScannerProfileGroups , SelectedProfile ) ;
391504
392- PortScannerProfileInfo profile = new PortScannerProfileInfo
505+ customDialog . Content = new PortScannerProfileDialog
393506 {
394- Name = name ,
395- Ports = Ports
507+ DataContext = portScannerProfileViewModel
396508 } ;
397509
398- PortScannerProfileManager . AddProfile ( profile ) ;
510+ await dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
399511 }
400512
401513 public ICommand DeleteProfileCommand
0 commit comments