Changeset 454 for binary-improvements/MapRendering/API/GetLog.cs
- Timestamp:
- Jul 28, 2023, 8:42:10 PM (16 months ago)
- Location:
- binary-improvements/MapRendering/API
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetLog.cs
r453 r454 1 1 using System.Collections.Generic; 2 using System.Net;3 2 using AllocsFixes.JSON; 3 using Webserver; 4 using Webserver.WebAPI; 4 5 5 namespace AllocsFixes. NetConnections.Servers.Web.API{6 public class GetLog : WebAPI {6 namespace AllocsFixes.WebAPIs { 7 public class GetLog : AbsWebAPI { 7 8 private const int MAX_COUNT = 1000; 8 9 9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 10 int _permissionLevel) { 11 int count, firstLine, lastLine; 12 13 if (_req.QueryString ["count"] == null || !int.TryParse (_req.QueryString ["count"], out count)) { 10 public override void HandleRequest (RequestContext _context) { 11 if (_context.Request.QueryString ["count"] == null || !int.TryParse (_context.Request.QueryString ["count"], out var count)) { 14 12 count = 50; 15 13 } … … 27 25 } 28 26 29 if (_ req.QueryString ["firstLine"] == null || !int.TryParse (_req.QueryString ["firstLine"], outfirstLine)) {27 if (_context.Request.QueryString ["firstLine"] == null || !int.TryParse (_context.Request.QueryString ["firstLine"], out var firstLine)) { 30 28 if (count > 0) { 31 29 firstLine = LogBuffer.Instance.OldestLine; … … 37 35 JSONObject result = new JSONObject (); 38 36 39 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, count, out lastLine);37 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, count, out var lastLine); 40 38 41 39 JSONArray entries = new JSONArray (); 42 40 foreach (LogBuffer.LogEntry logEntry in logEntries) { 43 41 JSONObject entry = new JSONObject (); 44 entry.Add ("date", new JSONString (logEntry.date)); 45 entry.Add ("time", new JSONString (logEntry.time)); 46 entry.Add ("uptime", new JSONString (logEntry.uptime)); 47 entry.Add ("msg", new JSONString (logEntry.message)); 48 entry.Add ("trace", new JSONString (logEntry.trace)); 49 entry.Add ("type", new JSONString (logEntry.type.ToStringCached ())); 42 var logEntryTimestamp = logEntry.Timestamp; 43 entry.Add ("date", new JSONString ($"{logEntryTimestamp.Year:0000}-{logEntryTimestamp.Month:00}-{logEntryTimestamp.Day:00}")); 44 entry.Add ("time", new JSONString ($"{logEntryTimestamp.Hour:00}:{logEntryTimestamp.Minute:00}:{logEntryTimestamp.Second:00}")); 45 entry.Add ("uptime", new JSONString (logEntry.Uptime.ToString())); 46 entry.Add ("msg", new JSONString (logEntry.Message)); 47 entry.Add ("trace", new JSONString (logEntry.Trace)); 48 entry.Add ("type", new JSONString (logEntry.Type.ToStringCached ())); 50 49 entries.Add (entry); 51 50 } … … 55 54 result.Add ("entries", entries); 56 55 57 WriteJSON (_resp, result);56 LegacyApiHelper.WriteJSON (_context.Response, result); 58 57 } 59 58 }
Note:
See TracChangeset
for help on using the changeset viewer.