|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.ComponentModel; |
| 4 | +using System.Linq; |
4 | 5 | using System.Runtime.CompilerServices; |
5 | 6 | using System.Text.Json.Serialization; |
6 | 7 |
|
@@ -76,7 +77,99 @@ public DateTime? LastBackup |
76 | 77 | } |
77 | 78 |
|
78 | 79 | /// <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. |
80 | 83 | /// </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 | + } |
82 | 175 | } |
0 commit comments