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

Last change on this file since 251 was 250, checked in by alloc, 10 years ago

Fixes 5_7_9

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