Changeset 372 for binary-improvements/MapRendering/Web
- Timestamp:
- Jul 27, 2022, 7:17:17 PM (2 years ago)
- Location:
- binary-improvements/MapRendering/Web
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/Handlers/PathHandler.cs
r367 r372 12 12 } 13 13 14 public string ModuleName { 15 get { return moduleName; } 16 } 14 public string ModuleName => moduleName; 17 15 18 16 public abstract void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 19 17 int _permissionLevel); 20 18 21 public bool IsAuthorizedForHandler (WebConnection _user, int _permissionLevel) { 22 if (moduleName != null) { 23 return WebPermissions.Instance.ModuleAllowedWithLevel (moduleName, _permissionLevel); 24 } 25 26 return true; 19 public virtual bool IsAuthorizedForHandler (WebConnection _user, int _permissionLevel) { 20 return moduleName == null || WebPermissions.Instance.ModuleAllowedWithLevel (moduleName, _permissionLevel); 27 21 } 28 22 -
binary-improvements/MapRendering/Web/SSE/EventBase.cs
r367 r372 55 55 stringBuilder.Append ("data: "); 56 56 57 if (data is string dataString) { 58 stringBuilder.AppendLine (dataString); 59 } else if (data is JSONNode dataJson) { 60 dataJson.ToString (stringBuilder); 61 stringBuilder.AppendLine (""); 62 } else { 63 Log.Error ($"SSE ({Name}): Data is neither string nor JSON."); 64 continue; 57 switch (data) { 58 case string dataString: 59 stringBuilder.AppendLine (dataString); 60 break; 61 case JSONNode dataJson: 62 dataJson.ToString (stringBuilder); 63 stringBuilder.AppendLine (""); 64 break; 65 default: 66 logError ("Data is neither string nor JSON.", false); 67 continue; 65 68 } 66 69 … … 76 79 bytesToSend = Encoding.UTF8.GetBytes (output, 0, output.Length, buf, 0); 77 80 } catch (ArgumentException e) { 78 Log.Error ($"SSE ({Name}): Exception while encoding data for output, most likely exceeding buffer size:");81 logError ("Exception while encoding data for output, most likely exceeding buffer size:", false); 79 82 Log.Exception (e); 80 83 return; … … 95 98 totalClosed++; 96 99 97 Log.Out ( 98 $"SSE ({Name}): Can not write to endpoint, closing. (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 100 logError ("Can not write to endpoint, closing", true); 99 101 openStreams.RemoveAt (i); 100 102 resp.Close (); … … 107 109 108 110 if (e.InnerException is SocketException se) { 109 if (se.SocketErrorCode != SocketError.ConnectionAborted ) {110 Log.Error ($"SSE ({Name}): SocketError ({se.SocketErrorCode}) while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}");111 if (se.SocketErrorCode != SocketError.ConnectionAborted && se.SocketErrorCode != SocketError.Shutdown) { 112 logError ($"SocketError ({se.SocketErrorCode}) while trying to write", true); 111 113 } 112 114 } else { 113 Log.Error ( 114 $"SSE ({Name}): IOException while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 115 logError ("IOException while trying to write:", true); 115 116 Log.Exception (e); 116 117 } … … 122 123 123 124 openStreams.RemoveAt (i); 124 Log.Error ( 125 $"SSE ({Name}): Exception while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 125 logError ("Exception while trying to write:", true); 126 126 Log.Exception (e); 127 127 resp.Close (); … … 131 131 } 132 132 133 protected void logError (string _message, bool _printConnections) { 134 Log.Error (_printConnections 135 ? $"SSE ({Name}): {_message} (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed})" 136 : $"SSE ({Name}): {_message}"); 137 } 138 133 139 public virtual int DefaultPermissionLevel () { 134 140 return 0; -
binary-improvements/MapRendering/Web/WebPermissions.cs
r369 r372 18 18 private readonly Dictionary<string, WebModulePermission> modules = new CaseInsensitiveStringDictionary<WebModulePermission> (); 19 19 20 p ublicWebPermissions () {20 private WebPermissions () { 21 21 allModulesList = new List<WebModulePermission> (); 22 22 allModulesListRO = new ReadOnlyCollection<WebModulePermission> (allModulesList); … … 29 29 get { 30 30 lock (typeof (WebPermissions)) { 31 if (instance == null) { 32 instance = new WebPermissions (); 33 } 34 35 return instance; 31 return instance ?? (instance = new WebPermissions ()); 36 32 } 37 33 } … … 52 48 53 49 public WebModulePermission GetModulePermission (string _module) { 54 WebModulePermission result; 55 if (modules.TryGetValue (_module, out result)) { 50 if (modules.TryGetValue (_module, out WebModulePermission result)) { 56 51 return result; 57 52 } … … 192 187 193 188 if (!File.Exists (GetFullPath ())) { 194 Log.Out ( string.Format ("Permissions file '{0}' not found, creating.", GetFileName ()));189 Log.Out ($"Permissions file '{GetFileName ()}' not found, creating."); 195 190 Save (); 196 191 return; 197 192 } 198 193 199 Log.Out ( string.Format ("Loading permissions file at '{0}'", GetFullPath ()));194 Log.Out ($"Loading permissions file at '{GetFullPath ()}'"); 200 195 201 196 XmlDocument xmlDoc = new XmlDocument ();
Note:
See TracChangeset
for help on using the changeset viewer.