mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-20 07:56:50 +00:00
chore: move all files to file-scoped namespace
This commit is contained in:
parent
aaa5b0532b
commit
3ece4f0b7b
522 changed files with 39628 additions and 45678 deletions
|
|
@ -8,281 +8,278 @@ using PepperDash.Core.Web;
|
|||
using PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a EssentialsWebApi
|
||||
/// </summary>
|
||||
public class EssentialsWebApi : EssentialsDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a EssentialsWebApi
|
||||
/// </summary>
|
||||
public class EssentialsWebApi : EssentialsDevice
|
||||
{
|
||||
private readonly WebApiServer _server;
|
||||
private readonly WebApiServer _server;
|
||||
|
||||
///<example>
|
||||
/// http(s)://{ipaddress}/cws/{basePath}
|
||||
/// http(s)://{ipaddress}/VirtualControl/Rooms/{roomId}/cws/{basePath}
|
||||
/// </example>
|
||||
private readonly string _defaultBasePath = CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance
|
||||
? string.Format("/app{0:00}/api", InitialParametersClass.ApplicationNumber)
|
||||
: "/api";
|
||||
///<example>
|
||||
/// http(s)://{ipaddress}/cws/{basePath}
|
||||
/// http(s)://{ipaddress}/VirtualControl/Rooms/{roomId}/cws/{basePath}
|
||||
/// </example>
|
||||
private readonly string _defaultBasePath = CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance
|
||||
? string.Format("/app{0:00}/api", InitialParametersClass.ApplicationNumber)
|
||||
: "/api";
|
||||
|
||||
private const int DebugTrace = 0;
|
||||
private const int DebugInfo = 1;
|
||||
private const int DebugVerbose = 2;
|
||||
private const int DebugTrace = 0;
|
||||
private const int DebugInfo = 1;
|
||||
private const int DebugVerbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the BasePath
|
||||
/// </summary>
|
||||
public string BasePath { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the BasePath
|
||||
/// </summary>
|
||||
public string BasePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tracks if CWS is registered
|
||||
/// </summary>
|
||||
public bool IsRegistered
|
||||
{
|
||||
get { return _server.IsRegistered; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Tracks if CWS is registered
|
||||
/// </summary>
|
||||
public bool IsRegistered
|
||||
{
|
||||
get { return _server.IsRegistered; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
public EssentialsWebApi(string key, string name)
|
||||
: this(key, name, null)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
public EssentialsWebApi(string key, string name)
|
||||
: this(key, name, null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
public EssentialsWebApi(string key, string name, EssentialsWebApiPropertiesConfig config)
|
||||
: base(key, name)
|
||||
{
|
||||
Key = key;
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
public EssentialsWebApi(string key, string name, EssentialsWebApiPropertiesConfig config)
|
||||
: base(key, name)
|
||||
{
|
||||
Key = key;
|
||||
|
||||
if (config == null)
|
||||
BasePath = _defaultBasePath;
|
||||
else
|
||||
BasePath = string.IsNullOrEmpty(config.BasePath) ? _defaultBasePath : config.BasePath;
|
||||
if (config == null)
|
||||
BasePath = _defaultBasePath;
|
||||
else
|
||||
BasePath = string.IsNullOrEmpty(config.BasePath) ? _defaultBasePath : config.BasePath;
|
||||
|
||||
_server = new WebApiServer(Key, Name, BasePath);
|
||||
_server = new WebApiServer(Key, Name, BasePath);
|
||||
|
||||
SetupRoutes();
|
||||
}
|
||||
SetupRoutes();
|
||||
}
|
||||
|
||||
private void SetupRoutes()
|
||||
{
|
||||
var routes = new List<HttpCwsRoute>
|
||||
{
|
||||
new HttpCwsRoute("versions")
|
||||
{
|
||||
Name = "ReportVersions",
|
||||
RouteHandler = new ReportVersionsRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("appdebug")
|
||||
{
|
||||
Name = "AppDebug",
|
||||
RouteHandler = new AppDebugRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("devices")
|
||||
{
|
||||
Name = "DevList",
|
||||
RouteHandler = new DevListRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceCommands/{deviceKey}")
|
||||
{
|
||||
Name = "DevJson",
|
||||
RouteHandler = new DevJsonRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceProperties/{deviceKey}")
|
||||
{
|
||||
Name = "DevProps",
|
||||
RouteHandler = new DevPropsRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceMethods/{deviceKey}")
|
||||
{
|
||||
Name = "DevMethods",
|
||||
RouteHandler = new DevMethodsRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceFeedbacks/{deviceKey}")
|
||||
{
|
||||
Name = "GetFeedbacksForDeviceKey",
|
||||
RouteHandler = new GetFeedbacksForDeviceRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceStreamDebug")
|
||||
{
|
||||
Name = "SetDeviceStreamDebug",
|
||||
RouteHandler = new SetDeviceStreamDebugRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("disableAllStreamDebug")
|
||||
{
|
||||
Name = "DisableAllStreamDebug",
|
||||
RouteHandler = new DisableAllStreamDebugRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("config")
|
||||
{
|
||||
Name = "ShowConfig",
|
||||
RouteHandler = new ShowConfigRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("types")
|
||||
{
|
||||
Name = "GetTypes",
|
||||
RouteHandler = new GetTypesRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("types/{filter}")
|
||||
{
|
||||
Name = "GetTypesByFilter",
|
||||
RouteHandler = new GetTypesByFilterRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("joinMap/{bridgeKey}")
|
||||
{
|
||||
Name = "GetJoinMapsForBridgeKey",
|
||||
RouteHandler = new GetJoinMapForBridgeKeyRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("joinMap/{bridgeKey}/{deviceKey}")
|
||||
{
|
||||
Name = "GetJoinMapsForDeviceKey",
|
||||
RouteHandler = new GetJoinMapForDeviceKeyRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("debugSession")
|
||||
{
|
||||
Name = "DebugSession",
|
||||
RouteHandler = new DebugSessionRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("doNotLoadConfigOnNextBoot")
|
||||
{
|
||||
Name = "DoNotLoadConfigOnNextBoot",
|
||||
RouteHandler = new DoNotLoadConfigOnNextBootRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("restartProgram")
|
||||
{
|
||||
Name = "Restart Program",
|
||||
RouteHandler = new RestartProgramRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("loadConfig")
|
||||
{
|
||||
Name = "Load Config",
|
||||
RouteHandler = new LoadConfigRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("tielines")
|
||||
{
|
||||
Name = "Get TieLines",
|
||||
RouteHandler = new GetTieLinesRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("device/{deviceKey}/routingPorts")
|
||||
{
|
||||
Name = "Get Routing Ports for a device",
|
||||
RouteHandler = new GetRoutingPortsHandler()
|
||||
},
|
||||
};
|
||||
|
||||
AddRoute(routes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a single route to the API. MUST be done during the activation phase
|
||||
/// </summary>
|
||||
/// <param name="route"></param>
|
||||
/// <summary>
|
||||
/// AddRoute method
|
||||
/// </summary>
|
||||
public void AddRoute(HttpCwsRoute route)
|
||||
private void SetupRoutes()
|
||||
{
|
||||
var routes = new List<HttpCwsRoute>
|
||||
{
|
||||
_server.AddRoute(route);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a collection of routes to the API. MUST be done during the activation phase
|
||||
/// </summary>
|
||||
/// <param name="routes"></param>
|
||||
public void AddRoute(List<HttpCwsRoute> routes)
|
||||
{
|
||||
foreach (var route in routes)
|
||||
new HttpCwsRoute("versions")
|
||||
{
|
||||
AddRoute(route);
|
||||
}
|
||||
Name = "ReportVersions",
|
||||
RouteHandler = new ReportVersionsRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("appdebug")
|
||||
{
|
||||
Name = "AppDebug",
|
||||
RouteHandler = new AppDebugRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("devices")
|
||||
{
|
||||
Name = "DevList",
|
||||
RouteHandler = new DevListRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceCommands/{deviceKey}")
|
||||
{
|
||||
Name = "DevJson",
|
||||
RouteHandler = new DevJsonRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceProperties/{deviceKey}")
|
||||
{
|
||||
Name = "DevProps",
|
||||
RouteHandler = new DevPropsRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceMethods/{deviceKey}")
|
||||
{
|
||||
Name = "DevMethods",
|
||||
RouteHandler = new DevMethodsRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceFeedbacks/{deviceKey}")
|
||||
{
|
||||
Name = "GetFeedbacksForDeviceKey",
|
||||
RouteHandler = new GetFeedbacksForDeviceRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("deviceStreamDebug")
|
||||
{
|
||||
Name = "SetDeviceStreamDebug",
|
||||
RouteHandler = new SetDeviceStreamDebugRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("disableAllStreamDebug")
|
||||
{
|
||||
Name = "DisableAllStreamDebug",
|
||||
RouteHandler = new DisableAllStreamDebugRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("config")
|
||||
{
|
||||
Name = "ShowConfig",
|
||||
RouteHandler = new ShowConfigRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("types")
|
||||
{
|
||||
Name = "GetTypes",
|
||||
RouteHandler = new GetTypesRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("types/{filter}")
|
||||
{
|
||||
Name = "GetTypesByFilter",
|
||||
RouteHandler = new GetTypesByFilterRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("joinMap/{bridgeKey}")
|
||||
{
|
||||
Name = "GetJoinMapsForBridgeKey",
|
||||
RouteHandler = new GetJoinMapForBridgeKeyRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("joinMap/{bridgeKey}/{deviceKey}")
|
||||
{
|
||||
Name = "GetJoinMapsForDeviceKey",
|
||||
RouteHandler = new GetJoinMapForDeviceKeyRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("debugSession")
|
||||
{
|
||||
Name = "DebugSession",
|
||||
RouteHandler = new DebugSessionRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("doNotLoadConfigOnNextBoot")
|
||||
{
|
||||
Name = "DoNotLoadConfigOnNextBoot",
|
||||
RouteHandler = new DoNotLoadConfigOnNextBootRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("restartProgram")
|
||||
{
|
||||
Name = "Restart Program",
|
||||
RouteHandler = new RestartProgramRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("loadConfig")
|
||||
{
|
||||
Name = "Load Config",
|
||||
RouteHandler = new LoadConfigRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("tielines")
|
||||
{
|
||||
Name = "Get TieLines",
|
||||
RouteHandler = new GetTieLinesRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("device/{deviceKey}/routingPorts")
|
||||
{
|
||||
Name = "Get Routing Ports for a device",
|
||||
RouteHandler = new GetRoutingPortsHandler()
|
||||
},
|
||||
};
|
||||
|
||||
AddRoute(routes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a single route to the API. MUST be done during the activation phase
|
||||
/// </summary>
|
||||
/// <param name="route"></param>
|
||||
public void AddRoute(HttpCwsRoute route)
|
||||
{
|
||||
_server.AddRoute(route);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a collection of routes to the API. MUST be done during the activation phase
|
||||
/// </summary>
|
||||
/// <param name="routes"></param>
|
||||
public void AddRoute(List<HttpCwsRoute> routes)
|
||||
{
|
||||
foreach (var route in routes)
|
||||
{
|
||||
AddRoute(route);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the CWS class
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
AddRoute(new HttpCwsRoute("apiPaths")
|
||||
{
|
||||
Name = "GetPaths",
|
||||
RouteHandler = new GetRoutesHandler(_server.GetRouteCollection(), BasePath)
|
||||
});
|
||||
|
||||
// If running on an appliance
|
||||
if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
|
||||
{
|
||||
/*
|
||||
WEBSERVER [ON | OFF | TIMEOUT <VALUE IN SECONDS> | MAXSESSIONSPERUSER <Number of sessions>]
|
||||
*/
|
||||
var response = string.Empty;
|
||||
CrestronConsole.SendControlSystemCommand("webserver", ref response);
|
||||
if (response.Contains("OFF")) return;
|
||||
|
||||
var is4Series = eCrestronSeries.Series4 == (Global.ProcessorSeries & eCrestronSeries.Series4);
|
||||
Debug.LogMessage(LogEventLevel.Verbose, "Starting Essentials Web API on {0} Appliance", is4Series ? "4-series" : "3-series");
|
||||
|
||||
_server.Start();
|
||||
|
||||
GetPaths();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
AddRoute(new HttpCwsRoute("apiPaths") {
|
||||
Name = "GetPaths",
|
||||
RouteHandler = new GetRoutesHandler(_server.GetRouteCollection(), BasePath)
|
||||
});
|
||||
// Automatically start CWS when running on a server (Linux OS, Virtual Control)
|
||||
Debug.LogMessage(LogEventLevel.Verbose, "Starting Essentials Web API on Virtual Control Server");
|
||||
|
||||
// If running on an appliance
|
||||
if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
|
||||
{
|
||||
/*
|
||||
WEBSERVER [ON | OFF | TIMEOUT <VALUE IN SECONDS> | MAXSESSIONSPERUSER <Number of sessions>]
|
||||
*/
|
||||
var response = string.Empty;
|
||||
CrestronConsole.SendControlSystemCommand("webserver", ref response);
|
||||
if (response.Contains("OFF")) return;
|
||||
_server.Start();
|
||||
|
||||
var is4Series = eCrestronSeries.Series4 == (Global.ProcessorSeries & eCrestronSeries.Series4);
|
||||
Debug.LogMessage(LogEventLevel.Verbose, "Starting Essentials Web API on {0} Appliance", is4Series ? "4-series" : "3-series");
|
||||
GetPaths();
|
||||
}
|
||||
|
||||
_server.Start();
|
||||
/// <summary>
|
||||
/// Print the available pahts
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// http(s)://{ipaddress}/cws/{basePath}
|
||||
/// http(s)://{ipaddress}/VirtualControl/Rooms/{roomId}/cws/{basePath}
|
||||
/// </example>
|
||||
/// <summary>
|
||||
/// GetPaths method
|
||||
/// </summary>
|
||||
public void GetPaths()
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, this, new string('-', 50));
|
||||
|
||||
GetPaths();
|
||||
var currentIp = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
var hostname = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
|
||||
|
||||
// Automatically start CWS when running on a server (Linux OS, Virtual Control)
|
||||
Debug.LogMessage(LogEventLevel.Verbose, "Starting Essentials Web API on Virtual Control Server");
|
||||
var path = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
|
||||
? $"https://{hostname}/VirtualControl/Rooms/{InitialParametersClass.RoomId}/cws{BasePath}"
|
||||
: $"https://{currentIp}/cws{BasePath}";
|
||||
|
||||
_server.Start();
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Server:{path:l}", path);
|
||||
|
||||
GetPaths();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print the available pahts
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// http(s)://{ipaddress}/cws/{basePath}
|
||||
/// http(s)://{ipaddress}/VirtualControl/Rooms/{roomId}/cws/{basePath}
|
||||
/// </example>
|
||||
/// <summary>
|
||||
/// GetPaths method
|
||||
/// </summary>
|
||||
public void GetPaths()
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, this, new string('-', 50));
|
||||
|
||||
var currentIp = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
|
||||
var hostname = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
|
||||
|
||||
var path = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
|
||||
? $"https://{hostname}/VirtualControl/Rooms/{InitialParametersClass.RoomId}/cws{BasePath}"
|
||||
: $"https://{currentIp}/cws{BasePath}";
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Server:{path:l}", path);
|
||||
|
||||
var routeCollection = _server.GetRouteCollection();
|
||||
if (routeCollection == null)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Server route collection is null");
|
||||
return;
|
||||
}
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Configured Routes:");
|
||||
foreach (var route in routeCollection)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "{routeName:l}: {routePath:l}/{routeUrl:l}", route.Name, path, route.Url);
|
||||
}
|
||||
Debug.LogMessage(LogEventLevel.Information, this, new string('-', 50));
|
||||
}
|
||||
}
|
||||
var routeCollection = _server.GetRouteCollection();
|
||||
if (routeCollection == null)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Server route collection is null");
|
||||
return;
|
||||
}
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Configured Routes:");
|
||||
foreach (var route in routeCollection)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "{routeName:l}: {routePath:l}/{routeUrl:l}", route.Name, path, route.Url);
|
||||
}
|
||||
Debug.LogMessage(LogEventLevel.Information, this, new string('-', 50));
|
||||
}
|
||||
}
|
||||
|
|
@ -3,34 +3,33 @@ using PepperDash.Core;
|
|||
using PepperDash.Essentials.Core.Config;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web
|
||||
namespace PepperDash.Essentials.Core.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Factory for creating EssentialsWebApi devices
|
||||
/// </summary>
|
||||
public class EssentialsWebApiFactory : EssentialsDeviceFactory<EssentialsWebApi>
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a EssentialsWebApiFactory
|
||||
/// </summary>
|
||||
public class EssentialsWebApiFactory : EssentialsDeviceFactory<EssentialsWebApi>
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public EssentialsWebApiFactory()
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public EssentialsWebApiFactory()
|
||||
{
|
||||
TypeNames = new List<string> { "EssentialsWebApi" };
|
||||
}
|
||||
TypeNames = new List<string> { "EssentialsWebApi" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BuildDevice method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new Essentials Web API Server");
|
||||
/// <summary>
|
||||
/// BuildDevice method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new Essentials Web API Server");
|
||||
|
||||
var props = dc.Properties.ToObject<EssentialsWebApiPropertiesConfig>();
|
||||
if (props != null) return new EssentialsWebApi(dc.Key, dc.Name, props);
|
||||
var props = dc.Properties.ToObject<EssentialsWebApiPropertiesConfig>();
|
||||
if (props != null) return new EssentialsWebApi(dc.Key, dc.Name, props);
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Factory failed to create new Essentials Web API Server");
|
||||
return null;
|
||||
}
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Factory failed to create new Essentials Web API Server");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,114 +1,112 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web
|
||||
namespace PepperDash.Essentials.Core.Web;
|
||||
|
||||
/// <summary>
|
||||
/// EssentialsWebApiHelpers class
|
||||
/// </summary>
|
||||
public static class EssentialsWebApiHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// EssentialsWebApiHelpers class
|
||||
/// GetRequestBody method
|
||||
/// </summary>
|
||||
public static class EssentialsWebApiHelpers
|
||||
public static string GetRequestBody(this HttpCwsRequest request)
|
||||
{
|
||||
/// <summary>
|
||||
/// GetRequestBody method
|
||||
/// </summary>
|
||||
public static string GetRequestBody(this HttpCwsRequest request)
|
||||
var bytes = new byte[request.ContentLength];
|
||||
|
||||
request.InputStream.Read(bytes, 0, request.ContentLength);
|
||||
|
||||
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapToAssemblyObject method
|
||||
/// </summary>
|
||||
public static object MapToAssemblyObject(LoadedAssembly assembly)
|
||||
{
|
||||
return new
|
||||
{
|
||||
var bytes = new byte[request.ContentLength];
|
||||
assembly.Name,
|
||||
assembly.Version
|
||||
};
|
||||
}
|
||||
|
||||
request.InputStream.Read(bytes, 0, request.ContentLength);
|
||||
|
||||
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapToAssemblyObject method
|
||||
/// </summary>
|
||||
public static object MapToAssemblyObject(LoadedAssembly assembly)
|
||||
/// <summary>
|
||||
/// MapToDeviceListObject method
|
||||
/// </summary>
|
||||
public static object MapToDeviceListObject(IKeyed device)
|
||||
{
|
||||
return new
|
||||
{
|
||||
return new
|
||||
{
|
||||
assembly.Name,
|
||||
assembly.Version
|
||||
};
|
||||
}
|
||||
device.Key,
|
||||
Name = (device is IKeyName)
|
||||
? (device as IKeyName).Name
|
||||
: "---"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapToDeviceListObject method
|
||||
/// </summary>
|
||||
public static object MapToDeviceListObject(IKeyed device)
|
||||
/// <summary>
|
||||
/// MapJoinToObject method
|
||||
/// </summary>
|
||||
public static object MapJoinToObject(string key, JoinMapBaseAdvanced join)
|
||||
{
|
||||
var kp = new KeyValuePair<string, JoinMapBaseAdvanced>(key, join);
|
||||
|
||||
return MapJoinToObject(kp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapJoinToObject method
|
||||
/// </summary>
|
||||
public static object MapJoinToObject(KeyValuePair<string, JoinMapBaseAdvanced> join)
|
||||
{
|
||||
return new
|
||||
{
|
||||
return new
|
||||
{
|
||||
device.Key,
|
||||
Name = (device is IKeyName)
|
||||
? (device as IKeyName).Name
|
||||
: "---"
|
||||
};
|
||||
}
|
||||
DeviceKey = join.Key,
|
||||
Joins = join.Value.Joins.Select(j => MapJoinDataCompleteToObject(j))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapJoinToObject method
|
||||
/// </summary>
|
||||
public static object MapJoinToObject(string key, JoinMapBaseAdvanced join)
|
||||
/// <summary>
|
||||
/// MapJoinDataCompleteToObject method
|
||||
/// </summary>
|
||||
public static object MapJoinDataCompleteToObject(KeyValuePair<string, JoinDataComplete> joinData)
|
||||
{
|
||||
return new
|
||||
{
|
||||
var kp = new KeyValuePair<string, JoinMapBaseAdvanced>(key, join);
|
||||
Signal = joinData.Key,
|
||||
Description = joinData.Value.Metadata.Description,
|
||||
JoinNumber = joinData.Value.JoinNumber,
|
||||
JoinSpan = joinData.Value.JoinSpan,
|
||||
JoinType = joinData.Value.Metadata.JoinType.ToString(),
|
||||
JoinCapabilities = joinData.Value.Metadata.JoinCapabilities.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
return MapJoinToObject(kp);
|
||||
}
|
||||
/// <summary>
|
||||
/// MapDeviceTypeToObject method
|
||||
/// </summary>
|
||||
public static object MapDeviceTypeToObject(string key, DeviceFactoryWrapper device)
|
||||
{
|
||||
var kp = new KeyValuePair<string, DeviceFactoryWrapper>(key, device);
|
||||
|
||||
/// <summary>
|
||||
/// MapJoinToObject method
|
||||
/// </summary>
|
||||
public static object MapJoinToObject(KeyValuePair<string, JoinMapBaseAdvanced> join)
|
||||
return MapDeviceTypeToObject(kp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapDeviceTypeToObject method
|
||||
/// </summary>
|
||||
public static object MapDeviceTypeToObject(KeyValuePair<string, DeviceFactoryWrapper> device)
|
||||
{
|
||||
return new
|
||||
{
|
||||
return new
|
||||
{
|
||||
DeviceKey = join.Key,
|
||||
Joins = join.Value.Joins.Select(j => MapJoinDataCompleteToObject(j))
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapJoinDataCompleteToObject method
|
||||
/// </summary>
|
||||
public static object MapJoinDataCompleteToObject(KeyValuePair<string, JoinDataComplete> joinData)
|
||||
{
|
||||
return new
|
||||
{
|
||||
Signal = joinData.Key,
|
||||
Description = joinData.Value.Metadata.Description,
|
||||
JoinNumber = joinData.Value.JoinNumber,
|
||||
JoinSpan = joinData.Value.JoinSpan,
|
||||
JoinType = joinData.Value.Metadata.JoinType.ToString(),
|
||||
JoinCapabilities = joinData.Value.Metadata.JoinCapabilities.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapDeviceTypeToObject method
|
||||
/// </summary>
|
||||
public static object MapDeviceTypeToObject(string key, DeviceFactoryWrapper device)
|
||||
{
|
||||
var kp = new KeyValuePair<string, DeviceFactoryWrapper>(key, device);
|
||||
|
||||
return MapDeviceTypeToObject(kp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MapDeviceTypeToObject method
|
||||
/// </summary>
|
||||
public static object MapDeviceTypeToObject(KeyValuePair<string, DeviceFactoryWrapper> device)
|
||||
{
|
||||
return new
|
||||
{
|
||||
Type = device.Key,
|
||||
Description = device.Value.Description,
|
||||
CType = device.Value.Type == null ? "---": device.Value.Type.ToString()
|
||||
};
|
||||
}
|
||||
Type = device.Key,
|
||||
Description = device.Value.Description,
|
||||
CType = device.Value.Type == null ? "---" : device.Value.Type.ToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,15 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web
|
||||
namespace PepperDash.Essentials.Core.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a EssentialsWebApiPropertiesConfig
|
||||
/// </summary>
|
||||
public class EssentialsWebApiPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a EssentialsWebApiPropertiesConfig
|
||||
/// Gets or sets the BasePath
|
||||
/// </summary>
|
||||
public class EssentialsWebApiPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the BasePath
|
||||
/// </summary>
|
||||
[JsonProperty("basePath")]
|
||||
public string BasePath { get; set; }
|
||||
}
|
||||
[JsonProperty("basePath")]
|
||||
public string BasePath { get; set; }
|
||||
}
|
||||
|
|
@ -2,94 +2,92 @@
|
|||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using System;
|
||||
using Serilog.Events;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a AppDebugRequestHandler
|
||||
/// </summary>
|
||||
public class AppDebugRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a AppDebugRequestHandler
|
||||
/// </summary>
|
||||
public class AppDebugRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public AppDebugRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public AppDebugRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel };
|
||||
|
||||
var body = JsonConvert.SerializeObject(appDebug, 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 appDebug = new AppDebug();
|
||||
var requestBody = JsonConvert.DeserializeObject<AppDebug>(data);
|
||||
|
||||
Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel);
|
||||
|
||||
appDebug.MinimumLevel = Debug.WebsocketMinimumLogLevel;
|
||||
var responseBody = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(responseBody, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a AppDebug
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
public class AppDebug
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the MinimumLevel
|
||||
/// </summary>
|
||||
[JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public LogEventLevel MinimumLevel { get; set; }
|
||||
var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel };
|
||||
|
||||
var body = JsonConvert.SerializeObject(appDebug, 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 appDebug = new AppDebug();
|
||||
var requestBody = JsonConvert.DeserializeObject<AppDebug>(data);
|
||||
|
||||
Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel);
|
||||
|
||||
appDebug.MinimumLevel = Debug.WebsocketMinimumLogLevel;
|
||||
var responseBody = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(responseBody, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a AppDebug
|
||||
/// </summary>
|
||||
public class AppDebug
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the MinimumLevel
|
||||
/// </summary>
|
||||
[JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public LogEventLevel MinimumLevel { get; set; }
|
||||
}
|
||||
|
|
@ -1,107 +1,94 @@
|
|||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Crestron.SimplSharpPro.EthernetCommunication;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using Serilog.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DebugSessionRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
private readonly DebugWebsocketSink _sink = new DebugWebsocketSink();
|
||||
|
||||
public DebugSessionRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a DebugSessionRequestHandler
|
||||
/// Gets details for a debug session
|
||||
/// </summary>
|
||||
public class DebugSessionRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
|
||||
private readonly DebugWebsocketSink _sink = new DebugWebsocketSink();
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public DebugSessionRequestHandler()
|
||||
: base(true)
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets details for a debug session
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var ip = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
|
||||
var port = 0;
|
||||
|
||||
if (!_sink.IsRunning)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, "Starting WS Server");
|
||||
// Generate a random port within a specified range
|
||||
port = new Random().Next(65435, 65535);
|
||||
// Start the WS Server
|
||||
_sink.StartServerAndSetPort(port);
|
||||
Debug.SetWebSocketMinimumDebugLevel(Serilog.Events.LogEventLevel.Verbose);
|
||||
}
|
||||
|
||||
var url = _sink.Url;
|
||||
|
||||
object data = new
|
||||
{
|
||||
url = _sink.Url
|
||||
};
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Information, "Debug Session URL: {0}", url);
|
||||
|
||||
// Return the port number with the full url of the WS Server
|
||||
var res = JsonConvert.SerializeObject(data);
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(res, false);
|
||||
context.Response.End();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, "Error: {0}", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a debug session
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
_sink.StopServer();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Information, "Websocket Debug Session Stopped");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var ip = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
|
||||
var port = 0;
|
||||
|
||||
if (!_sink.IsRunning)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, "Starting WS Server");
|
||||
// Generate a random port within a specified range
|
||||
port = new Random().Next(65435, 65535);
|
||||
// Start the WS Server
|
||||
_sink.StartServerAndSetPort(port);
|
||||
Debug.SetWebSocketMinimumDebugLevel(Serilog.Events.LogEventLevel.Verbose);
|
||||
}
|
||||
|
||||
var url = _sink.Url;
|
||||
|
||||
object data = new
|
||||
{
|
||||
url = _sink.Url
|
||||
};
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Information, "Debug Session URL: {0}", url);
|
||||
|
||||
// Return the port number with the full url of the WS Server
|
||||
var res = JsonConvert.SerializeObject(data);
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(res, false);
|
||||
context.Response.End();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, "Error: {0}", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a debug session
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
_sink.StopServer();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Information, "Websocket Debug Session Stopped");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,41 @@
|
|||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DebugWebsocketSink
|
||||
{
|
||||
public class DebugWebsocketSink
|
||||
private bool _isRunning;
|
||||
private string _url;
|
||||
|
||||
public bool IsRunning => _isRunning;
|
||||
public string Url => _url;
|
||||
|
||||
public void StartServerAndSetPort(int port)
|
||||
{
|
||||
private bool _isRunning;
|
||||
private string _url;
|
||||
|
||||
public bool IsRunning => _isRunning;
|
||||
public string Url => _url;
|
||||
|
||||
public void StartServerAndSetPort(int port)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
_url = $"ws://localhost:{port}";
|
||||
_isRunning = true;
|
||||
// Implement actual server startup logic here
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isRunning = false;
|
||||
throw new Exception($"Failed to start debug websocket server: {ex.Message}");
|
||||
}
|
||||
_url = $"ws://localhost:{port}";
|
||||
_isRunning = true;
|
||||
// Implement actual server startup logic here
|
||||
}
|
||||
|
||||
public void StopServer()
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Implement actual server shutdown logic here
|
||||
_isRunning = false;
|
||||
_url = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Failed to stop debug websocket server: {ex.Message}");
|
||||
}
|
||||
_isRunning = false;
|
||||
throw new Exception($"Failed to start debug websocket server: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void StopServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Implement actual server shutdown logic here
|
||||
_isRunning = false;
|
||||
_url = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Failed to stop debug websocket server: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
using Crestron.SimplSharp.WebScripting;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DefaultRequestHandler
|
||||
/// </summary>
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DefaultRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -117,5 +114,4 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,11 +5,8 @@ using PepperDash.Core;
|
|||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DevJsonRequestHandler
|
||||
/// </summary>
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DevJsonRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -29,25 +26,25 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
var routeData = context.Request.RouteData;
|
||||
|
||||
if(routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
if(routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(!routeData.Values.TryGetValue("deviceKey", out var deviceKey))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
if(!routeData.Values.TryGetValue("deviceKey", out var deviceKey))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.Request.ContentLength < 0)
|
||||
{
|
||||
|
|
@ -71,11 +68,11 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||
|
||||
try
|
||||
{
|
||||
var daw = new DeviceActionWrapper { DeviceKey = (string) deviceKey};
|
||||
var daw = new DeviceActionWrapper { DeviceKey = (string) deviceKey};
|
||||
|
||||
JsonConvert.PopulateObject(data, daw);
|
||||
JsonConvert.PopulateObject(data, daw);
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Verbose, "Device Action Wrapper: {@wrapper}", null, daw);
|
||||
Debug.LogMessage(LogEventLevel.Verbose, "Device Action Wrapper: {@wrapper}", null, daw);
|
||||
|
||||
DeviceJsonApi.DoDeviceAction(daw);
|
||||
|
||||
|
|
@ -89,9 +86,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.Write(JsonConvert.SerializeObject(new { error = ex.Message }), false);
|
||||
context.Response.Write(JsonConvert.SerializeObject(new { error = ex.Message }), false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,52 +3,48 @@ using Crestron.SimplSharp.WebScripting;
|
|||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DevListRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DevListRequestHandler
|
||||
/// </summary>
|
||||
public class DevListRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DevListRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DevListRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var allDevices = DeviceManager.AllDevices;
|
||||
if (allDevices == null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var allDevices = DeviceManager.AllDevices;
|
||||
if (allDevices == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
allDevices.Sort((a, b) => string.Compare(a.Key, b.Key, System.StringComparison.Ordinal));
|
||||
|
||||
var deviceList = allDevices.Select(d => EssentialsWebApiHelpers.MapToDeviceListObject(d)).ToList();
|
||||
|
||||
var js = JsonConvert.SerializeObject(deviceList, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
allDevices.Sort((a, b) => string.Compare(a.Key, b.Key, System.StringComparison.Ordinal));
|
||||
|
||||
var deviceList = allDevices.Select(d => EssentialsWebApiHelpers.MapToDeviceListObject(d)).ToList();
|
||||
|
||||
var js = JsonConvert.SerializeObject(deviceList, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +1,76 @@
|
|||
using System.Text;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DevMethodsRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DevMethodsRequestHandler
|
||||
/// </summary>
|
||||
public class DevMethodsRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DevMethodsRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DevMethodsRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, "Getting DevMethods: {@routeData}", routeData);
|
||||
if (routeData == null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, "Getting DevMethods: {@routeData}", routeData);
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString());
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Device Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceMethods = DeviceJsonApi.GetMethods(device.Key);
|
||||
if (deviceMethods == null || deviceMethods.ToLower().Contains("no device"))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(deviceMethods, false);
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString());
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Device Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceMethods = DeviceJsonApi.GetMethods(device.Key);
|
||||
if (deviceMethods == null || deviceMethods.ToLower().Contains("no device"))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(deviceMethods, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,79 +1,74 @@
|
|||
using System.Text;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DevPropsRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DevPropsRequestHandler
|
||||
/// </summary>
|
||||
public class DevPropsRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DevPropsRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DevPropsRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString());
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Device Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceProperties = DeviceJsonApi.GetProperties(device.Key);
|
||||
if (deviceProperties == null || deviceProperties.ToLower().Contains("no device"))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(deviceProperties, false);
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString());
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Device Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceProperties = DeviceJsonApi.GetProperties(device.Key);
|
||||
if (deviceProperties == null || deviceProperties.ToLower().Contains("no device"))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(deviceProperties, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +1,31 @@
|
|||
using Crestron.SimplSharp.WebScripting;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DisableAllStreamDebugRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DisableAllStreamDebugRequestHandler
|
||||
/// </summary>
|
||||
public class DisableAllStreamDebugRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DisableAllStreamDebugRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DisableAllStreamDebugRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
DeviceManager.DisableAllDeviceStreamDebugging();
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
DeviceManager.DisableAllDeviceStreamDebugging();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
}
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -3,91 +3,87 @@ using Newtonsoft.Json;
|
|||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class DoNotLoadConfigOnNextBootRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DoNotLoadConfigOnNextBootRequestHandler
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public class DoNotLoadConfigOnNextBootRequestHandler : WebApiBaseRequestHandler
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DoNotLoadConfigOnNextBootRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Data
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
public class Data
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the DoNotLoadConfigOnNextBoot
|
||||
/// </summary>
|
||||
[JsonProperty("doNotLoadConfigOnNextBoot", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool DoNotLoadConfigOnNextBoot { get; set; }
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Data
|
||||
/// </summary>
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the DoNotLoadConfigOnNextBoot
|
||||
/// </summary>
|
||||
[JsonProperty("doNotLoadConfigOnNextBoot", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool DoNotLoadConfigOnNextBoot { get; set; }
|
||||
}
|
||||
|
|
@ -3,103 +3,99 @@ using Crestron.SimplSharp.WebScripting;
|
|||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class GetFeedbacksForDeviceRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetFeedbacksForDeviceRequestHandler
|
||||
/// </summary>
|
||||
public class GetFeedbacksForDeviceRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetFeedbacksForDeviceRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetFeedbacksForDeviceRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString()) as IHasFeedback;
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var boolFeedback =
|
||||
from feedback in device.Feedbacks.OfType<BoolFeedback>()
|
||||
where !string.IsNullOrEmpty(feedback.Key)
|
||||
select new
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString()) as IHasFeedback;
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var boolFeedback =
|
||||
from feedback in device.Feedbacks.OfType<BoolFeedback>()
|
||||
where !string.IsNullOrEmpty(feedback.Key)
|
||||
select new
|
||||
{
|
||||
FeedbackKey = feedback.Key,
|
||||
Value = feedback.BoolValue
|
||||
};
|
||||
|
||||
var intFeedback =
|
||||
from feedback in device.Feedbacks.OfType<IntFeedback>()
|
||||
where !string.IsNullOrEmpty(feedback.Key)
|
||||
select new
|
||||
{
|
||||
FeedbackKey = feedback.Key,
|
||||
Value = feedback.IntValue
|
||||
};
|
||||
|
||||
var stringFeedback =
|
||||
from feedback in device.Feedbacks.OfType<StringFeedback>()
|
||||
where !string.IsNullOrEmpty(feedback.Key)
|
||||
select new
|
||||
{
|
||||
FeedbackKey = feedback.Key,
|
||||
Value = feedback.StringValue ?? string.Empty
|
||||
};
|
||||
|
||||
var responseObj = new
|
||||
{
|
||||
BoolValues = boolFeedback,
|
||||
IntValues = intFeedback,
|
||||
SerialValues = stringFeedback
|
||||
FeedbackKey = feedback.Key,
|
||||
Value = feedback.BoolValue
|
||||
};
|
||||
|
||||
var js = JsonConvert.SerializeObject(responseObj, Formatting.Indented);
|
||||
var intFeedback =
|
||||
from feedback in device.Feedbacks.OfType<IntFeedback>()
|
||||
where !string.IsNullOrEmpty(feedback.Key)
|
||||
select new
|
||||
{
|
||||
FeedbackKey = feedback.Key,
|
||||
Value = feedback.IntValue
|
||||
};
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
var stringFeedback =
|
||||
from feedback in device.Feedbacks.OfType<StringFeedback>()
|
||||
where !string.IsNullOrEmpty(feedback.Key)
|
||||
select new
|
||||
{
|
||||
FeedbackKey = feedback.Key,
|
||||
Value = feedback.StringValue ?? string.Empty
|
||||
};
|
||||
|
||||
var responseObj = new
|
||||
{
|
||||
BoolValues = boolFeedback,
|
||||
IntValues = intFeedback,
|
||||
SerialValues = stringFeedback
|
||||
};
|
||||
|
||||
var js = JsonConvert.SerializeObject(responseObj, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,78 +4,74 @@ using Newtonsoft.Json;
|
|||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class GetJoinMapForBridgeKeyRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetJoinMapForBridgeKeyRequestHandler
|
||||
/// </summary>
|
||||
public class GetJoinMapForBridgeKeyRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetJoinMapForBridgeKeyRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetJoinMapForBridgeKeyRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
object bridgeObj;
|
||||
if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj))
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object bridgeObj;
|
||||
if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var bridge = DeviceManager.GetDeviceForKey(bridgeObj.ToString()) as EiscApiAdvanced;
|
||||
if (bridge == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var joinMap = bridge.JoinMaps.Select(j => EssentialsWebApiHelpers.MapJoinToObject(j)).ToList();
|
||||
if (joinMap == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var bridge = DeviceManager.GetDeviceForKey(bridgeObj.ToString()) as EiscApiAdvanced;
|
||||
if (bridge == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var joinMap = bridge.JoinMaps.Select(j => EssentialsWebApiHelpers.MapJoinToObject(j)).ToList();
|
||||
if (joinMap == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -3,96 +3,92 @@ using Newtonsoft.Json;
|
|||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class GetJoinMapForDeviceKeyRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetJoinMapForDeviceKeyRequestHandler
|
||||
/// </summary>
|
||||
public class GetJoinMapForDeviceKeyRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetJoinMapForDeviceKeyRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetJoinMapForDeviceKeyRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object bridgeObj;
|
||||
if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var bridge = DeviceManager.GetDeviceForKey(bridgeObj.ToString()) as EiscApiAdvanced;
|
||||
if (bridge == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
JoinMapBaseAdvanced deviceJoinMap;
|
||||
if (!bridge.JoinMaps.TryGetValue(deviceObj.ToString(), out deviceJoinMap))
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var joinMap = EssentialsWebApiHelpers.MapJoinToObject(deviceObj.ToString(), deviceJoinMap);
|
||||
var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
});
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object bridgeObj;
|
||||
if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var bridge = DeviceManager.GetDeviceForKey(bridgeObj.ToString()) as EiscApiAdvanced;
|
||||
if (bridge == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
JoinMapBaseAdvanced deviceJoinMap;
|
||||
if (!bridge.JoinMaps.TryGetValue(deviceObj.ToString(), out deviceJoinMap))
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var joinMap = EssentialsWebApiHelpers.MapJoinToObject(deviceObj.ToString(), deviceJoinMap);
|
||||
var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
});
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -3,71 +3,49 @@ using Crestron.SimplSharp.WebScripting;
|
|||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class GetRoutesHandler:WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetRoutesHandler
|
||||
/// </summary>
|
||||
public class GetRoutesHandler:WebApiBaseRequestHandler
|
||||
{
|
||||
private HttpCwsRouteCollection routeCollection;
|
||||
private string basePath;
|
||||
private HttpCwsRouteCollection routeCollection;
|
||||
private string basePath;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="routeCollection"></param>
|
||||
/// <param name="basePath"></param>
|
||||
public GetRoutesHandler(HttpCwsRouteCollection routeCollection, string basePath) {
|
||||
this.routeCollection = routeCollection;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var currentIp = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
|
||||
var hostname = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
|
||||
|
||||
var path = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
|
||||
? $"https://{hostname}/VirtualControl/Rooms/{InitialParametersClass.RoomId}/cws{basePath}"
|
||||
: $"https://{currentIp}/cws{basePath}";
|
||||
|
||||
var response = JsonConvert.SerializeObject(new RoutesResponseObject()
|
||||
{
|
||||
Url = path,
|
||||
Routes = routeCollection
|
||||
});
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.Headers.Add("Content-Type", "application/json");
|
||||
context.Response.Write(response, false);
|
||||
context.Response.End();
|
||||
}
|
||||
public GetRoutesHandler(HttpCwsRouteCollection routeCollection, string basePath) {
|
||||
this.routeCollection = routeCollection;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a RoutesResponseObject
|
||||
/// </summary>
|
||||
public class RoutesResponseObject
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Url
|
||||
/// </summary>
|
||||
[JsonProperty("url")]
|
||||
public string Url { set; get; }
|
||||
var currentIp = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Routes
|
||||
/// </summary>
|
||||
[JsonProperty("routes")]
|
||||
public HttpCwsRouteCollection Routes { get; set; }
|
||||
var hostname = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
|
||||
|
||||
var path = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
|
||||
? $"https://{hostname}/VirtualControl/Rooms/{InitialParametersClass.RoomId}/cws{basePath}"
|
||||
: $"https://{currentIp}/cws{basePath}";
|
||||
|
||||
var response = JsonConvert.SerializeObject(new RoutesResponseObject()
|
||||
{
|
||||
Url = path,
|
||||
Routes = routeCollection
|
||||
});
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.Headers.Add("Content-Type", "application/json");
|
||||
context.Response.Write(response, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
public class RoutesResponseObject
|
||||
{
|
||||
[JsonProperty("url")]
|
||||
public string Url { set; get; }
|
||||
|
||||
[JsonProperty("routes")]
|
||||
public HttpCwsRouteCollection Routes { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,83 +5,66 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class GetRoutingPortsHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetRoutingPortsHandler
|
||||
/// </summary>
|
||||
public class GetRoutingPortsHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public GetRoutingPortsHandler() : base(true) { }
|
||||
public GetRoutingPortsHandler() : base(true) { }
|
||||
|
||||
/// <summary>
|
||||
/// Handles the GET request
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
|
||||
if (routeData == null)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!routeData.Values.TryGetValue("deviceKey", out var deviceKey))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceKey.ToString());
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Device Not Found";
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
var inputPorts = (device as IRoutingInputs)?.InputPorts;
|
||||
var outputPorts = (device as IRoutingOutputs)?.OutputPorts;
|
||||
|
||||
var response = JsonConvert.SerializeObject( new ReturnValue
|
||||
{
|
||||
InputPorts = inputPorts?.Select(p => p.Key).ToList(),
|
||||
OutputPorts = outputPorts?.Select(p => p.Key).ToList()
|
||||
});
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(response, false);
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
internal class ReturnValue
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the InputPorts
|
||||
/// </summary>
|
||||
[JsonProperty("inputPorts", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<string> InputPorts { get; set; }
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out var deviceKey))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
var device = DeviceManager.GetDeviceForKey(deviceKey.ToString());
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Device Not Found";
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
var inputPorts = (device as IRoutingInputs)?.InputPorts;
|
||||
var outputPorts = (device as IRoutingOutputs)?.OutputPorts;
|
||||
|
||||
var response = JsonConvert.SerializeObject(new ReturnValue
|
||||
{
|
||||
InputPorts = inputPorts?.Select(p => p.Key).ToList(),
|
||||
OutputPorts = outputPorts?.Select(p => p.Key).ToList()
|
||||
});
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(response, false);
|
||||
context.Response.End();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the OutputPorts
|
||||
/// </summary>
|
||||
[JsonProperty("outputPorts", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<string> OutputPorts { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
internal class ReturnValue
|
||||
{
|
||||
[JsonProperty("inputPorts", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<string> InputPorts { get; set; }
|
||||
|
||||
[JsonProperty("outputPorts", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<string> OutputPorts { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,32 @@
|
|||
using Crestron.SimplSharp.WebScripting;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
public class GetTieLinesRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetTieLinesRequestHandler
|
||||
/// </summary>
|
||||
public class GetTieLinesRequestHandler : WebApiBaseRequestHandler
|
||||
public GetTieLinesRequestHandler() : base(true) { }
|
||||
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public GetTieLinesRequestHandler() : base(true) { }
|
||||
|
||||
/// <summary>
|
||||
/// Handles the GET request
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
var tieLineString = JsonConvert.SerializeObject(TieLineCollection.Default.Select((tl) => new
|
||||
{
|
||||
var tieLineString = JsonConvert.SerializeObject(TieLineCollection.Default.Select((tl) => new
|
||||
{
|
||||
sourceKey = tl.SourcePort.ParentDevice.Key,
|
||||
sourcePort = tl.SourcePort.Key,
|
||||
destinationKey = tl.DestinationPort.ParentDevice.Key,
|
||||
destinationPort = tl.DestinationPort.Key,
|
||||
type = tl.Type.ToString(),
|
||||
}));
|
||||
sourceKey = tl.SourcePort.ParentDevice.Key,
|
||||
sourcePort = tl.SourcePort.Key,
|
||||
destinationKey = tl.DestinationPort.ParentDevice.Key,
|
||||
destinationPort = tl.DestinationPort.Key,
|
||||
type = tl.Type.ToString(),
|
||||
}));
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(tieLineString, false);
|
||||
context.Response.End();
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.Write(tieLineString, false);
|
||||
context.Response.End();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,69 +3,68 @@ using Crestron.SimplSharp.WebScripting;
|
|||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests for types of devices based on a filter. The filter is used to determine which device factory to pull types from. The filter is passed as part of the URL and is accessed via the RouteData property of the HttpCwsContext.
|
||||
/// </summary>
|
||||
public class GetTypesByFilterRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetTypesByFilterRequestHandler
|
||||
/// </summary>
|
||||
public class GetTypesByFilterRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetTypesByFilterRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetTypesByFilterRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object filterObj;
|
||||
if (!routeData.Values.TryGetValue("filter", out filterObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceFactory = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString());
|
||||
if (deviceFactory == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceTypes = deviceFactory.Select(t => EssentialsWebApiHelpers.MapDeviceTypeToObject(t)).ToList();
|
||||
var js = JsonConvert.SerializeObject(deviceTypes, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object filterObj;
|
||||
if (!routeData.Values.TryGetValue("filter", out filterObj))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceFactory = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString());
|
||||
if (deviceFactory == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceTypes = deviceFactory.Select(t => EssentialsWebApiHelpers.MapDeviceTypeToObject(t)).ToList();
|
||||
var js = JsonConvert.SerializeObject(deviceTypes, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -3,59 +3,58 @@ using Crestron.SimplSharp.WebScripting;
|
|||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests for types of devices. This handler is used when no filter is needed to determine which device factory to pull types from. If a filter is needed, use the GetTypesByFilterRequestHandler instead.
|
||||
/// </summary>
|
||||
public class GetTypesRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a GetTypesRequestHandler
|
||||
/// </summary>
|
||||
public class GetTypesRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetTypesRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public GetTypesRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceFactory = DeviceFactory.GetDeviceFactoryDictionary(null);
|
||||
if (deviceFactory == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceTypes = deviceFactory.Select(t => EssentialsWebApiHelpers.MapDeviceTypeToObject(t)).ToList();
|
||||
var js = JsonConvert.SerializeObject(deviceTypes, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceFactory = DeviceFactory.GetDeviceFactoryDictionary(null);
|
||||
if (deviceFactory == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var deviceTypes = deviceFactory.Select(t => EssentialsWebApiHelpers.MapDeviceTypeToObject(t)).ToList();
|
||||
var js = JsonConvert.SerializeObject(deviceTypes, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +1,38 @@
|
|||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests to load the config. This is used when the config is loaded via the web API instead of at startup. This is typically used in conjunction with the SaveConfigRequestHandler to allow for saving and loading of the config via the web API.
|
||||
/// </summary>
|
||||
public class LoadConfigRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a LoadConfigRequestHandler
|
||||
/// </summary>
|
||||
public class LoadConfigRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public LoadConfigRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public LoadConfigRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
var message = "";
|
||||
var cs = Global.ControlSystem as ILoadConfig;
|
||||
if(cs != null)
|
||||
cs.GoWithLoad();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(message, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
var message = "";
|
||||
var cs = Global.ControlSystem as ILoadConfig;
|
||||
if (cs != null)
|
||||
cs.GoWithLoad();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(message, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -3,50 +3,49 @@ using Crestron.SimplSharp.WebScripting;
|
|||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests for reporting versions of loaded assemblies. This is used to report the versions of the assemblies that are currently loaded in the system, which can be helpful for debugging and support purposes.
|
||||
/// </summary>
|
||||
public class ReportVersionsRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a ReportVersionsRequestHandler
|
||||
/// </summary>
|
||||
public class ReportVersionsRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public ReportVersionsRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public ReportVersionsRequestHandler()
|
||||
: base(true)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var loadAssemblies = PluginLoader.LoadedAssemblies;
|
||||
if (loadAssemblies == null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var loadAssemblies = PluginLoader.LoadedAssemblies;
|
||||
if (loadAssemblies == null)
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var assemblies = loadAssemblies.Select(a => EssentialsWebApiHelpers.MapToAssemblyObject(a)).ToList();
|
||||
|
||||
var js = JsonConvert.SerializeObject(assemblies, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var assemblies = loadAssemblies.Select(a => EssentialsWebApiHelpers.MapToAssemblyObject(a)).ToList();
|
||||
|
||||
var js = JsonConvert.SerializeObject(assemblies, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +1,39 @@
|
|||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests to restart the program.
|
||||
/// This is used when the program needs to be restarted via the web API instead of manually restarting the program.
|
||||
/// </summary>
|
||||
public class RestartProgramRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a RestartProgramRequestHandler
|
||||
/// </summary>
|
||||
public class RestartProgramRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public RestartProgramRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public RestartProgramRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
var message = "";
|
||||
if(CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
|
||||
CrestronConsole.SendControlSystemCommand($"progres -p:{InitialParametersClass.ApplicationNumber}", ref message);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(message, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
var message = "";
|
||||
if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
|
||||
CrestronConsole.SendControlSystemCommand($"progres -p:{InitialParametersClass.ApplicationNumber}", ref message);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(message, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,228 +4,230 @@ using Newtonsoft.Json;
|
|||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests for setting stream debugging on devices that support it.
|
||||
/// The request is expected to be a POST with a JSON body that includes the device key, the desired debug setting, and an optional timeout in minutes.
|
||||
/// The handler will attempt to find the device by key, cast it to IStreamDebugging, and then set the debugging according to the provided setting and timeout.
|
||||
/// If any step fails, an appropriate HTTP error response is returned.
|
||||
/// </summary>
|
||||
public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a SetDeviceStreamDebugRequestHandler
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleConnect(HttpCwsContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleConnect(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles DELETE method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleDelete(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles HEAD method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleHead(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles OPTIONS method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleOptions(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PATCH method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePatch(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
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 (data == null)
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var config = new SetDeviceStreamDebugConfig();
|
||||
var body = JsonConvert.DeserializeAnonymousType(data, config);
|
||||
if (body == null)
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(body.DeviceKey) || string.IsNullOrEmpty(body.Setting))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(DeviceManager.GetDeviceForKey(body.DeviceKey) is IStreamDebugging device))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
eStreamDebuggingSetting debugSetting;
|
||||
try
|
||||
{
|
||||
debugSetting = (eStreamDebuggingSetting)Enum.Parse(typeof(eStreamDebuggingSetting), body.Setting, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage(ex, "Exception handling set debug request");
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var mins = Convert.ToUInt32(body.Timeout);
|
||||
if (mins > 0)
|
||||
{
|
||||
device.StreamDebugging.SetDebuggingWithSpecificTimeout(debugSetting, mins);
|
||||
}
|
||||
else
|
||||
{
|
||||
device.StreamDebugging.SetDebuggingWithDefaultTimeout(debugSetting);
|
||||
}
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage(ex, "Exception handling set debug request");
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PUT method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePut(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles TRACE method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleTrace(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configuration class for SetDeviceStreamDebugRequestHandler
|
||||
/// Handles DELETE method requests
|
||||
/// </summary>
|
||||
public class SetDeviceStreamDebugConfig
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleDelete(HttpCwsContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the DeviceKey
|
||||
/// </summary>
|
||||
[JsonProperty("deviceKey", NullValueHandling = NullValueHandling.Include)]
|
||||
public string DeviceKey { get; set; }
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Setting
|
||||
/// </summary>
|
||||
[JsonProperty("setting", NullValueHandling = NullValueHandling.Include)]
|
||||
public string Setting { get; set; }
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Timeout
|
||||
/// </summary>
|
||||
[JsonProperty("timeout")]
|
||||
public int Timeout { get; set; }
|
||||
/// <summary>
|
||||
/// Handles HEAD method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleHead(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public SetDeviceStreamDebugConfig()
|
||||
/// <summary>
|
||||
/// Handles OPTIONS method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleOptions(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PATCH method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePatch(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
if (context.Request.ContentLength < 0)
|
||||
{
|
||||
DeviceKey = null;
|
||||
Setting = null;
|
||||
Timeout = 15;
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var data = context.Request.GetRequestBody();
|
||||
if (data == null)
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var config = new SetDeviceStreamDebugConfig();
|
||||
var body = JsonConvert.DeserializeAnonymousType(data, config);
|
||||
if (body == null)
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(body.DeviceKey) || string.IsNullOrEmpty(body.Setting))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(DeviceManager.GetDeviceForKey(body.DeviceKey) is IStreamDebugging device))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
context.Response.StatusDescription = "Not Found";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
eStreamDebuggingSetting debugSetting;
|
||||
try
|
||||
{
|
||||
debugSetting = (eStreamDebuggingSetting)Enum.Parse(typeof(eStreamDebuggingSetting), body.Setting, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage(ex, "Exception handling set debug request");
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var mins = Convert.ToUInt32(body.Timeout);
|
||||
if (mins > 0)
|
||||
{
|
||||
device.StreamDebugging.SetDebuggingWithSpecificTimeout(debugSetting, mins);
|
||||
}
|
||||
else
|
||||
{
|
||||
device.StreamDebugging.SetDebuggingWithDefaultTimeout(debugSetting);
|
||||
}
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage(ex, "Exception handling set debug request");
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PUT method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePut(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles TRACE method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleTrace(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configuration class for SetDeviceStreamDebugRequestHandler
|
||||
/// </summary>
|
||||
public class SetDeviceStreamDebugConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the DeviceKey
|
||||
/// </summary>
|
||||
[JsonProperty("deviceKey", NullValueHandling = NullValueHandling.Include)]
|
||||
public string DeviceKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Setting
|
||||
/// </summary>
|
||||
[JsonProperty("setting", NullValueHandling = NullValueHandling.Include)]
|
||||
public string Setting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Timeout
|
||||
/// </summary>
|
||||
[JsonProperty("timeout")]
|
||||
public int Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public SetDeviceStreamDebugConfig()
|
||||
{
|
||||
DeviceKey = null;
|
||||
Setting = null;
|
||||
Timeout = 15;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,38 +3,39 @@ using Newtonsoft.Json;
|
|||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests to show the current config.
|
||||
/// This is used to display the current config via the web API.
|
||||
/// The config is returned as a JSON string.
|
||||
/// </summary>
|
||||
public class ShowConfigRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a ShowConfigRequestHandler
|
||||
/// </summary>
|
||||
public class ShowConfigRequestHandler : WebApiBaseRequestHandler
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public ShowConfigRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public ShowConfigRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var config = JsonConvert.SerializeObject(ConfigReader.ConfigObject, Formatting.Indented);
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var config = JsonConvert.SerializeObject(ConfigReader.ConfigObject, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(config, false);
|
||||
context.Response.End();
|
||||
}
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(config, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue