mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-23 01:15:03 +00:00
* changed path for DevJson to include the device key instead of requiring it in the body * Made the `GetRequestBody` method an extension method for the `HttpCwsRequest` class
84 lines
2.1 KiB
C#
84 lines
2.1 KiB
C#
using Crestron.SimplSharp.WebScripting;
|
|
using Newtonsoft.Json;
|
|
using PepperDash.Core;
|
|
using PepperDash.Core.Web.RequestHandlers;
|
|
|
|
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|
{
|
|
public class DoNotLoadConfigOnNextBootRequestHandler : WebApiBaseRequestHandler
|
|
{
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// base(true) enables CORS support by default
|
|
/// </remarks>
|
|
public DoNotLoadConfigOnNextBootRequestHandler()
|
|
: base(true)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles GET method requests
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
protected override void HandleGet(HttpCwsContext context)
|
|
{
|
|
var data = new Data
|
|
{
|
|
DoNotLoadConfigOnNextBoot = Debug.DoNotLoadConfigOnNextBoot
|
|
};
|
|
|
|
var body = JsonConvert.SerializeObject(data, Formatting.Indented);
|
|
|
|
context.Response.StatusCode = 200;
|
|
context.Response.StatusDescription = "OK";
|
|
context.Response.Write(body, false);
|
|
context.Response.End();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles POST method requests
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
protected override void HandlePost(HttpCwsContext context)
|
|
{
|
|
if (context.Request.ContentLength < 0)
|
|
{
|
|
context.Response.StatusCode = 400;
|
|
context.Response.StatusDescription = "Bad Request";
|
|
context.Response.End();
|
|
|
|
return;
|
|
}
|
|
|
|
var data = context.Request.GetRequestBody();
|
|
if (string.IsNullOrEmpty(data))
|
|
{
|
|
context.Response.StatusCode = 400;
|
|
context.Response.StatusDescription = "Bad Request";
|
|
context.Response.End();
|
|
|
|
return;
|
|
}
|
|
|
|
var d = new Data();
|
|
var requestBody = JsonConvert.DeserializeAnonymousType(data, d);
|
|
|
|
Debug.SetDoNotLoadConfigOnNextBoot(requestBody.DoNotLoadConfigOnNextBoot);
|
|
|
|
var responseBody = JsonConvert.SerializeObject(d, Formatting.Indented);
|
|
|
|
context.Response.StatusCode = 200;
|
|
context.Response.StatusDescription = "OK";
|
|
context.Response.Write(responseBody, false);
|
|
context.Response.End();
|
|
}
|
|
}
|
|
|
|
public class Data
|
|
{
|
|
[JsonProperty("doNotLoadConfigOnNextBoot", NullValueHandling = NullValueHandling.Ignore)]
|
|
public bool DoNotLoadConfigOnNextBoot { get; set; }
|
|
}
|
|
} |