source: binary-improvements/MapRendering/Web/API/GetLog.cs@ 332

Last change on this file since 332 was 325, checked in by alloc, 6 years ago

Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)

File size: 1.3 KB
RevLine 
[250]1using System.Collections.Generic;
2using System.Net;
[325]3using AllocsFixes.JSON;
[250]4
[325]5namespace AllocsFixes.NetConnections.Servers.Web.API {
[250]6 public class GetLog : WebAPI {
[325]7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
8 int permissionLevel) {
[250]9 int firstLine, lastLine;
10
11 if (req.QueryString ["firstLine"] == null || !int.TryParse (req.QueryString ["firstLine"], out firstLine)) {
12 firstLine = LogBuffer.Instance.OldestLine;
13 }
14
15 JSONObject result = new JSONObject ();
16
[253]17 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, 50, out lastLine);
[250]18
19 JSONArray entries = new JSONArray ();
20 foreach (LogBuffer.LogEntry logEntry in logEntries) {
21 JSONObject entry = new JSONObject ();
22 entry.Add ("date", new JSONString (logEntry.date));
23 entry.Add ("time", new JSONString (logEntry.time));
24 entry.Add ("uptime", new JSONString (logEntry.uptime));
25 entry.Add ("msg", new JSONString (logEntry.message));
26 entry.Add ("trace", new JSONString (logEntry.trace));
27 entry.Add ("type", new JSONString (logEntry.type.ToString ()));
28 entries.Add (entry);
29 }
30
31 result.Add ("firstLine", new JSONNumber (firstLine));
32 result.Add ("lastLine", new JSONNumber (lastLine));
33 result.Add ("entries", entries);
34
35 WriteJSON (resp, result);
36 }
37 }
[325]38}
Note: See TracBrowser for help on using the repository browser.