Skip to content

Commit 61670c2

Browse files
authored
Feature: Group profile (#3089)
* Feature: Group profile * Docs: #3089
1 parent f44a4a9 commit 61670c2

30 files changed

+425
-409
lines changed

Source/NETworkManager.Profiles/Application/AWSSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AWSSessionManager
88
public static AWSSessionManagerSessionInfo CreateSessionInfo(ProfileInfo profile)
99
{
1010
// Get group info
11-
var group = ProfileManager.GetGroup(profile.Group);
11+
var group = ProfileManager.GetGroupByName(profile.Group);
1212

1313
return new AWSSessionManagerSessionInfo
1414
{

Source/NETworkManager.Profiles/Application/PowerShell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class PowerShell
88
public static PowerShellSessionInfo CreateSessionInfo(ProfileInfo profile)
99
{
1010
// Get group info
11-
var group = ProfileManager.GetGroup(profile.Group);
11+
var group = ProfileManager.GetGroupByName(profile.Group);
1212

1313
return new PowerShellSessionInfo
1414
{

Source/NETworkManager.Profiles/Application/PuTTY.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class PuTTY
88
public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profile)
99
{
1010
// Get group info
11-
var group = ProfileManager.GetGroup(profile.Group);
11+
var group = ProfileManager.GetGroupByName(profile.Group);
1212

1313
return new PuTTYSessionInfo
1414
{

Source/NETworkManager.Profiles/Application/RemoteDesktop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profile)
7373
var info = CreateSessionInfo();
7474

7575
// Get group info
76-
var group = ProfileManager.GetGroup(profile.Group);
76+
var group = ProfileManager.GetGroupByName(profile.Group);
7777

7878
// Override hostname
7979
info.Hostname = profile.RemoteDesktop_Host;

Source/NETworkManager.Profiles/Application/SNMP.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static SNMPSessionInfo CreateSessionInfo(ProfileInfo profile)
2323
SNMPSessionInfo info = new();
2424

2525
// Get group info
26-
var group = ProfileManager.GetGroup(profile.Group);
26+
var group = ProfileManager.GetGroupByName(profile.Group);
2727

2828
info.Host = profile.SNMP_Host;
2929

Source/NETworkManager.Profiles/Application/TigerVNC.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class TigerVNC
88
public static TigerVNCSessionInfo CreateSessionInfo(ProfileInfo profile)
99
{
1010
// Get group info
11-
var group = ProfileManager.GetGroup(profile.Group);
11+
var group = ProfileManager.GetGroupByName(profile.Group);
1212

1313
return new TigerVNCSessionInfo
1414
{

Source/NETworkManager.Profiles/ProfileManager.cs

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using System;
1+
using NETworkManager.Settings;
2+
using NETworkManager.Utilities;
3+
using System;
24
using System.Collections.Generic;
35
using System.Collections.ObjectModel;
46
using System.IO;
57
using System.Linq;
68
using System.Security;
79
using System.Text;
810
using System.Xml.Serialization;
9-
using NETworkManager.Settings;
10-
using NETworkManager.Utilities;
1111

1212
namespace NETworkManager.Profiles;
1313

@@ -482,7 +482,7 @@ public static void Save()
482482
// Only if the password provided earlier was valid...
483483
if (LoadedProfileFile.IsPasswordValid)
484484
{
485-
var decryptedBytes = SerializeToByteArray([..Groups]);
485+
var decryptedBytes = SerializeToByteArray([.. Groups]);
486486
var encryptedBytes = CryptoHelper.Encrypt(decryptedBytes,
487487
SecureStringHelper.ConvertToString(LoadedProfileFile.Password),
488488
GlobalStaticConfiguration.Profile_EncryptionKeySize,
@@ -493,7 +493,7 @@ public static void Save()
493493
}
494494
else
495495
{
496-
SerializeToFile(LoadedProfileFile.Path, [..Groups]);
496+
SerializeToFile(LoadedProfileFile.Path, [.. Groups]);
497497
}
498498

499499
ProfilesChanged = false;
@@ -579,25 +579,25 @@ private static List<GroupInfoSerializable> SerializeGroup(List<GroupInfo> groups
579579
continue;
580580

581581
var profilesSerializable = (from profile in @group.Profiles
582-
where !profile.IsDynamic
583-
select new ProfileInfoSerializable(profile)
584-
{
585-
RemoteDesktop_Password = profile.RemoteDesktop_Password != null
586-
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_Password)
587-
: string.Empty,
588-
RemoteDesktop_GatewayServerPassword = profile.RemoteDesktop_GatewayServerPassword != null
589-
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_GatewayServerPassword)
590-
: string.Empty,
591-
SNMP_Community = profile.SNMP_Community != null
592-
? SecureStringHelper.ConvertToString(profile.SNMP_Community)
593-
: string.Empty,
594-
SNMP_Auth = profile.SNMP_Auth != null
595-
? SecureStringHelper.ConvertToString(profile.SNMP_Auth)
596-
: string.Empty,
597-
SNMP_Priv = profile.SNMP_Priv != null
598-
? SecureStringHelper.ConvertToString(profile.SNMP_Priv)
599-
: string.Empty
600-
}).ToList();
582+
where !profile.IsDynamic
583+
select new ProfileInfoSerializable(profile)
584+
{
585+
RemoteDesktop_Password = profile.RemoteDesktop_Password != null
586+
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_Password)
587+
: string.Empty,
588+
RemoteDesktop_GatewayServerPassword = profile.RemoteDesktop_GatewayServerPassword != null
589+
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_GatewayServerPassword)
590+
: string.Empty,
591+
SNMP_Community = profile.SNMP_Community != null
592+
? SecureStringHelper.ConvertToString(profile.SNMP_Community)
593+
: string.Empty,
594+
SNMP_Auth = profile.SNMP_Auth != null
595+
? SecureStringHelper.ConvertToString(profile.SNMP_Auth)
596+
: string.Empty,
597+
SNMP_Priv = profile.SNMP_Priv != null
598+
? SecureStringHelper.ConvertToString(profile.SNMP_Priv)
599+
: string.Empty
600+
}).ToList();
601601

602602
groupsSerializable.Add(new GroupInfoSerializable(group)
603603
{
@@ -655,58 +655,58 @@ private static List<GroupInfo> DeserializeGroup(Stream stream)
655655
XmlSerializer xmlSerializer = new(typeof(List<GroupInfoSerializable>));
656656

657657
return (from groupSerializable in ((List<GroupInfoSerializable>)xmlSerializer.Deserialize(stream))!
658-
let profiles = groupSerializable.Profiles.Select(profileSerializable => new ProfileInfo(profileSerializable)
658+
let profiles = groupSerializable.Profiles.Select(profileSerializable => new ProfileInfo(profileSerializable)
659659
{
660660
// Migrate old data
661661
NetworkInterface_Subnetmask =
662-
string.IsNullOrEmpty(profileSerializable.NetworkInterface_Subnetmask) &&
663-
!string.IsNullOrEmpty(profileSerializable.NetworkInterface_SubnetmaskOrCidr)
664-
? profileSerializable.NetworkInterface_SubnetmaskOrCidr
665-
: profileSerializable.NetworkInterface_Subnetmask,
662+
string.IsNullOrEmpty(profileSerializable.NetworkInterface_Subnetmask) &&
663+
!string.IsNullOrEmpty(profileSerializable.NetworkInterface_SubnetmaskOrCidr)
664+
? profileSerializable.NetworkInterface_SubnetmaskOrCidr
665+
: profileSerializable.NetworkInterface_Subnetmask,
666666

667667
// Convert passwords to secure strings
668668
RemoteDesktop_Password = !string.IsNullOrEmpty(profileSerializable.RemoteDesktop_Password)
669-
? SecureStringHelper.ConvertToSecureString(profileSerializable.RemoteDesktop_Password)
670-
: null,
671-
RemoteDesktop_GatewayServerPassword =
672-
!string.IsNullOrEmpty(profileSerializable.RemoteDesktop_GatewayServerPassword)
673-
? SecureStringHelper.ConvertToSecureString(profileSerializable
674-
.RemoteDesktop_GatewayServerPassword)
669+
? SecureStringHelper.ConvertToSecureString(profileSerializable.RemoteDesktop_Password)
675670
: null,
671+
RemoteDesktop_GatewayServerPassword =
672+
!string.IsNullOrEmpty(profileSerializable.RemoteDesktop_GatewayServerPassword)
673+
? SecureStringHelper.ConvertToSecureString(profileSerializable
674+
.RemoteDesktop_GatewayServerPassword)
675+
: null,
676676
SNMP_Community = !string.IsNullOrEmpty(profileSerializable.SNMP_Community)
677-
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Community)
678-
: null,
677+
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Community)
678+
: null,
679679
SNMP_Auth = !string.IsNullOrEmpty(profileSerializable.SNMP_Auth)
680-
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Auth)
681-
: null,
680+
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Auth)
681+
: null,
682682
SNMP_Priv = !string.IsNullOrEmpty(profileSerializable.SNMP_Priv)
683-
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Priv)
684-
: null
683+
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Priv)
684+
: null
685685
})
686-
.ToList()
687-
select new GroupInfo(groupSerializable)
688-
{
689-
Profiles = profiles,
690-
691-
// Convert passwords to secure strings
692-
RemoteDesktop_Password = !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_Password)
693-
? SecureStringHelper.ConvertToSecureString(groupSerializable.RemoteDesktop_Password)
694-
: null,
695-
RemoteDesktop_GatewayServerPassword =
696-
!string.IsNullOrEmpty(groupSerializable.RemoteDesktop_GatewayServerPassword)
697-
? SecureStringHelper.ConvertToSecureString(
698-
groupSerializable.RemoteDesktop_GatewayServerPassword)
686+
.ToList()
687+
select new GroupInfo(groupSerializable)
688+
{
689+
Profiles = profiles,
690+
691+
// Convert passwords to secure strings
692+
RemoteDesktop_Password = !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_Password)
693+
? SecureStringHelper.ConvertToSecureString(groupSerializable.RemoteDesktop_Password)
699694
: null,
700-
SNMP_Community = !string.IsNullOrEmpty(groupSerializable.SNMP_Community)
701-
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Community)
702-
: null,
703-
SNMP_Auth = !string.IsNullOrEmpty(groupSerializable.SNMP_Auth)
704-
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Auth)
705-
: null,
706-
SNMP_Priv = !string.IsNullOrEmpty(groupSerializable.SNMP_Priv)
707-
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Priv)
708-
: null
709-
}).ToList();
695+
RemoteDesktop_GatewayServerPassword =
696+
!string.IsNullOrEmpty(groupSerializable.RemoteDesktop_GatewayServerPassword)
697+
? SecureStringHelper.ConvertToSecureString(
698+
groupSerializable.RemoteDesktop_GatewayServerPassword)
699+
: null,
700+
SNMP_Community = !string.IsNullOrEmpty(groupSerializable.SNMP_Community)
701+
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Community)
702+
: null,
703+
SNMP_Auth = !string.IsNullOrEmpty(groupSerializable.SNMP_Auth)
704+
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Auth)
705+
: null,
706+
SNMP_Priv = !string.IsNullOrEmpty(groupSerializable.SNMP_Priv)
707+
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Priv)
708+
: null
709+
}).ToList();
710710
}
711711

