Ignore:
Timestamp:
Aug 6, 2022, 11:32:32 PM (2 years ago)
Author:
alloc
Message:

Big refactoring in Web to pass around a Context instead of a bunch of individual arguments all the time

File:
1 edited

Legend:

Unmodified
Added
Removed
  • binary-improvements2/MapRendering/Web/API/GetLog.cs

    r383 r387  
    11using System.Collections.Generic;
    22using AllocsFixes.JSON;
    3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
    4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
    53
    64namespace AllocsFixes.NetConnections.Servers.Web.API {
    7         public class GetLog : WebAPI {
     5        public class GetLog : AbsWebAPI {
    86                private const int MAX_COUNT = 1000;
    97               
    10                 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
    11                         int _permissionLevel) {
    12                         if (_req.QueryString ["count"] == null || !int.TryParse (_req.QueryString ["count"], out int count)) {
     8                public override void HandleRequest (RequestContext _context) {
     9                        if (_context.Request.QueryString ["count"] == null || !int.TryParse (_context.Request.QueryString ["count"], out int count)) {
    1310                                count = 50;
    1411                        }
     
    2623                        }
    2724
    28                         if (_req.QueryString ["firstLine"] == null || !int.TryParse (_req.QueryString ["firstLine"], out int firstLine)) {
     25                        if (_context.Request.QueryString ["firstLine"] == null || !int.TryParse (_context.Request.QueryString ["firstLine"], out int firstLine)) {
    2926                                firstLine = count > 0 ? LogBuffer.Instance.OldestLine : LogBuffer.Instance.LatestLine;
    3027                        }
     
    3734                        foreach (LogBuffer.LogEntry logEntry in logEntries) {
    3835                                JSONObject entry = new JSONObject ();
    39                                 entry.Add ("date", new JSONString (logEntry.date));
    40                                 entry.Add ("time", new JSONString (logEntry.time));
    4136                                entry.Add ("isotime", new JSONString (logEntry.isoTime));
    4237                                entry.Add ("uptime", new JSONString (logEntry.uptime.ToString ()));
     
    5146                        result.Add ("entries", entries);
    5247
    53                         WriteJSON (_resp, result);
     48                        WebUtils.WriteJson (_context.Response, result);
    5449                }
    5550        }
Note: See TracChangeset for help on using the changeset viewer.