Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class AWSSessionManager
public static AWSSessionManagerSessionInfo CreateSessionInfo(ProfileInfo profile)
{
// Get group info
var group = ProfileManager.GetGroup(profile.Group);
var group = ProfileManager.GetGroupByName(profile.Group);

return new AWSSessionManagerSessionInfo
{
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager.Profiles/Application/PowerShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PowerShell
public static PowerShellSessionInfo CreateSessionInfo(ProfileInfo profile)
{
// Get group info
var group = ProfileManager.GetGroup(profile.Group);
var group = ProfileManager.GetGroupByName(profile.Group);

return new PowerShellSessionInfo
{
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager.Profiles/Application/PuTTY.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class PuTTY
public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profile)
{
// Get group info
var group = ProfileManager.GetGroup(profile.Group);
var group = ProfileManager.GetGroupByName(profile.Group);

return new PuTTYSessionInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profile)
var info = CreateSessionInfo();

// Get group info
var group = ProfileManager.GetGroup(profile.Group);
var group = ProfileManager.GetGroupByName(profile.Group);

// Override hostname
info.Hostname = profile.RemoteDesktop_Host;
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager.Profiles/Application/SNMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static SNMPSessionInfo CreateSessionInfo(ProfileInfo profile)
SNMPSessionInfo info = new();

// Get group info
var group = ProfileManager.GetGroup(profile.Group);
var group = ProfileManager.GetGroupByName(profile.Group);

info.Host = profile.SNMP_Host;

Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager.Profiles/Application/TigerVNC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class TigerVNC
public static TigerVNCSessionInfo CreateSessionInfo(ProfileInfo profile)
{
// Get group info
var group = ProfileManager.GetGroup(profile.Group);
var group = ProfileManager.GetGroupByName(profile.Group);

return new TigerVNCSessionInfo
{
Expand Down
130 changes: 65 additions & 65 deletions Source/NETworkManager.Profiles/ProfileManager.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using NETworkManager.Settings;
using NETworkManager.Utilities;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Security;
using System.Text;
using System.Xml.Serialization;
using NETworkManager.Settings;
using NETworkManager.Utilities;

namespace NETworkManager.Profiles;

Expand Down Expand Up @@ -482,7 +482,7 @@ public static void Save()
// Only if the password provided earlier was valid...
if (LoadedProfileFile.IsPasswordValid)
{
var decryptedBytes = SerializeToByteArray([..Groups]);
var decryptedBytes = SerializeToByteArray([.. Groups]);
var encryptedBytes = CryptoHelper.Encrypt(decryptedBytes,
SecureStringHelper.ConvertToString(LoadedProfileFile.Password),
GlobalStaticConfiguration.Profile_EncryptionKeySize,
Expand All @@ -493,7 +493,7 @@ public static void Save()
}
else
{
SerializeToFile(LoadedProfileFile.Path, [..Groups]);
SerializeToFile(LoadedProfileFile.Path, [.. Groups]);
}

ProfilesChanged = false;
Expand Down Expand Up @@ -579,25 +579,25 @@ private static List<GroupInfoSerializable> SerializeGroup(List<GroupInfo> groups
continue;

var profilesSerializable = (from profile in @group.Profiles
where !profile.IsDynamic
select new ProfileInfoSerializable(profile)
{
RemoteDesktop_Password = profile.RemoteDesktop_Password != null
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_Password)
: string.Empty,
RemoteDesktop_GatewayServerPassword = profile.RemoteDesktop_GatewayServerPassword != null
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_GatewayServerPassword)
: string.Empty,
SNMP_Community = profile.SNMP_Community != null
? SecureStringHelper.ConvertToString(profile.SNMP_Community)
: string.Empty,
SNMP_Auth = profile.SNMP_Auth != null
? SecureStringHelper.ConvertToString(profile.SNMP_Auth)
: string.Empty,
SNMP_Priv = profile.SNMP_Priv != null
? SecureStringHelper.ConvertToString(profile.SNMP_Priv)
: string.Empty
}).ToList();
where !profile.IsDynamic
select new ProfileInfoSerializable(profile)
{
RemoteDesktop_Password = profile.RemoteDesktop_Password != null
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_Password)
: string.Empty,
RemoteDesktop_GatewayServerPassword = profile.RemoteDesktop_GatewayServerPassword != null
? SecureStringHelper.ConvertToString(profile.RemoteDesktop_GatewayServerPassword)
: string.Empty,
SNMP_Community = profile.SNMP_Community != null
? SecureStringHelper.ConvertToString(profile.SNMP_Community)
: string.Empty,
SNMP_Auth = profile.SNMP_Auth != null
? SecureStringHelper.ConvertToString(profile.SNMP_Auth)
: string.Empty,
SNMP_Priv = profile.SNMP_Priv != null
? SecureStringHelper.ConvertToString(profile.SNMP_Priv)
: string.Empty
}).ToList();

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

return (from groupSerializable in ((List<GroupInfoSerializable>)xmlSerializer.Deserialize(stream))!
let profiles = groupSerializable.Profiles.Select(profileSerializable => new ProfileInfo(profileSerializable)
let profiles = groupSerializable.Profiles.Select(profileSerializable => new ProfileInfo(profileSerializable)
{
// Migrate old data
NetworkInterface_Subnetmask =
string.IsNullOrEmpty(profileSerializable.NetworkInterface_Subnetmask) &&
!string.IsNullOrEmpty(profileSerializable.NetworkInterface_SubnetmaskOrCidr)
? profileSerializable.NetworkInterface_SubnetmaskOrCidr
: profileSerializable.NetworkInterface_Subnetmask,
string.IsNullOrEmpty(profileSerializable.NetworkInterface_Subnetmask) &&
!string.IsNullOrEmpty(profileSerializable.NetworkInterface_SubnetmaskOrCidr)
? profileSerializable.NetworkInterface_SubnetmaskOrCidr
: profileSerializable.NetworkInterface_Subnetmask,

// Convert passwords to secure strings
RemoteDesktop_Password = !string.IsNullOrEmpty(profileSerializable.RemoteDesktop_Password)
? SecureStringHelper.ConvertToSecureString(profileSerializable.RemoteDesktop_Password)
: null,
RemoteDesktop_GatewayServerPassword =
!string.IsNullOrEmpty(profileSerializable.RemoteDesktop_GatewayServerPassword)
? SecureStringHelper.ConvertToSecureString(profileSerializable
.RemoteDesktop_GatewayServerPassword)
? SecureStringHelper.ConvertToSecureString(profileSerializable.RemoteDesktop_Password)
: null,
RemoteDesktop_GatewayServerPassword =
!string.IsNullOrEmpty(profileSerializable.RemoteDesktop_GatewayServerPassword)
? SecureStringHelper.ConvertToSecureString(profileSerializable
.RemoteDesktop_GatewayServerPassword)
: null,
SNMP_Community = !string.IsNullOrEmpty(profileSerializable.SNMP_Community)
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Community)
: null,
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Community)
: null,
SNMP_Auth = !string.IsNullOrEmpty(profileSerializable.SNMP_Auth)
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Auth)
: null,
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Auth)
: null,
SNMP_Priv = !string.IsNullOrEmpty(profileSerializable.SNMP_Priv)
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Priv)
: null
? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Priv)
: null
})
.ToList()
select new GroupInfo(groupSerializable)
{
Profiles = profiles,

// Convert passwords to secure strings
RemoteDesktop_Password = !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_Password)
? SecureStringHelper.ConvertToSecureString(groupSerializable.RemoteDesktop_Password)
: null,
RemoteDesktop_GatewayServerPassword =
!string.IsNullOrEmpty(groupSerializable.RemoteDesktop_GatewayServerPassword)
? SecureStringHelper.ConvertToSecureString(
groupSerializable.RemoteDesktop_GatewayServerPassword)
.ToList()
select new GroupInfo(groupSerializable)
{
Profiles = profiles,

// Convert passwords to secure strings
RemoteDesktop_Password = !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_Password)
? SecureStringHelper.ConvertToSecureString(groupSerializable.RemoteDesktop_Password)
: null,
SNMP_Community = !string.IsNullOrEmpty(groupSerializable.SNMP_Community)
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Community)
: null,
SNMP_Auth = !string.IsNullOrEmpty(groupSerializable.SNMP_Auth)
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Auth)
: null,
SNMP_Priv = !string.IsNullOrEmpty(groupSerializable.SNMP_Priv)
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Priv)
: null
}).ToList();
RemoteDesktop_GatewayServerPassword =
!string.IsNullOrEmpty(groupSerializable.RemoteDesktop_GatewayServerPassword)
? SecureStringHelper.ConvertToSecureString(
groupSerializable.RemoteDesktop_GatewayServerPassword)
: null,
SNMP_Community = !string.IsNullOrEmpty(groupSerializable.SNMP_Community)
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Community)
: null,
SNMP_Auth = !string.IsNullOrEmpty(groupSerializable.SNMP_Auth)
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Auth)
: null,
SNMP_Priv = !string.IsNullOrEmpty(groupSerializable.SNMP_Priv)
? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Priv)
: null
}).ToList();
}

