Compare commits

...

6 Commits

Author SHA1 Message Date
Neil Dorin
d3719ee505 Merge pull request #1230 from PepperDash/room-loading-protections 2025-03-31 11:58:14 -06:00
Andrew Welker
041059210c fix: add null check for room before adding to DevManager 2025-03-31 12:53:44 -05:00
Andrew Welker
65a0743dac Merge pull request #1228 from PepperDash/add-routes
fix: add routes to get routing ports & all defined routes
2025-03-28 10:50:04 -05:00
Andrew Welker
32e090648c fix: add missing parameter for GetRoutesHandler 2025-03-28 10:41:21 -05:00
Andrew Welker
bb045ba06b fix: add base URL to routes response 2025-03-28 10:32:16 -05:00
Andrew Welker
474b2eb647 fix: add routes to get routing ports & all defined routes 2025-03-28 10:25:17 -05:00
4 changed files with 157 additions and 24 deletions

View File

@@ -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
}
}
/// <summary>
/// Initializes the CWS class
/// </summary>
public override void Initialize()
/// <summary>
/// Initializes the CWS class
/// </summary>
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(), BasePath)
});
// If running on an appliance
if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
{
/*
WEBSERVER [ON | OFF | TIMEOUT <VALUE IN SECONDS> | MAXSESSIONSPERUSER <Number of sessions>]
@@ -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);

View File

@@ -0,0 +1,52 @@
using Crestron.SimplSharp;
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;
private string basePath;
public GetRoutesHandler(HttpCwsRouteCollection routeCollection, string basePath) {
this.routeCollection = routeCollection;
this.basePath = basePath;
}
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 class RoutesResponseObject
{
[JsonProperty("url")]
public string Url { set; get; }
[JsonProperty("routes")]
public HttpCwsRouteCollection Routes { get; set; }
}
}

View File

@@ -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<string> InputPorts { get; set; }
[JsonProperty("outputPorts", NullValueHandling = NullValueHandling.Ignore)]
public List<string> OutputPorts { get; set; }
}
}

View File

@@ -483,11 +483,13 @@ namespace PepperDash.Essentials
{
var room = Core.DeviceFactory.GetDevice(roomConfig);
DeviceManager.AddDevice(room);
if (room is ICustomMobileControl)
if(room == null)
{
Debug.LogWarning("ERROR: Cannot load unknown room type '{roomType:l}', key '{roomKey:l}'.", roomConfig.Type, roomConfig.Key);
continue;
}
DeviceManager.AddDevice(room);
} catch (Exception ex)
{
Debug.LogMessage(ex, "Exception loading room {roomKey}:{roomType}", null, roomConfig.Key, roomConfig.Type);