mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 12:15:01 +00:00
feat: worked on adding get/post for appdebug, devprops, devjson, disableallstreamdebug, setdevicestreamdebug
This commit is contained in:
@@ -272,7 +272,7 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
Debug.Console(2, this,
|
Debug.Console(2, this,
|
||||||
@"Attempting to run action:
|
@"Attempting to run action:
|
||||||
DeviceKey: {0}
|
Key: {0}
|
||||||
MethodName: {1}
|
MethodName: {1}
|
||||||
Params: {2}"
|
Params: {2}"
|
||||||
, a.DeviceKey, a.MethodName, a.Params);
|
, a.DeviceKey, a.MethodName, a.Params);
|
||||||
|
|||||||
@@ -93,21 +93,31 @@ namespace PepperDash.Essentials.Core.Web
|
|||||||
Name = "DevList",
|
Name = "DevList",
|
||||||
RouteHandler = new DevListRequestHandler()
|
RouteHandler = new DevListRequestHandler()
|
||||||
},
|
},
|
||||||
new HttpCwsRoute("devprops/{key}")
|
new HttpCwsRoute("devprops")
|
||||||
{
|
{
|
||||||
Name = "DevProps",
|
Name = "DevProps",
|
||||||
RouteHandler = new DevPropsRequestHandler()
|
RouteHandler = new DevPropsRequestHandler()
|
||||||
},
|
},
|
||||||
|
//new HttpCwsRoute("devprops/{key}")
|
||||||
|
//{
|
||||||
|
// Name = "DevProps",
|
||||||
|
// RouteHandler = new DevPropsRequestHandler()
|
||||||
|
//},
|
||||||
new HttpCwsRoute("devjson")
|
new HttpCwsRoute("devjson")
|
||||||
{
|
{
|
||||||
Name = "DevJson",
|
Name = "DevJson",
|
||||||
RouteHandler = new DevJsonRequestHandler()
|
RouteHandler = new DevJsonRequestHandler()
|
||||||
},
|
},
|
||||||
new HttpCwsRoute("setdevicestreamdebug/{deviceKey}/{state}")
|
new HttpCwsRoute("setdevicestreamdebug")
|
||||||
{
|
{
|
||||||
Name = "SetDeviceStreamDebug",
|
Name = "SetDeviceStreamDebug",
|
||||||
RouteHandler = new SetDeviceStreamDebugRequestHandler()
|
RouteHandler = new SetDeviceStreamDebugRequestHandler()
|
||||||
},
|
},
|
||||||
|
//new HttpCwsRoute("setdevicestreamdebug/{deviceKey}/{state}")
|
||||||
|
//{
|
||||||
|
// Name = "SetDeviceStreamDebug",
|
||||||
|
// RouteHandler = new SetDeviceStreamDebugRequestHandler()
|
||||||
|
//},
|
||||||
new HttpCwsRoute("disableallstreamdebug")
|
new HttpCwsRoute("disableallstreamdebug")
|
||||||
{
|
{
|
||||||
Name = "DisableAllStreamDebug",
|
Name = "DisableAllStreamDebug",
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
using Crestron.SimplSharp.WebScripting;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp.WebScripting;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Core;
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||||
{
|
{
|
||||||
public class AppDebugRequestHandler : WebApiBaseRequestHandler
|
public class AppDebugRequestHandler : WebApiBaseRequestHandler
|
||||||
{
|
{
|
||||||
|
private const string Key = "AppDebugRequestHandler";
|
||||||
|
private const uint Trace = 0;
|
||||||
|
private const uint Info = 0;
|
||||||
|
private const uint Verbose = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles CONNECT method requests
|
/// Handles CONNECT method requests
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -33,8 +42,14 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
protected override void HandleGet(HttpCwsContext context)
|
protected override void HandleGet(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 501;
|
var o = new AppDebug();
|
||||||
context.Response.StatusDescription = "Not Implemented";
|
o.Level = Debug.Level;
|
||||||
|
|
||||||
|
var body = JsonConvert.SerializeObject(o, Formatting.Indented);
|
||||||
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.StatusDescription = "OK";
|
||||||
|
context.Response.Write(body, false);
|
||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +92,25 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
protected override void HandlePost(HttpCwsContext context)
|
protected override void HandlePost(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 501;
|
if (context.Request.ContentLength < 0) return;
|
||||||
context.Response.StatusDescription = "Not Implemented";
|
|
||||||
|
var bytes = new Byte[context.Request.ContentLength];
|
||||||
|
context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength);
|
||||||
|
var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||||
|
//Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data);
|
||||||
|
|
||||||
|
var o = new AppDebug();
|
||||||
|
var requestBody = JsonConvert.DeserializeAnonymousType(data, o);
|
||||||
|
|
||||||
|
Debug.SetDebugLevel(requestBody.Level);
|
||||||
|
|
||||||
|
o.Level = Debug.Level;
|
||||||
|
|
||||||
|
var responseBody = JsonConvert.SerializeObject(o, Formatting.Indented);
|
||||||
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.StatusDescription = "OK";
|
||||||
|
context.Response.Write(responseBody, false);
|
||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,4 +136,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AppDebug
|
||||||
|
{
|
||||||
|
[JsonProperty("level", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public int Level { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,18 @@
|
|||||||
using Crestron.SimplSharp.WebScripting;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp.WebScripting;
|
||||||
|
using PepperDash.Core;
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||||
{
|
{
|
||||||
public class DevJsonRequestHandler : WebApiBaseRequestHandler
|
public class DevJsonRequestHandler : WebApiBaseRequestHandler
|
||||||
{
|
{
|
||||||
|
private const string Key = "DevJsonRequestHandler";
|
||||||
|
private const uint Trace = 0;
|
||||||
|
private const uint Info = 0;
|
||||||
|
private const uint Verbose = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles CONNECT method requests
|
/// Handles CONNECT method requests
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -77,8 +85,17 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
protected override void HandlePost(HttpCwsContext context)
|
protected override void HandlePost(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 501;
|
if (context.Request.ContentLength < 0) return;
|
||||||
context.Response.StatusDescription = "Not Implemented";
|
|
||||||
|
var bytes = new Byte[context.Request.ContentLength];
|
||||||
|
context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength);
|
||||||
|
var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||||
|
Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data);
|
||||||
|
|
||||||
|
DeviceJsonApi.DoDeviceActionWithJson(data);
|
||||||
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.StatusDescription = "OK";
|
||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
using System.Diagnostics;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using Crestron.SimplSharp.WebScripting;
|
using Crestron.SimplSharp.WebScripting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
using Debug = PepperDash.Core.Debug;
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
using Crestron.SimplSharp.WebScripting;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp.WebScripting;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Core;
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||||
{
|
{
|
||||||
public class DevPropsRequestHandler : WebApiBaseRequestHandler
|
public class DevPropsRequestHandler : WebApiBaseRequestHandler
|
||||||
{
|
{
|
||||||
|
private const string Key = "DevPropsRequestHandler";
|
||||||
|
private const uint Trace = 0;
|
||||||
|
private const uint Info = 0;
|
||||||
|
private const uint Verbose = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles CONNECT method requests
|
/// Handles CONNECT method requests
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -77,8 +86,34 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
protected override void HandlePost(HttpCwsContext context)
|
protected override void HandlePost(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 501;
|
if (context.Request.ContentLength < 0) return;
|
||||||
context.Response.StatusDescription = "Not Implemented";
|
|
||||||
|
var bytes = new Byte[context.Request.ContentLength];
|
||||||
|
context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength);
|
||||||
|
var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||||
|
//Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data);
|
||||||
|
|
||||||
|
var o = new DeviceActionWrapper();
|
||||||
|
var body = JsonConvert.DeserializeAnonymousType(data, o);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(body.DeviceKey))
|
||||||
|
{
|
||||||
|
Debug.Console(Info, "[{0}] Request body is null or empty", Key.ToLower());
|
||||||
|
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
context.Response.StatusDescription = "Bad Request";
|
||||||
|
context.Response.End();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var deviceProps = DeviceJsonApi.GetProperties(body.DeviceKey);
|
||||||
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.StatusDescription = "OK";
|
||||||
|
context.Response.ContentType = "application/json";
|
||||||
|
context.Response.ContentEncoding = Encoding.UTF8;
|
||||||
|
context.Response.Write(deviceProps, false);
|
||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,8 +77,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
protected override void HandlePost(HttpCwsContext context)
|
protected override void HandlePost(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 501;
|
DeviceManager.DisableAllDeviceStreamDebugging();
|
||||||
context.Response.StatusDescription = "Not Implemented";
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.StatusDescription = "OK";
|
||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Crestron.SimplSharp.WebScripting;
|
using Crestron.SimplSharp.WebScripting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PepperDash.Core;
|
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
using Crestron.SimplSharp.WebScripting;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp.WebScripting;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Core;
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||||
{
|
{
|
||||||
public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler
|
public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler
|
||||||
{
|
{
|
||||||
|
private const string Key = "SetDeviceStreamDebugRequestHandler";
|
||||||
|
private const uint Trace = 0;
|
||||||
|
private const uint Info = 0;
|
||||||
|
private const uint Verbose = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles CONNECT method requests
|
/// Handles CONNECT method requests
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -77,8 +87,39 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
protected override void HandlePost(HttpCwsContext context)
|
protected override void HandlePost(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 501;
|
if (context.Request.ContentLength < 0) return;
|
||||||
context.Response.StatusDescription = "Not Implemented";
|
|
||||||
|
var bytes = new Byte[context.Request.ContentLength];
|
||||||
|
context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength);
|
||||||
|
var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||||
|
Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data);
|
||||||
|
|
||||||
|
var o = new
|
||||||
|
{
|
||||||
|
DeviceKey = "",
|
||||||
|
Type = "",
|
||||||
|
Timeout = 15
|
||||||
|
};
|
||||||
|
|
||||||
|
var body = JsonConvert.DeserializeAnonymousType(data, o);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(body.DeviceKey) || string.IsNullOrEmpty(body.Type)
|
||||||
|
|| !body.Type.ToLower().Contains("off")
|
||||||
|
|| !body.Type.ToLower().Contains("tx")
|
||||||
|
|| !body.Type.ToLower().Contains("rx")
|
||||||
|
|| !body.Type.ToLower().Contains("both"))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
context.Response.StatusDescription = "Bad Request";
|
||||||
|
context.Response.End();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceManager.SetDeviceStreamDebugging(string.Format("setdevicestreamdebug {0} {1} {2}", body.DeviceKey, body.Type, body.Timeout));
|
||||||
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.StatusDescription = "OK";
|
||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user