#endregion
Expand Down Expand Up @@ -741,7 +741,7 @@ public static void AddGroup(GroupInfo group)
/// </summary>
/// <param name="name">Name of the group.</param>
/// <returns>Group as <see cref="GroupInfo" />.</returns>
public static GroupInfo GetGroup(string name)
public static GroupInfo GetGroupByName(string name)
{
return Groups.First(x => x.Name.Equals(name));
}
Expand Down
92 changes: 46 additions & 46 deletions Source/NETworkManager/ProfileDialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,6 @@ public static Task ShowAddProfileDialog(Window parentWindow, IProfileManagerMini
ProfileManager.AddProfile(ParseProfileInfo(instance));
}, _ =>
{
Debug.WriteLine("Profile dialog closed without saving");

childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

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

#region Dialog to add, edit and delete group

public static Task ShowAddGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator)
public static Task ShowAddGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel)
{
CustomDialog customDialog = new()
{
Title = Strings.AddGroup,
Style = (Style)Application.Current.FindResource(DialogResourceKey)
};

GroupViewModel groupViewModel = new(async instance =>
var childWindow = new GroupChildWindow(parentWindow);

GroupViewModel childWindowViewModel = new(instance =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.AddGroup(ParseGroupInfo(instance));
}, async _ =>
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
}, ProfileManager.GetGroupNames());