712712
#endregion
@@ -741,7 +741,7 @@ public static void AddGroup(GroupInfo group)
741741
/// </summary>
742742
/// <param name="name">Name of the group.</param>
743743
/// <returns>Group as <see cref="GroupInfo" />.</returns>
744-
public static GroupInfo GetGroup(string name)
744+
public static GroupInfo GetGroupByName(string name)
745745
{
746746
return Groups.First(x => x.Name.Equals(name));
747747
}

Source/NETworkManager/ProfileDialogManager.cs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,6 @@ public static Task ShowAddProfileDialog(Window parentWindow, IProfileManagerMini
485485
ProfileManager.AddProfile(ParseProfileInfo(instance));
486486
}, _ =>
487487
{
488-
Debug.WriteLine("Profile dialog closed without saving");
489-
490488
childWindow.IsOpen = false;
491489
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;
492490

@@ -607,65 +605,67 @@ public static Task ShowDeleteProfileDialog(Window parentWindow, IProfileManagerM
607605

608606
#region Dialog to add, edit and delete group
609607

610-
public static Task ShowAddGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator)
608+
public static Task ShowAddGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel)
611609
{
612-
CustomDialog customDialog = new()
613-
{
614-
Title = Strings.AddGroup,
615-
Style = (Style)Application.Current.FindResource(DialogResourceKey)
616-
};
617-
618-
GroupViewModel groupViewModel = new(async instance =>
610+
var childWindow = new GroupChildWindow(parentWindow);
611+
612+
GroupViewModel childWindowViewModel = new(instance =>
619613
{
620-
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
614+
childWindow.IsOpen = false;
615+
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;
616+
621617
viewModel.OnProfileManagerDialogClose();
622-
618+
623619
ProfileManager.AddGroup(ParseGroupInfo(instance));
624-
}, async _ =>
620+
}, _ =>
625621
{
626-
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
622+
childWindow.IsOpen = false;
623+
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;
624+
627625
viewModel.OnProfileManagerDialogClose();
628626
}, ProfileManager.GetGroupNames());
629-
630-
customDialog.Content = new GroupDialog
631-
{
632-
DataContext = groupViewModel
633-
};
634-
627+
628+
childWindow.Title = Strings.AddGroup;
629+
630+
childWindow.DataContext = childWindowViewModel;
631+
635632
viewModel.OnProfileManagerDialogOpen();
636-
637-
return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
633+
634+
Settings.ConfigurationManager.Current.IsChildWindowOpen = true;
635+
636+
return parentWindow.ShowChildWindowAsync(childWindow);
638637
}
639638

