Changeset 332 for binary-improvements/MapRendering/Web/WebPermissions.cs
- Timestamp:
- Nov 16, 2018, 10:38:46 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/WebPermissions.cs
r326 r332 1 1 using System.Collections.Generic; 2 using System.Collections.ObjectModel; 2 3 using System.IO; 3 4 using System.Xml; 5 using UniLinq; 4 6 5 7 namespace AllocsFixes.NetConnections.Servers.Web { … … 10 12 11 13 private readonly Dictionary<string, WebModulePermission> knownModules = 12 new Dictionary<string,WebModulePermission> ();14 new CaseInsensitiveStringDictionary<WebModulePermission> (); 13 15 14 16 private readonly Dictionary<string, AdminToken> admintokens = new CaseInsensitiveStringDictionary<AdminToken> (); … … 18 20 19 21 public WebPermissions () { 22 allModulesList = new List<WebModulePermission> (); 23 allModulesListRO = new ReadOnlyCollection<WebModulePermission> (allModulesList); 20 24 Directory.CreateDirectory (GetFilePath ()); 21 25 InitFileWatcher (); … … 54 58 } 55 59 60 if (knownModules.TryGetValue (_module, out result)) { 61 return result; 62 } 63 56 64 return defaultModulePermission; 57 65 } … … 93 101 WebModulePermission p = new WebModulePermission (_module, _permissionLevel); 94 102 lock (this) { 103 allModulesList.Clear (); 95 104 modules [_module] = p; 96 105 if (_save) { … … 104 113 return; 105 114 } 106 107 lock (this) { 108 if (!IsKnownModule (_module)) { 109 knownModules.Add (_module, new WebModulePermission (_module, _defaultPermission)); 110 } 111 112 if (_defaultPermission > 0 && !modules.ContainsKey (_module)) { 113 AddModulePermission (_module, _defaultPermission); 114 } 115 116 WebModulePermission p = new WebModulePermission (_module, _defaultPermission); 117 118 lock (this) { 119 allModulesList.Clear (); 120 knownModules [_module] = p; 115 121 } 116 122 } … … 129 135 public void RemoveModulePermission (string _module, bool _save = true) { 130 136 lock (this) { 137 allModulesList.Clear (); 131 138 modules.Remove (_module); 132 139 if (_save) { … … 136 143 } 137 144 138 public List<WebModulePermission> GetModules () { 139 List<WebModulePermission> result = new List<WebModulePermission> (); 140 foreach (string module in knownModules.Keys) { 141 if (modules.ContainsKey (module)) { 142 result.Add (modules [module]); 143 } else { 144 result.Add (knownModules [module]); 145 } 146 } 147 148 return result; 145 private readonly List<WebModulePermission> allModulesList; 146 private readonly ReadOnlyCollection<WebModulePermission> allModulesListRO; 147 148 public IList<WebModulePermission> GetModules () { 149 if (allModulesList.Count == 0) { 150 foreach (KeyValuePair<string, WebModulePermission> kvp in knownModules) { 151 if (modules.ContainsKey (kvp.Key)) { 152 allModulesList.Add (modules [kvp.Key]); 153 } else { 154 allModulesList.Add (kvp.Value); 155 } 156 } 157 } 158 159 return allModulesListRO; 149 160 } 150 161 … … 302 313 sw.WriteLine ( 303 314 " <!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->"); 304 foreach ( AdminToken at in admintokens.Values) {305 sw.WriteLine (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token,306 at.permissionLevel);315 foreach (KeyValuePair<string, AdminToken> kvp in admintokens) { 316 sw.WriteLine (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", kvp.Value.name, 317 kvp.Value.token, kvp.Value.permissionLevel); 307 318 } 308 319 … … 310 321 sw.WriteLine (); 311 322 sw.WriteLine (" <permissions>"); 312 foreach ( WebModulePermission wap in modules.Values) {313 sw.WriteLine (" <permission module=\"{0}\" permission_level=\"{1}\" />", wap.module,314 wap.permissionLevel);323 foreach (KeyValuePair<string, WebModulePermission> kvp in modules) { 324 sw.WriteLine (" <permission module=\"{0}\" permission_level=\"{1}\" />", kvp.Value.module, 325 kvp.Value.permissionLevel); 315 326 } 316 327
Note:
See TracChangeset
for help on using the changeset viewer.