diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs
index a37a78c0..f953443b 100644
--- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs
+++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs
@@ -144,17 +144,17 @@ namespace PepperDash.Essentials.Core.Web
Name = "GetJoinMapsForDeviceKey",
RouteHandler = new GetJoinMapForDeviceKeyRequestHandler()
},
- new HttpCwsRoute("debugSession")
- {
- Name = "DebugSession",
- RouteHandler = new DebugSessionRequestHandler()
- },
- new HttpCwsRoute("doNotLoadConfigOnNextBoot")
- {
- Name = "DoNotLoadConfigOnNextBoot",
- RouteHandler = new DoNotLoadConfigOnNextBootRequestHandler()
- },
- new HttpCwsRoute("restartProgram")
+ 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()
@@ -164,12 +164,16 @@ namespace PepperDash.Essentials.Core.Web
Name = "Load Config",
RouteHandler = new LoadConfigRequestHandler()
},
- new HttpCwsRoute("getTielines")
+ 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);
@@ -196,13 +200,18 @@ namespace PepperDash.Essentials.Core.Web
}
}
- ///
- /// Initializes the CWS class
- ///
- public override void Initialize()
+ ///
+ /// Initializes the CWS class
+ ///
+ public override void Initialize()
{
- // If running on an appliance
- if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
+ AddRoute(new HttpCwsRoute("apiPaths") {
+ Name = "GetPaths",
+ RouteHandler = new GetRoutesHandler(_server.GetRouteCollection())
+ });
+
+ // If running on an appliance
+ if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
{
/*
WEBSERVER [ON | OFF | TIMEOUT | MAXSESSIONSPERUSER ]
@@ -247,8 +256,8 @@ namespace PepperDash.Essentials.Core.Web
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
var path = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
- ? $"http(s)://{hostname}/VirtualControl/Rooms/{InitialParametersClass.RoomId}/cws{BasePath}"
- : $"http(s)://{currentIp}/cws{BasePath}";
+ ? $"https://{hostname}/VirtualControl/Rooms/{InitialParametersClass.RoomId}/cws{BasePath}"
+ : $"https://{currentIp}/cws{BasePath}";
Debug.LogMessage(LogEventLevel.Information, this, "Server:{path:l}", path);
diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetRoutesHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetRoutesHandler.cs
new file mode 100644
index 00000000..a1042a77
--- /dev/null
+++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetRoutesHandler.cs
@@ -0,0 +1,25 @@
+using Crestron.SimplSharp.WebScripting;
+using Newtonsoft.Json;
+using PepperDash.Core.Web.RequestHandlers;
+
+namespace PepperDash.Essentials.Core.Web.RequestHandlers
+{
+ public class GetRoutesHandler:WebApiBaseRequestHandler
+ {
+ private HttpCwsRouteCollection routeCollection;
+ public GetRoutesHandler(HttpCwsRouteCollection routeCollection) {
+ this.routeCollection = routeCollection;
+ }
+
+ protected override void HandleGet(HttpCwsContext context)
+ {
+ var response = JsonConvert.SerializeObject(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();
+ }
+ }
+}
diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetRoutingPortsHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetRoutingPortsHandler.cs
new file mode 100644
index 00000000..6e033f06
--- /dev/null
+++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetRoutingPortsHandler.cs
@@ -0,0 +1,70 @@
+using Crestron.SimplSharp.WebScripting;
+using Newtonsoft.Json;
+using PepperDash.Core.Web.RequestHandlers;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace PepperDash.Essentials.Core.Web.RequestHandlers
+{
+ public class GetRoutingPortsHandler : WebApiBaseRequestHandler
+ {
+ public GetRoutingPortsHandler() : base(true) { }
+
+ 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;
+ }
+
+ 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();
+
+ }
+ }
+
+ internal class ReturnValue {
+ [JsonProperty("inputPorts", NullValueHandling = NullValueHandling.Ignore)]
+ public List InputPorts { get; set; }
+
+ [JsonProperty("outputPorts", NullValueHandling = NullValueHandling.Ignore)]
+ public List OutputPorts { get; set; }
+ }
+}