Skip to content

Commit 1598368

Browse files
committed
Feature: Refactor ProfileManager to add properties to a ProfileFile
1 parent 9b4ed37 commit 1598368

File tree

106 files changed

+513
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+513
-384
lines changed

Source/NETworkManager.Profiles/ProfileFileData.cs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.Linq;
45
using System.Runtime.CompilerServices;
56
using System.Text.Json.Serialization;
67

@@ -76,7 +77,99 @@ public DateTime? LastBackup
7677
}
7778

7879
/// <summary>
79-
/// List of groups containing profiles.
80+
/// Working copy of groups containing profiles (runtime objects with SecureString passwords).
81+
/// This is the single source of truth for profile data in memory.
82+
/// Not serialized directly - use <see cref="GroupsSerializable"/> for JSON serialization.
8083
/// </summary>
81-
public List<GroupInfoSerializable> Groups { get; set; } = [];
84+
[JsonIgnore]
85+
public List<GroupInfo> Groups { get; set; } = [];
86+
87+
/// <summary>
88+
/// Serializable representation of groups for JSON persistence.
89+
/// Gets: Converts working Groups to serializable format.
90+
/// Sets: Converts deserialized data back to working Groups.
91+
/// </summary>
92+
[JsonPropertyName("Groups")]
93+
public List<GroupInfoSerializable> GroupsSerializable
94+
{
95+
get => [.. Groups.Select(g => new GroupInfoSerializable(g)
96+
{
97+
Profiles = [.. g.Profiles.Where(p => !p.IsDynamic).Select(p => new ProfileInfoSerializable(p)
98+
{
99+
RemoteDesktop_Password = p.RemoteDesktop_Password != null
100+
? Utilities.SecureStringHelper.ConvertToString(p.RemoteDesktop_Password)
101+
: string.Empty,
102+
RemoteDesktop_GatewayServerPassword = p.RemoteDesktop_GatewayServerPassword != null
103+
? Utilities.SecureStringHelper.ConvertToString(p.RemoteDesktop_GatewayServerPassword)
104+
: string.Empty,
105+
SNMP_Community = p.SNMP_Community != null
106+
? Utilities.SecureStringHelper.ConvertToString(p.SNMP_Community)
107+
: string.Empty,
108+
SNMP_Auth = p.SNMP_Auth != null
109+
? Utilities.SecureStringHelper.ConvertToString(p.SNMP_Auth)
110+
: string.Empty,
111+
SNMP_Priv = p.SNMP_Priv != null
112+
? Utilities.SecureStringHelper.ConvertToString(p.SNMP_Priv)
113+
: string.Empty
114+
})],
115+
RemoteDesktop_Password = g.RemoteDesktop_Password != null
116+
? Utilities.SecureStringHelper.ConvertToString(g.RemoteDesktop_Password)
117+
: string.Empty,
118+
RemoteDesktop_GatewayServerPassword = g.RemoteDesktop_GatewayServerPassword != null
119+
? Utilities.SecureStringHelper.ConvertToString(g.RemoteDesktop_GatewayServerPassword)
120+
: string.Empty,
121+
SNMP_Community = g.SNMP_Community != null
122+
? Utilities.SecureStringHelper.ConvertToString(g.SNMP_Community)
123+
: string.Empty,
124+
SNMP_Auth = g.SNMP_Auth != null
125+
? Utilities.SecureStringHelper.ConvertToString(g.SNMP_Auth)
126+
: string.Empty,
127+
SNMP_Priv = g.SNMP_Priv != null
128+
? Utilities.SecureStringHelper.ConvertToString(g.SNMP_Priv)
129+
: string.Empty
130+
}).Where(g => !g.IsDynamic)];
131+
132+
set
133+
{
134+
Groups = value?.Select(gs => new GroupInfo(gs)
135+
{
136+
Profiles = [.. (gs.Profiles ?? []).Select(ps => new ProfileInfo(ps)
137+
{
138+
TagsCollection = (ps.TagsCollection == null || ps.TagsCollection.Count == 0) && !string.IsNullOrEmpty(ps.Tags)
139+
? new Controls.ObservableSetCollection<string>(ps.Tags.Split([';'], StringSplitOptions.RemoveEmptyEntries))
140+
: ps.TagsCollection,
141+
RemoteDesktop_Password = !string.IsNullOrEmpty(ps.RemoteDesktop_Password)
142+
? Utilities.SecureStringHelper.ConvertToSecureString(ps.RemoteDesktop_Password)
143+
: null,
144+
RemoteDesktop_GatewayServerPassword = !string.IsNullOrEmpty(ps.RemoteDesktop_GatewayServerPassword)
145+
? Utilities.SecureStringHelper.ConvertToSecureString(ps.RemoteDesktop_GatewayServerPassword)
146+
: null,
147+
SNMP_Community = !string.IsNullOrEmpty(ps.SNMP_Community)
148+
? Utilities.SecureStringHelper.ConvertToSecureString(ps.SNMP_Community)
149+
: null,
150+
SNMP_Auth = !string.IsNullOrEmpty(ps.SNMP_Auth)
151+
? Utilities.SecureStringHelper.ConvertToSecureString(ps.SNMP_Auth)
152+
: null,
153+
SNMP_Priv = !string.IsNullOrEmpty(ps.SNMP_Priv)
154+
? Utilities.SecureStringHelper.ConvertToSecureString(ps.SNMP_Priv)
155+
: null
156+
})],
157+
RemoteDesktop_Password = !string.IsNullOrEmpty(gs.RemoteDesktop_Password)
158+
? Utilities.SecureStringHelper.ConvertToSecureString(gs.RemoteDesktop_Password)
159+
: null,
160+
RemoteDesktop_GatewayServerPassword = !string.IsNullOrEmpty(gs.RemoteDesktop_GatewayServerPassword)
161+
? Utilities.SecureStringHelper.ConvertToSecureString(gs.RemoteDesktop_GatewayServerPassword)
162+
: null,
163+
SNMP_Community = !string.IsNullOrEmpty(gs.SNMP_Community)
164+
? Utilities.SecureStringHelper.ConvertToSecureString(gs.SNMP_Community)
165+
: null,
166+
SNMP_Auth = !string.IsNullOrEmpty(gs.SNMP_Auth)
167+
? Utilities.SecureStringHelper.ConvertToSecureString(gs.SNMP_Auth)
168+
: null,
169+
SNMP_Priv = !string.IsNullOrEmpty(gs.SNMP_Priv)
170+
? Utilities.SecureStringHelper.ConvertToSecureString(gs.SNMP_Priv)
171+
: null
172+
}).ToList() ?? [];
173+
}
174+
}
82175
}

Source/NETworkManager.Profiles/ProfileInfoSerializable.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
public class ProfileInfoSerializable : ProfileInfo
44
{
5+
/// <summary>
6+
/// Initializes a new instance of the <see cref="ProfileInfoSerializable"/> class.
7+
/// </summary>
58
public ProfileInfoSerializable()
69
{
10+
711
}
812

13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="ProfileInfoSerializable"/> class using the specified profile information.
15+
/// </summary>
16+
/// <param name="profile">The <see cref="ProfileInfo" /> object that contains the profile data to be serialized. Cannot be null.</param>
917
public ProfileInfoSerializable(ProfileInfo profile) : base(profile)
1018
{
19+
1120
}
1221

1322
/// <summary>

0 commit comments

Comments
 (0)