640-
public static Task ShowEditGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator,
639+
public static Task ShowEditGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel,
641640
GroupInfo group)
642641
{
643-
CustomDialog customDialog = new()
644-
{
645-
Title = Strings.EditGroup,
646-
Style = (Style)Application.Current.FindResource(DialogResourceKey)
647-
};
648-
649-
GroupViewModel groupViewModel = new(async instance =>
642+
var childWindow = new GroupChildWindow(parentWindow);
643+
644+
GroupViewModel childWindowViewModel = new(instance =>
650645
{
651-
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
646+
childWindow.IsOpen = false;
647+
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;
648+
652649
viewModel.OnProfileManagerDialogClose();
653-
654-
ProfileManager.ReplaceGroup(instance.Group, ParseGroupInfo(instance));
655-
}, async _ =>
650+
651+
ProfileManager.ReplaceGroup(group, ParseGroupInfo(instance));
652+
}, _ =>
656653
{
657-
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
654+
childWindow.IsOpen = false;
655+
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;
656+
658657
viewModel.OnProfileManagerDialogClose();
659658
}, ProfileManager.GetGroupNames(), GroupEditMode.Edit, group);
660-
661-
customDialog.Content = new GroupDialog
662-
{
663-
DataContext = groupViewModel
664-
};
665-
659+
660+
childWindow.Title = Strings.EditGroup;
661+
662+
childWindow.DataContext = childWindowViewModel;
663+
666664
viewModel.OnProfileManagerDialogOpen();
667-
668-
return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
665+
666+
Settings.ConfigurationManager.Current.IsChildWindowOpen = true;
667+
668+
return parentWindow.ShowChildWindowAsync(childWindow);
669669
}
670670

671671
public static Task ShowDeleteGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel,
@@ -688,13 +688,13 @@ public static Task ShowDeleteGroupDialog(Window parentWindow, IProfileManagerMin
688688

689689
viewModel.OnProfileManagerDialogClose();
690690
}, Strings.DeleteGroupMessage);
691-
691+
692692
childWindow.Title = Strings.DeleteGroup;
693693

694694
childWindow.DataContext = childWindowViewModel;
695-
695+
696696
viewModel.OnProfileManagerDialogOpen();
697-
697+
698698
Settings.ConfigurationManager.Current.IsChildWindowOpen = true;
699699

700700
return parentWindow.ShowChildWindowAsync(childWindow);

0 commit comments

Comments
 (0)