customDialog.Content = new GroupDialog
{
DataContext = groupViewModel
};


childWindow.Title = Strings.AddGroup;

childWindow.DataContext = childWindowViewModel;

viewModel.OnProfileManagerDialogOpen();

return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return parentWindow.ShowChildWindowAsync(childWindow);
}

public static Task ShowEditGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator,
public static Task ShowEditGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel,
GroupInfo group)
{
CustomDialog customDialog = new()
{
Title = Strings.EditGroup,
Style = (Style)Application.Current.FindResource(DialogResourceKey)
};

GroupViewModel groupViewModel = new(async instance =>
var childWindow = new GroupChildWindow(parentWindow);

GroupViewModel childWindowViewModel = new(instance =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.ReplaceGroup(instance.Group, ParseGroupInfo(instance));
}, async _ =>
ProfileManager.ReplaceGroup(group, ParseGroupInfo(instance));
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
}, ProfileManager.GetGroupNames(), GroupEditMode.Edit, group);

customDialog.Content = new GroupDialog
{
DataContext = groupViewModel
};


childWindow.Title = Strings.EditGroup;

childWindow.DataContext = childWindowViewModel;

viewModel.OnProfileManagerDialogOpen();

return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return parentWindow.ShowChildWindowAsync(childWindow);
}

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

viewModel.OnProfileManagerDialogClose();
}, Strings.DeleteGroupMessage);

childWindow.Title = Strings.DeleteGroup;

childWindow.DataContext = childWindowViewModel;

viewModel.OnProfileManagerDialogOpen();

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return parentWindow.ShowChildWindowAsync(childWindow);
Expand Down
Loading