Changeset 350 for binary-improvements
- Timestamp:
- Jan 19, 2019, 6:08:32 PM (6 years ago)
- Location:
- binary-improvements/MapRendering/Web
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetLog.cs
r325 r350 5 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 6 public class GetLog : WebAPI { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 9 int firstLine, lastLine; 7 private const int MAX_COUNT = 1000; 8 9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 10 int _permissionLevel) { 11 int count, firstLine, lastLine; 10 12 11 if (req.QueryString ["firstLine"] == null || !int.TryParse (req.QueryString ["firstLine"], out firstLine)) { 12 firstLine = LogBuffer.Instance.OldestLine; 13 if (_req.QueryString ["count"] == null || !int.TryParse (_req.QueryString ["count"], out count)) { 14 count = 50; 15 } 16 17 if (count == 0) { 18 count = 1; 19 } 20 21 if (count > MAX_COUNT) { 22 count = MAX_COUNT; 23 } 24 25 if (count < -MAX_COUNT) { 26 count = -MAX_COUNT; 27 } 28 29 if (_req.QueryString ["firstLine"] == null || !int.TryParse (_req.QueryString ["firstLine"], out firstLine)) { 30 if (count > 0) { 31 firstLine = LogBuffer.Instance.OldestLine; 32 } else { 33 firstLine = LogBuffer.Instance.LatestLine; 34 } 13 35 } 14 36 15 37 JSONObject result = new JSONObject (); 16 38 17 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, 50, out lastLine);39 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, count, out lastLine); 18 40 19 41 JSONArray entries = new JSONArray (); … … 25 47 entry.Add ("msg", new JSONString (logEntry.message)); 26 48 entry.Add ("trace", new JSONString (logEntry.trace)); 27 entry.Add ("type", new JSONString (logEntry.type.ToString ()));49 entry.Add ("type", new JSONString (logEntry.type.ToStringCached ())); 28 50 entries.Add (entry); 29 51 } … … 33 55 result.Add ("entries", entries); 34 56 35 WriteJSON ( resp, result);57 WriteJSON (_resp, result); 36 58 } 37 59 } -
binary-improvements/MapRendering/Web/LogBuffer.cs
r326 r350 19 19 if (instance == null) { 20 20 instance = new LogBuffer (); 21 } ;21 } 22 22 } 23 23 … … 60 60 } 61 61 62 public LogEntry this [int index] {62 public LogEntry this [int _index] { 63 63 get { 64 64 lock (logEntries) { 65 if ( index >= listOffset &&index < listOffset + logEntries.Count) {66 return logEntries [ index];65 if (_index >= listOffset && _index < listOffset + logEntries.Count) { 66 return logEntries [_index]; 67 67 } 68 68 } … … 101 101 } 102 102 103 private readonly List<LogEntry> emptyList = new List<LogEntry> (); 104 103 105 public List<LogEntry> GetRange (ref int _start, int _count, out int _end) { 104 106 lock (logEntries) { 105 if (_count < 1) { 107 int index; 108 109 if (_count < 0) { 110 _count = -_count; 111 112 if (_start >= listOffset + logEntries.Count) { 113 _start = listOffset + logEntries.Count - 1; 114 } 115 106 116 _end = _start; 107 return new List<LogEntry> (); 117 118 if (_start < listOffset) { 119 return emptyList; 120 } 121 122 _start -= _count - 1; 123 124 if (_start < listOffset) { 125 _start = listOffset; 126 } 127 128 index = _start - listOffset; 129 _end += 1; 130 _count = _end - _start; 131 } else { 132 if (_start < listOffset) { 133 _start = listOffset; 134 } 135 136 if (_start >= listOffset + logEntries.Count) { 137 _end = _start; 138 return emptyList; 139 } 140 141 index = _start - listOffset; 142 143 if (index + _count > logEntries.Count) { 144 _count = logEntries.Count - index; 145 } 146 147 _end = _start + _count; 108 148 } 109 110 if (_start < listOffset) {111 _start = listOffset;112 }113 114 if (_start >= listOffset + logEntries.Count) {115 _end = _start;116 return new List<LogEntry> ();117 }118 119 int index = _start - listOffset;120 121 if (index + _count > logEntries.Count) {122 _count = logEntries.Count - index;123 }124 125 _end = _start + _count;126 149 127 150 return logEntries.GetRange (index, _count);
Note:
See TracChangeset
for help on using the changeset viewer.