Skip to content

Commit 14b6978

Browse files
committed
PortScanner - profile dialog (add/edit/copy as) added
1 parent acc6ea9 commit 14b6978

10 files changed

Lines changed: 437 additions & 28 deletions

Source/NETworkManager/Models/Settings/PortScannerProfileInfo.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
public class PortScannerProfileInfo
44
{
55
public string Name { get; set; }
6+
public string HostnameOrIPAddress { get; set; }
67
public string Ports { get; set; }
7-
8+
public string Group { get; set; }
9+
810
public PortScannerProfileInfo()
911
{
1012

1113
}
1214

13-
public PortScannerProfileInfo(string name, string ports)
15+
public PortScannerProfileInfo(string name, string hostnameOrIPAddress, string ports, string group)
1416
{
1517
Name = name;
18+
HostnameOrIPAddress = hostnameOrIPAddress;
1619
Ports = ports;
20+
Group = group;
1721
}
1822
}
1923
}

Source/NETworkManager/Models/Settings/PortScannerProfileManager.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
33
using System.IO;
4+
using System.Windows;
45
using System.Xml.Serialization;
56

67
namespace NETworkManager.Models.Settings
@@ -37,12 +38,12 @@ private static List<PortScannerProfileInfo> GetDefaultProfiles()
3738
{
3839
return new List<PortScannerProfileInfo>
3940
{
40-
new PortScannerProfileInfo("1-1023 (well known)", "1-1023"),
41-
new PortScannerProfileInfo("FTP","20; 21"),
42-
new PortScannerProfileInfo("LDAP/LDAPS", "389; 636"),
43-
new PortScannerProfileInfo("RDP", "3389"),
44-
new PortScannerProfileInfo("SSH", "22"),
45-
new PortScannerProfileInfo("Webserver", "80; 443"),
41+
new PortScannerProfileInfo("1-1023 (well known)",string.Empty, "1-1023", Application.Current.Resources["String_Default"] as string),
42+
new PortScannerProfileInfo("FTP",string.Empty,"20; 21", Application.Current.Resources["String_Default"] as string),
43+
new PortScannerProfileInfo("LDAP/LDAPS", string.Empty,"389; 636", Application.Current.Resources["String_Default"] as string),
44+
new PortScannerProfileInfo("RDP", string.Empty,"3389", Application.Current.Resources["String_Default"] as string),
45+
new PortScannerProfileInfo("SSH",string.Empty, "22", Application.Current.Resources["String_Default"] as string),
46+
new PortScannerProfileInfo("Webserver", string.Empty, "80; 443", Application.Current.Resources["String_Default"] as string),
4647
};
4748
}
4849

Source/NETworkManager/NETworkManager.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
<Compile Include="Models\RemoteDesktop\RemoteDesktopSessionInfo.cs" />
188188
<Compile Include="Models\Settings\RemoteDesktopSessionManager.cs" />
189189
<Compile Include="Models\Settings\RemoteDesktopSessionInfo.cs" />
190+
<Compile Include="ViewModels\Dialogs\PortScannerProfileViewModel.cs" />
190191
<Compile Include="ViewModels\Dialogs\WakeOnLANClientViewModel.cs" />
191192
<Compile Include="ViewModels\Dialogs\IPScannerProfileViewModel.cs" />
192193
<Compile Include="ViewModels\Dialogs\RemoteDesktopSessionViewModel.cs" />
@@ -235,6 +236,9 @@
235236
<Compile Include="Controls\DragablzTabHostWindow.xaml.cs">
236237
<DependentUpon>DragablzTabHostWindow.xaml</DependentUpon>
237238
</Compile>
239+
<Compile Include="Views\Dialogs\PortScannerProfileDialog.xaml.cs">
240+
<DependentUpon>PortScannerProfileDialog.xaml</DependentUpon>
241+
</Compile>
238242
<Compile Include="Views\Dialogs\WakeOnLANClientDialog.xaml.cs">
239243
<DependentUpon>WakeOnLANClientDialog.xaml</DependentUpon>
240244
</Compile>
@@ -367,6 +371,10 @@
367371
<Generator>MSBuild:Compile</Generator>
368372
<SubType>Designer</SubType>
369373
</Page>
374+
<Page Include="Views\Dialogs\PortScannerProfileDialog.xaml">
375+
<Generator>MSBuild:Compile</Generator>
376+
<SubType>Designer</SubType>
377+
</Page>
370378
<Page Include="Views\Dialogs\WakeOnLANClientDialog.xaml">
371379
<Generator>MSBuild:Compile</Generator>
372380
<SubType>Designer</SubType>

Source/NETworkManager/ViewModels/Applications/PortScannerViewModel.cs

Lines changed: 123 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using System.ComponentModel;
1515
using System.Windows.Data;
1616
using MahApps.Metro.Controls.Dialogs;
17+
using NETworkManager.ViewModels.Dialogs;
18+
using NETworkManager.Views.Dialogs;
1719

1820
namespace 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

Comments
 (0)