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

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

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

File size: 1.3 KB
Line 
1using System.Collections.Generic;
2using System.Net;
3using AllocsFixes.JSON;
4
5namespace AllocsFixes.NetConnections.Servers.Web.API {
6 public class GetLog : WebAPI {
7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
8 int permissionLevel) {
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
17 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, 50, out lastLine);
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 }
38}
Note: See TracBrowser for help on using the repository browser.