Changeset 326 for binary-improvements/MapRendering/Web/WebPermissions.cs
- Timestamp:
- Sep 4, 2018, 2:33:52 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/WebPermissions.cs
r325 r326 12 12 new Dictionary<string, WebModulePermission> (); 13 13 14 private Dictionary<string, AdminToken> admintokens;14 private readonly Dictionary<string, AdminToken> admintokens = new CaseInsensitiveStringDictionary<AdminToken> (); 15 15 private FileSystemWatcher fileWatcher; 16 16 17 private Dictionary<string, WebModulePermission> modules;17 private readonly Dictionary<string, WebModulePermission> modules = new CaseInsensitiveStringDictionary<WebModulePermission> (); 18 18 19 19 public WebPermissions () { … … 49 49 50 50 public WebModulePermission GetModulePermission (string _module) { 51 if (modules.ContainsKey (_module.ToLower ())) { 52 return modules [_module.ToLower ()]; 51 WebModulePermission result; 52 if (modules.TryGetValue (_module, out result)) { 53 return result; 53 54 } 54 55 … … 83 84 public AdminToken[] GetAdmins () { 84 85 AdminToken[] result = new AdminToken[admintokens.Count]; 85 admintokens. Values.CopyTo (result, 0);86 admintokens.CopyValuesTo (result); 86 87 return result; 87 88 } … … 90 91 // Commands 91 92 public void AddModulePermission (string _module, int _permissionLevel, bool _save = true) { 92 WebModulePermission p = new WebModulePermission (_module .ToLower (), _permissionLevel);93 WebModulePermission p = new WebModulePermission (_module, _permissionLevel); 93 94 lock (this) { 94 95 modules [_module] = p; … … 100 101 101 102 public void AddKnownModule (string _module, int _defaultPermission) { 102 if (!string.IsNullOrEmpty (_module)) { 103 lock (this) { 104 if (!IsKnownModule (_module)) { 105 knownModules.Add (_module, new WebModulePermission (_module, _defaultPermission)); 106 } 107 108 if (_defaultPermission > 0 && !modules.ContainsKey (_module.ToLower ())) { 109 AddModulePermission (_module, _defaultPermission); 110 } 103 if (string.IsNullOrEmpty (_module)) { 104 return; 105 } 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); 111 114 } 112 115 } … … 114 117 115 118 public bool IsKnownModule (string _module) { 116 if (!string.IsNullOrEmpty (_module)) { 117 lock (this) { 118 return knownModules.ContainsKey (_module); 119 } 120 } 121 122 return false; 119 if (string.IsNullOrEmpty (_module)) { 120 return false; 121 } 122 123 lock (this) { 124 return knownModules.ContainsKey (_module); 125 } 126 123 127 } 124 128 125 129 public void RemoveModulePermission (string _module, bool _save = true) { 126 130 lock (this) { 127 modules.Remove (_module .ToLower ());131 modules.Remove (_module); 128 132 if (_save) { 129 133 Save (); … … 174 178 175 179 public void Load () { 176 admintokens = new Dictionary<string, AdminToken>();177 modules = new Dictionary<string, WebModulePermission>();180 admintokens.Clear (); 181 modules.Clear (); 178 182 179 183 if (!Utils.FileExists (GetFullPath ())) { … … 190 194 xmlDoc.Load (GetFullPath ()); 191 195 } catch (XmlException e) { 192 Log.Error ( string.Format ("Failed loading permissions file: {0}", e.Message));196 Log.Error ("Failed loading permissions file: " + e.Message); 193 197 return; 194 198 } … … 196 200 XmlNode adminToolsNode = xmlDoc.DocumentElement; 197 201 202 if (adminToolsNode == null) { 203 Log.Error ("Failed loading permissions file: No DocumentElement found"); 204 return; 205 } 206 198 207 foreach (XmlNode childNode in adminToolsNode.ChildNodes) { 199 208 if (childNode.Name == "admintokens") { … … 230 239 string name = lineItem.GetAttribute ("name"); 231 240 string token = lineItem.GetAttribute ("token"); 232 int permissionLevel = 2000;241 int permissionLevel; 233 242 if (!int.TryParse (lineItem.GetAttribute ("permission_level"), out permissionLevel)) { 234 243 Log.Warning ( … … 267 276 } 268 277 269 int permissionLevel = 0;278 int permissionLevel; 270 279 if (!int.TryParse (lineItem.GetAttribute ("permission_level"), out permissionLevel)) { 271 280 Log.Warning ( … … 275 284 } 276 285 277 AddModulePermission (lineItem.GetAttribute ("module") .ToLower (), permissionLevel, false);286 AddModulePermission (lineItem.GetAttribute ("module"), permissionLevel, false); 278 287 } 279 288 }
Note:
See TracChangeset
for help on using the changeset viewer.