From 23d75e78c6dcd5738d4425e1eda8eba84d819bac Mon Sep 17 00:00:00 2001
From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Date: Mon, 6 Mar 2023 04:43:15 +0100
Subject: [PATCH] Chore: Replace function / make generic
---
.../IProfileManager.cs | 6 +--
.../IProfileManagerMinimal.cs | 19 +++++++++
Source/NETworkManager/ProfileDialogManager.cs | 18 ++++-----
.../AWSSessionManagerHostViewModel.cs | 2 +-
.../ViewModels/DNSLookupHostViewModel.cs | 2 +-
.../ViewModels/IPScannerHostViewModel.cs | 2 +-
.../ViewModels/IPScannerViewModel.cs | 40 +++++++------------
.../ViewModels/NetworkInterfaceViewModel.cs | 2 +-
.../ViewModels/PingMonitorHostViewModel.cs | 2 +-
.../ViewModels/PortScannerHostViewModel.cs | 2 +-
.../ViewModels/PowerShellHostViewModel.cs | 2 +-
.../ViewModels/ProfilesViewModel.cs | 2 +-
.../ViewModels/PuTTYHostViewModel.cs | 2 +-
.../ViewModels/RemoteDesktopHostViewModel.cs | 2 +-
.../ViewModels/TigerVNCHostViewModel.cs | 2 +-
.../ViewModels/TracerouteHostViewModel.cs | 2 +-
.../ViewModels/WakeOnLANViewModel.cs | 2 +-
.../ViewModels/WebConsoleHostViewModel.cs | 2 +-
.../ViewModels/WhoisHostViewModel.cs | 2 +-
19 files changed, 60 insertions(+), 53 deletions(-)
create mode 100644 Source/NETworkManager.Profiles/IProfileManagerMinimal.cs
diff --git a/Source/NETworkManager.Profiles/IProfileManager.cs b/Source/NETworkManager.Profiles/IProfileManager.cs
index efa6665e80..e3966d05d1 100644
--- a/Source/NETworkManager.Profiles/IProfileManager.cs
+++ b/Source/NETworkManager.Profiles/IProfileManager.cs
@@ -3,11 +3,9 @@
namespace NETworkManager.Profiles
{
- public interface IProfileManager
+ public interface IProfileManager : IProfileManagerMinimal
{
- ICollectionView Profiles { get; }
- void OnProfileDialogOpen();
- void OnProfileDialogClose();
+ ICollectionView Profiles { get; }
ICommand AddProfileCommand { get; }
ICommand EditProfileCommand { get; }
ICommand CopyAsProfileCommand { get; }
diff --git a/Source/NETworkManager.Profiles/IProfileManagerMinimal.cs b/Source/NETworkManager.Profiles/IProfileManagerMinimal.cs
new file mode 100644
index 0000000000..9485dc9f42
--- /dev/null
+++ b/Source/NETworkManager.Profiles/IProfileManagerMinimal.cs
@@ -0,0 +1,19 @@
+namespace NETworkManager.Profiles
+{
+ ///
+ /// Interface for the profile manager.
+ /// Minimal implementation to get the view model.
+ ///
+ public interface IProfileManagerMinimal
+ {
+ ///
+ /// Event is fired when the profile dialog is opened.
+ ///
+ void OnProfileDialogOpen();
+
+ ///
+ /// Event is fired when the profile dialog is closed.
+ ///
+ void OnProfileDialogClose();
+ }
+}
diff --git a/Source/NETworkManager/ProfileDialogManager.cs b/Source/NETworkManager/ProfileDialogManager.cs
index 8064dadf61..05073cc958 100644
--- a/Source/NETworkManager/ProfileDialogManager.cs
+++ b/Source/NETworkManager/ProfileDialogManager.cs
@@ -14,11 +14,11 @@ namespace NETworkManager;
public static class ProfileDialogManager
{
#region Variables
- private static string DialogResourceKey = "LargeMetroDialog";
+ private static string DialogResourceKey => "LargeMetroDialog";
#endregion
#region Dialog to add, edit, copy as and delete profile
- public static async Task ShowAddProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, string group = null, ApplicationName applicationName = ApplicationName.None)
+ public static async Task ShowAddProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile = null, string group = null, ApplicationName applicationName = ApplicationName.None)
{
CustomDialog customDialog = new()
{
@@ -36,7 +36,7 @@ public static async Task ShowAddProfileDialog(IProfileManager viewModel, IDialog
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
viewModel.OnProfileDialogClose();
- }, ProfileManager.GetGroupNames(), group, ProfileEditMode.Add, null, applicationName);
+ }, ProfileManager.GetGroupNames(), group, ProfileEditMode.Add, profile, applicationName);
customDialog.Content = new ProfileDialog
{
@@ -48,7 +48,7 @@ public static async Task ShowAddProfileDialog(IProfileManager viewModel, IDialog
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
}
- public static async Task ShowEditProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
+ public static async Task ShowEditProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
{
CustomDialog customDialog = new()
{
@@ -77,7 +77,7 @@ public static async Task ShowEditProfileDialog(IProfileManager viewModel, IDialo
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
}
- public static async Task ShowCopyAsProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
+ public static async Task ShowCopyAsProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
{
CustomDialog customDialog = new()
{
@@ -106,7 +106,7 @@ public static async Task ShowCopyAsProfileDialog(IProfileManager viewModel, IDia
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
}
- public static async Task ShowDeleteProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, IList profiles)
+ public static async Task ShowDeleteProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, IList profiles)
{
CustomDialog customDialog = new()
{
@@ -137,7 +137,7 @@ public static async Task ShowDeleteProfileDialog(IProfileManager viewModel, IDia
#endregion
#region Dialog to add, edit and delete group
- public static async Task ShowAddGroupDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator)
+ public static async Task ShowAddGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator)
{
CustomDialog customDialog = new()
{
@@ -166,7 +166,7 @@ public static async Task ShowAddGroupDialog(IProfileManager viewModel, IDialogCo
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
}
- public static async Task ShowEditGroupDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
+ public static async Task ShowEditGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
{
CustomDialog customDialog = new()
{
@@ -195,7 +195,7 @@ public static async Task ShowEditGroupDialog(IProfileManager viewModel, IDialogC
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
}
- public static async Task ShowDeleteGroupDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
+ public static async Task ShowDeleteGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
{
CustomDialog customDialog = new()
{
diff --git a/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs b/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs
index ef4b939800..fa743bea90 100644
--- a/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs
@@ -415,7 +415,7 @@ private void ConnectProfileExternalAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.AWSSessionManager);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.AWSSessionManager);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs b/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs
index 3beb888aa2..42180d4237 100644
--- a/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs
@@ -224,7 +224,7 @@ private void LookupProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.DNSLookup);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.DNSLookup);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs b/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs
index 5d59390f1b..3b68d02828 100644
--- a/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs
@@ -224,7 +224,7 @@ private void ScanProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.IPScanner);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.IPScanner);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/IPScannerViewModel.cs b/Source/NETworkManager/ViewModels/IPScannerViewModel.cs
index 946efb60c0..2676692cda 100644
--- a/Source/NETworkManager/ViewModels/IPScannerViewModel.cs
+++ b/Source/NETworkManager/ViewModels/IPScannerViewModel.cs
@@ -29,7 +29,7 @@
namespace NETworkManager.ViewModels
{
- public class IPScannerViewModel : ViewModelBase
+ public class IPScannerViewModel : ViewModelBase, IProfileManagerMinimal
{
#region Variables
private readonly IDialogCoordinator _dialogCoordinator;
@@ -287,7 +287,7 @@ private void DetectSubnetAction()
private void RedirectDataToApplicationAction(object name)
{
- if (!(name is string appName))
+ if (name is not string appName)
return;
if (!Enum.TryParse(appName, out ApplicationName applicationName))
@@ -321,7 +321,7 @@ private void CustomCommandAction(object guid)
public ICommand AddProfileSelectedHostCommand => new RelayCommand(p => AddProfileSelectedHostAction());
- private async Task AddProfileSelectedHostAction()
+ private async void AddProfileSelectedHostAction()
{
ProfileInfo profileInfo = new()
{
@@ -332,27 +332,7 @@ private async Task AddProfileSelectedHostAction()
WakeOnLAN_MACAddress = SelectedResult.MACAddressString
};
- var customDialog = new CustomDialog
- {
- Title = Localization.Resources.Strings.AddProfile
- };
-
- var profileViewModel = new ProfileViewModel(instance =>
- {
- _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
-
- ProfileManager.AddProfile(ProfileDialogManager.ParseProfileInfo(instance));
- }, instance =>
- {
- _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
- }, ProfileManager.GetGroupNames(), null, ProfileEditMode.Add, profileInfo);
-
- customDialog.Content = new ProfileDialog
- {
- DataContext = profileViewModel
- };
-
- await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
+ await ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, profileInfo);
}
public ICommand CopySelectedIPAddressCommand => new RelayCommand(p => CopySelectedIPAddressAction());
@@ -412,7 +392,7 @@ private void CopySelectedStatusAction()
}
public ICommand ExportCommand => new RelayCommand(p => ExportAction());
-
+
private void ExportAction()
{
Export();
@@ -693,6 +673,16 @@ private void SettingsManager_PropertyChanged(object sender, PropertyChangedEvent
break;
}
}
+
+ public void OnProfileDialogOpen()
+ {
+
+ }
+
+ public void OnProfileDialogClose()
+ {
+
+ }
#endregion
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs b/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs
index 2b8d4f983a..f3858b0d39 100644
--- a/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs
+++ b/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs
@@ -642,7 +642,7 @@ private void ApplyProfileProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator,null, ApplicationName.NetworkInterface);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.NetworkInterface);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs b/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs
index 151ef935b7..9cf04a68c2 100644
--- a/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs
@@ -306,7 +306,7 @@ private void AddHostProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.PingMonitor);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PingMonitor);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs b/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs
index 411e4b7608..df8a8a9928 100644
--- a/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs
@@ -218,7 +218,7 @@ private void ScanProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.PortScanner);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PortScanner);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs b/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs
index 389e94b93a..9a63937de8 100644
--- a/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs
@@ -341,7 +341,7 @@ private void ConnectProfileExternalAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.PowerShell);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PowerShell);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/ProfilesViewModel.cs b/Source/NETworkManager/ViewModels/ProfilesViewModel.cs
index 557f3b8f63..bf0aa2bb51 100644
--- a/Source/NETworkManager/ViewModels/ProfilesViewModel.cs
+++ b/Source/NETworkManager/ViewModels/ProfilesViewModel.cs
@@ -191,7 +191,7 @@ public void SetProfilesView(string groupName, ProfileInfo selectedProfileInfo =
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, SelectedGroup?.Name);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, SelectedGroup?.Name);
}
public ICommand EditProfileCommand => new RelayCommand(p => EditProfileAction(), EditProfile_CanExecute);
diff --git a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs
index 11bd440c4f..a2939b1614 100644
--- a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs
@@ -353,7 +353,7 @@ private void ConnectProfileExternalAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.PuTTY);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PuTTY);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs
index a3033730d1..04b4b872af 100644
--- a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs
@@ -311,7 +311,7 @@ private void ConnectProfileExternalAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator,null, ApplicationName.RemoteDesktop);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.RemoteDesktop);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs b/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs
index 8fe697c4c9..f0ad5e0e44 100644
--- a/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs
@@ -276,7 +276,7 @@ private void ConnectProfileExternalAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.TigerVNC);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.TigerVNC);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs b/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs
index f8e44337f4..dbc13d0ef5 100644
--- a/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs
@@ -224,7 +224,7 @@ private void TraceProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.Traceroute);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.Traceroute);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs b/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs
index 5f9682e8c7..a0752861e8 100644
--- a/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs
+++ b/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs
@@ -288,7 +288,7 @@ private void WakeUpProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.WakeOnLAN);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.WakeOnLAN);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs b/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs
index 8f7403026a..c0ff2b2822 100644
--- a/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs
@@ -278,7 +278,7 @@ private void ConnectProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.WebConsole);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.WebConsole);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
diff --git a/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs b/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs
index b1016af343..6f2dd140cc 100644
--- a/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs
+++ b/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs
@@ -226,7 +226,7 @@ private void QueryProfileAction()
private void AddProfileAction()
{
- ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.Whois);
+ ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.Whois);
}
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;