Skip to content

Commit a95eadb

Browse files
authored
Chore: Replace function / make generic (#1999)
1 parent b8c7825 commit a95eadb

19 files changed

+60
-53
lines changed

Source/NETworkManager.Profiles/IProfileManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33

44
namespace NETworkManager.Profiles
55
{
6-
public interface IProfileManager
6+
public interface IProfileManager : IProfileManagerMinimal
77
{
8-
ICollectionView Profiles { get; }
9-
void OnProfileDialogOpen();
10-
void OnProfileDialogClose();
8+
ICollectionView Profiles { get; }
119
ICommand AddProfileCommand { get; }
1210
ICommand EditProfileCommand { get; }
1311
ICommand CopyAsProfileCommand { get; }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace NETworkManager.Profiles
2+
{
3+
/// <summary>
4+
/// Interface for the profile manager.
5+
/// Minimal implementation to get the view model.
6+
/// </summary>
7+
public interface IProfileManagerMinimal
8+
{
9+
/// <summary>
10+
/// Event is fired when the profile dialog is opened.
11+
/// </summary>
12+
void OnProfileDialogOpen();
13+
14+
/// <summary>
15+
/// Event is fired when the profile dialog is closed.
16+
/// </summary>
17+
void OnProfileDialogClose();
18+
}
19+
}

Source/NETworkManager/ProfileDialogManager.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ namespace NETworkManager;
1414
public static class ProfileDialogManager
1515
{
1616
#region Variables
17-
private static string DialogResourceKey = "LargeMetroDialog";
17+
private static string DialogResourceKey => "LargeMetroDialog";
1818
#endregion
1919

2020
#region Dialog to add, edit, copy as and delete profile
21-
public static async Task ShowAddProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, string group = null, ApplicationName applicationName = ApplicationName.None)
21+
public static async Task ShowAddProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile = null, string group = null, ApplicationName applicationName = ApplicationName.None)
2222
{
2323
CustomDialog customDialog = new()
2424
{
@@ -36,7 +36,7 @@ public static async Task ShowAddProfileDialog(IProfileManager viewModel, IDialog
3636
{
3737
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
3838
viewModel.OnProfileDialogClose();
39-
}, ProfileManager.GetGroupNames(), group, ProfileEditMode.Add, null, applicationName);
39+
}, ProfileManager.GetGroupNames(), group, ProfileEditMode.Add, profile, applicationName);
4040

4141
customDialog.Content = new ProfileDialog
4242
{
@@ -48,7 +48,7 @@ public static async Task ShowAddProfileDialog(IProfileManager viewModel, IDialog
4848
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
4949
}
5050

51-
public static async Task ShowEditProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
51+
public static async Task ShowEditProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
5252
{
5353
CustomDialog customDialog = new()
5454
{
@@ -77,7 +77,7 @@ public static async Task ShowEditProfileDialog(IProfileManager viewModel, IDialo
7777
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
7878
}
7979

80-
public static async Task ShowCopyAsProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
80+
public static async Task ShowCopyAsProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, ProfileInfo profile)
8181
{
8282
CustomDialog customDialog = new()
8383
{
@@ -106,7 +106,7 @@ public static async Task ShowCopyAsProfileDialog(IProfileManager viewModel, IDia
106106
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
107107
}
108108

109-
public static async Task ShowDeleteProfileDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, IList<ProfileInfo> profiles)
109+
public static async Task ShowDeleteProfileDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, IList<ProfileInfo> profiles)
110110
{
111111
CustomDialog customDialog = new()
112112
{
@@ -137,7 +137,7 @@ public static async Task ShowDeleteProfileDialog(IProfileManager viewModel, IDia
137137
#endregion
138138

139139
#region Dialog to add, edit and delete group
140-
public static async Task ShowAddGroupDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator)
140+
public static async Task ShowAddGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator)
141141
{
142142
CustomDialog customDialog = new()
143143
{
@@ -166,7 +166,7 @@ public static async Task ShowAddGroupDialog(IProfileManager viewModel, IDialogCo
166166
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
167167
}
168168

169-
public static async Task ShowEditGroupDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
169+
public static async Task ShowEditGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
170170
{
171171
CustomDialog customDialog = new()
172172
{
@@ -195,7 +195,7 @@ public static async Task ShowEditGroupDialog(IProfileManager viewModel, IDialogC
195195
await dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
196196
}
197197

198-
public static async Task ShowDeleteGroupDialog(IProfileManager viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
198+
public static async Task ShowDeleteGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, GroupInfo group)
199199
{
200200
CustomDialog customDialog = new()
201201
{

Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private void ConnectProfileExternalAction()
415415

416416
private void AddProfileAction()
417417
{
418-
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.AWSSessionManager);
418+
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.AWSSessionManager);
419419
}
420420

421421
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;

Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private void LookupProfileAction()
224224

225225
private void AddProfileAction()
226226
{
227-
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.DNSLookup);
227+
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.DNSLookup);
228228
}
229229

230230
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;

Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private void ScanProfileAction()
224224

225225
private void AddProfileAction()
226226
{
227-
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.IPScanner);
227+
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.IPScanner);
228228
}
229229

230230
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;

Source/NETworkManager/ViewModels/IPScannerViewModel.cs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
namespace NETworkManager.ViewModels
3131
{
32-
public class IPScannerViewModel : ViewModelBase
32+
public class IPScannerViewModel : ViewModelBase, IProfileManagerMinimal
3333
{
3434
#region Variables
3535
private readonly IDialogCoordinator _dialogCoordinator;
@@ -287,7 +287,7 @@ private void DetectSubnetAction()
287287

288288
private void RedirectDataToApplicationAction(object name)
289289
{
290-
if (!(name is string appName))
290+
if (name is not string appName)
291291
return;
292292

293293
if (!Enum.TryParse(appName, out ApplicationName applicationName))
@@ -321,7 +321,7 @@ private void CustomCommandAction(object guid)
321321

322322
public ICommand AddProfileSelectedHostCommand => new RelayCommand(p => AddProfileSelectedHostAction());
323323

324-
private async Task AddProfileSelectedHostAction()
324+
private async void AddProfileSelectedHostAction()
325325
{
326326
ProfileInfo profileInfo = new()
327327
{
@@ -332,27 +332,7 @@ private async Task AddProfileSelectedHostAction()
332332
WakeOnLAN_MACAddress = SelectedResult.MACAddressString
333333
};
334334

335-
var customDialog = new CustomDialog
336-
{
337-
Title = Localization.Resources.Strings.AddProfile
338-
};
339-
340-
var profileViewModel = new ProfileViewModel(instance =>
341-
{
342-
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
343-
344-
ProfileManager.AddProfile(ProfileDialogManager.ParseProfileInfo(instance));
345-
}, instance =>
346-
{
347-
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
348-
}, ProfileManager.GetGroupNames(), null, ProfileEditMode.Add, profileInfo);
349-
350-
customDialog.Content = new ProfileDialog
351-
{
352-
DataContext = profileViewModel
353-
};
354-
355-
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
335+
await ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, profileInfo);
356336
}
357337

358338
public ICommand CopySelectedIPAddressCommand => new RelayCommand(p => CopySelectedIPAddressAction());
@@ -412,7 +392,7 @@ private void CopySelectedStatusAction()
412392
}
413393

414394
public ICommand ExportCommand => new RelayCommand(p => ExportAction());
415-
395+
416396
private void ExportAction()
417397
{
418398
Export();
@@ -693,6 +673,16 @@ private void SettingsManager_PropertyChanged(object sender, PropertyChangedEvent
693673
break;
694674
}
695675
}
676+
677+
public void OnProfileDialogOpen()
678+
{
679+
680+
}
681+
682+
public void OnProfileDialogClose()
683+
{
684+
685+
}
696686
#endregion
697687
}
698688
}

Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ private void ApplyProfileProfileAction()
642642

643643
private void AddProfileAction()
644644
{
645-
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator,null, ApplicationName.NetworkInterface);
645+
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.NetworkInterface);
646646
}
647647

648648
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;

Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private void AddHostProfileAction()
306306

307307
private void AddProfileAction()
308308
{
309-
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.PingMonitor);
309+
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PingMonitor);
310310
}
311311

312312
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;

Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private void ScanProfileAction()
218218

219219
private void AddProfileAction()
220220
{
221-
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, ApplicationName.PortScanner);
221+
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PortScanner);
222222
}
223223

224224
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;

0 commit comments

Comments
 (0)