From c14e5fe449c769fa6c0fcd00333ee67d2b422884 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 11 Jan 2023 13:57:25 -0600 Subject: [PATCH 01/26] fix: issue registering versiport digital outputs --- .../Bridges/JoinMaps/IAnalogInputJoinMap.cs | 34 + .../Bridges/JoinMaps/IDigitalInputJoinMap.cs | 2 +- .../Crestron IO/IOPortConfig.cs | 2 + .../GenericVersiportAnalogInputDevice.cs | 208 +++++ .../Crestron IO/Inputs/IAnalogInput.cs | 14 + .../Outputs/GenericVersiportOutputDevice.cs | 78 +- .../PepperDash_Essentials_Core.csproj | 3 + .../Routing/IRoutingInputsExtensions.cs | 834 +++++++++--------- 8 files changed, 724 insertions(+), 451 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IAnalogInputJoinMap.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportAnalogInputDevice.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/IAnalogInput.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IAnalogInputJoinMap.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IAnalogInputJoinMap.cs new file mode 100644 index 00000000..eaf70f3a --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IAnalogInputJoinMap.cs @@ -0,0 +1,34 @@ +using System; + +namespace PepperDash.Essentials.Core.Bridges +{ + public class IAnalogInputJoinMap : JoinMapBaseAdvanced + { + + [JoinName("InputValue")] + public JoinDataComplete InputValue = new JoinDataComplete(new JoinData { JoinNumber = 1, JoinSpan = 1 }, + new JoinMetadata { Description = "Input Value", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Analog }); + [JoinName("MinimumChange")] + public JoinDataComplete MinimumChange = new JoinDataComplete(new JoinData { JoinNumber = 2, JoinSpan = 1 }, + new JoinMetadata { Description = "Minimum voltage change required to reflect a change", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Analog }); + + /// + /// Constructor to use when instantiating this Join Map without inheriting from it + /// + /// Join this join map will start at + public IAnalogInputJoinMap(uint joinStart) + : this(joinStart, typeof(IAnalogInputJoinMap)) + { + } + + /// + /// Constructor to use when extending this Join map + /// + /// Join this join map will start at + /// Type of the child join map + protected IAnalogInputJoinMap(uint joinStart, Type type) + : base(joinStart, type) + { + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IDigitalInputJoinMap.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IDigitalInputJoinMap.cs index 82c09e54..83e6cdab 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IDigitalInputJoinMap.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/IDigitalInputJoinMap.cs @@ -7,7 +7,7 @@ namespace PepperDash.Essentials.Core.Bridges [JoinName("InputState")] public JoinDataComplete InputState = new JoinDataComplete(new JoinData { JoinNumber = 1, JoinSpan = 1 }, - new JoinMetadata { Description = "Room Email Url", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Digital }); + new JoinMetadata { Description = "Input State", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Digital }); /// /// Constructor to use when instantiating this Join Map without inheriting from it diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/IOPortConfig.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/IOPortConfig.cs index 09061ff2..5fbe10e1 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/IOPortConfig.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/IOPortConfig.cs @@ -15,5 +15,7 @@ namespace PepperDash.Essentials.Core.CrestronIO public uint PortNumber { get; set; } [JsonProperty("disablePullUpResistor")] public bool DisablePullUpResistor { get; set; } + [JsonProperty("minimumChange")] + public int MinimumChange { get; set; } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportAnalogInputDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportAnalogInputDevice.cs new file mode 100644 index 00000000..70be2f6f --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportAnalogInputDevice.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro.DeviceSupport; + +using PepperDash.Core; +using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Core.Bridges; + + +using Newtonsoft.Json; + +namespace PepperDash.Essentials.Core.CrestronIO +{ + /// + /// Represents a generic digital input deviced tied to a versiport + /// + public class GenericVersiportAnalogInputDevice : EssentialsBridgeableDevice, IAnalogInput + { + public Versiport InputPort { get; private set; } + + public IntFeedback InputValueFeedback { get; private set; } + public IntFeedback InputMinimumChangeFeedback { get; private set; } + + Func InputValueFeedbackFunc + { + get + { + return () => InputPort.AnalogIn; + } + } + + Func InputMinimumChangeFeedbackFunc + { + get { return () => InputPort.AnalogMinChange; } + } + + public GenericVersiportAnalogInputDevice(string key, string name, Func postActivationFunc, IOPortConfig config) : + base(key, name) + { + InputValueFeedback = new IntFeedback(InputValueFeedbackFunc); + InputMinimumChangeFeedback = new IntFeedback(InputMinimumChangeFeedbackFunc); + + AddPostActivationAction(() => + { + InputPort = postActivationFunc(config); + + InputPort.Register(); + + InputPort.SetVersiportConfiguration(eVersiportConfiguration.AnalogInput); + InputPort.AnalogMinChange = (ushort)(config.MinimumChange > 0 ? config.MinimumChange : 655); + if (config.DisablePullUpResistor) + InputPort.DisablePullUpResistor = true; + + InputPort.VersiportChange += InputPort_VersiportChange; + + Debug.Console(1, this, "Created GenericVersiportAnalogInputDevice on port '{0}'. DisablePullUpResistor: '{1}'", config.PortNumber, InputPort.DisablePullUpResistor); + + }); + + } + + /// + /// Set minimum voltage change for device to update voltage changed method + /// + /// valid values range from 0 - 65535, representing the full 100% range of the processor voltage source. Check processor documentation for details + public void SetMinimumChange(ushort value) + { + InputPort.AnalogMinChange = value; + } + + void InputPort_VersiportChange(Versiport port, VersiportEventArgs args) + { + Debug.Console(1, this, "Versiport change: {0}", args.Event); + + if(args.Event == eVersiportEvent.AnalogInChange) + InputValueFeedback.FireUpdate(); + if (args.Event == eVersiportEvent.AnalogMinChangeChange) + InputMinimumChangeFeedback.FireUpdate(); + } + + + #region Bridge Linking + + public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) + { + var joinMap = new IAnalogInputJoinMap(joinStart); + + var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); + + if (!string.IsNullOrEmpty(joinMapSerialized)) + joinMap = JsonConvert.DeserializeObject(joinMapSerialized); + + if (bridge != null) + { + bridge.AddJoinMap(Key, joinMap); + } + else + { + Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device."); + } + + try + { + Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); + + // Link feedback for input state + InputValueFeedback.LinkInputSig(trilist.UShortInput[joinMap.InputValue.JoinNumber]); + InputMinimumChangeFeedback.LinkInputSig(trilist.UShortInput[joinMap.MinimumChange.JoinNumber]); + trilist.SetUShortSigAction(joinMap.MinimumChange.JoinNumber, SetMinimumChange); + + } + catch (Exception e) + { + Debug.Console(1, this, "Unable to link device '{0}'. Input is null", Key); + Debug.Console(1, this, "Error: {0}", e); + } + + trilist.OnlineStatusChange += (d, args) => + { + if (!args.DeviceOnLine) return; + InputValueFeedback.FireUpdate(); + InputMinimumChangeFeedback.FireUpdate(); + }; + + } + + void trilist_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args) + { + throw new NotImplementedException(); + } + + #endregion + + + public static Versiport GetVersiportDigitalInput(IOPortConfig dc) + { + + IIOPorts ioPortDevice; + + if (dc.PortDeviceKey.Equals("processor")) + { + if (!Global.ControlSystem.SupportsVersiport) + { + Debug.Console(0, "GetVersiportAnalogInput: Processor does not support Versiports"); + return null; + } + ioPortDevice = Global.ControlSystem; + } + else + { + var ioPortDev = DeviceManager.GetDeviceForKey(dc.PortDeviceKey) as IIOPorts; + if (ioPortDev == null) + { + Debug.Console(0, "GetVersiportAnalogInput: Device {0} is not a valid device", dc.PortDeviceKey); + return null; + } + ioPortDevice = ioPortDev; + } + if (ioPortDevice == null) + { + Debug.Console(0, "GetVersiportAnalogInput: Device '0' is not a valid IIOPorts Device", dc.PortDeviceKey); + return null; + } + + if (dc.PortNumber > ioPortDevice.NumberOfVersiPorts) + { + Debug.Console(0, "GetVersiportAnalogInput: Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber); + return null; + } + if(!ioPortDevice.VersiPorts[dc.PortNumber].SupportsAnalogInput) + { + Debug.Console(0, "GetVersiportAnalogInput: Device {0} does not support AnalogInput on port {1}", dc.PortDeviceKey, dc.PortNumber); + return null; + } + + + return ioPortDevice.VersiPorts[dc.PortNumber]; + + + } + } + + + public class GenericVersiportAbalogInputDeviceFactory : EssentialsDeviceFactory + { + public GenericVersiportAbalogInputDeviceFactory() + { + TypeNames = new List() { "versiportanaloginput" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Versiport Device"); + + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + if (props == null) return null; + + var portDevice = new GenericVersiportAnalogInputDevice(dc.Key, dc.Name, GenericVersiportAnalogInputDevice.GetVersiportDigitalInput, props); + + return portDevice; + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/IAnalogInput.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/IAnalogInput.cs new file mode 100644 index 00000000..44af9954 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/IAnalogInput.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using PepperDash.Essentials.Core; + +namespace PepperDash.Essentials.Core.CrestronIO +{ + public interface IAnalogInput + { + IntFeedback InputValueFeedback { get; } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs index 77037845..2d1ae9c4 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Outputs/GenericVersiportOutputDevice.cs @@ -42,18 +42,19 @@ namespace PepperDash.Essentials.Core.CrestronIO OutputPort = postActivationFunc(config); OutputPort.Register(); + + if (!OutputPort.SupportsDigitalOutput) { Debug.Console(0, this, "Device does not support configuration as a Digital Output"); return; } + OutputPort.SetVersiportConfiguration(eVersiportConfiguration.DigitalOutput); + + OutputPort.VersiportChange += OutputPort_VersiportChange; - - - Debug.Console(1, this, "Created GenericVersiportDigitalOutputDevice on port '{0}'.", config.PortNumber); - }); } @@ -72,7 +73,18 @@ namespace PepperDash.Essentials.Core.CrestronIO /// value to set the output to public void SetOutput(bool state) { - OutputPort.DigitalOut = state; + if (OutputPort.SupportsDigitalOutput) + { + Debug.Console(0, this, "Passed the Check"); + + OutputPort.DigitalOut = state; + + } + else + { + Debug.Console(0, this, "Versiport does not support Digital Output Mode"); + } + } #region Bridge Linking @@ -115,40 +127,40 @@ namespace PepperDash.Essentials.Core.CrestronIO public static Versiport GetVersiportDigitalOutput(IOPortConfig dc) { - - IIOPorts ioPortDevice; - if (dc.PortDeviceKey.Equals("processor")) - { - if (!Global.ControlSystem.SupportsVersiport) + IIOPorts ioPortDevice; + + if (dc.PortDeviceKey.Equals("processor")) { - Debug.Console(0, "GetVersiportDigitalOuptut: Processor does not support Versiports"); + if (!Global.ControlSystem.SupportsVersiport) + { + Debug.Console(0, "GetVersiportDigitalOuptut: Processor does not support Versiports"); + return null; + } + ioPortDevice = Global.ControlSystem; + } + else + { + var ioPortDev = DeviceManager.GetDeviceForKey(dc.PortDeviceKey) as IIOPorts; + if (ioPortDev == null) + { + Debug.Console(0, "GetVersiportDigitalOuptut: Device {0} is not a valid device", dc.PortDeviceKey); + return null; + } + ioPortDevice = ioPortDev; + } + if (ioPortDevice == null) + { + Debug.Console(0, "GetVersiportDigitalOuptut: Device '0' is not a valid IOPorts Device", dc.PortDeviceKey); return null; } - ioPortDevice = Global.ControlSystem; - } - else - { - var ioPortDev = DeviceManager.GetDeviceForKey(dc.PortDeviceKey) as IIOPorts; - if (ioPortDev == null) + + if (dc.PortNumber > ioPortDevice.NumberOfVersiPorts) { - Debug.Console(0, "GetVersiportDigitalOuptut: Device {0} is not a valid device", dc.PortDeviceKey); - return null; + Debug.Console(0, "GetVersiportDigitalOuptut: Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber); } - ioPortDevice = ioPortDev; - } - if (ioPortDevice == null) - { - Debug.Console(0, "GetVersiportDigitalOuptut: Device '0' is not a valid IIOPorts Device", dc.PortDeviceKey); - return null; - } - - if (dc.PortNumber > ioPortDevice.NumberOfVersiPorts) - { - Debug.Console(0, "GetVersiportDigitalOuptut: Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber); - } - - return ioPortDevice.VersiPorts[dc.PortNumber]; + var port = ioPortDevice.VersiPorts[dc.PortNumber]; + return port; } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 2cf2928c..268d4f12 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -123,6 +123,7 @@ + @@ -182,8 +183,10 @@ + + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Routing/IRoutingInputsExtensions.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Routing/IRoutingInputsExtensions.cs index d371c2d6..4cd0d4ff 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Routing/IRoutingInputsExtensions.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Routing/IRoutingInputsExtensions.cs @@ -1,425 +1,425 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Crestron.SimplSharpPro; -using Crestron.SimplSharpPro.DM; - -using PepperDash.Core; - - -namespace PepperDash.Essentials.Core -{ - public class RouteRequest - { - public IRoutingSink Destination {get; set;} - public IRoutingOutputs Source {get; set;} - public eRoutingSignalType SignalType {get; set;} - - public void HandleCooldown(object sender, FeedbackEventArgs args) - { - var coolingDevice = sender as IWarmingCooling; - - if(args.BoolValue == false) - { - Destination.ReleaseAndMakeRoute(Source, SignalType); - - if(sender == null) return; - - coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown; - } - } - } - - /// - /// Extensions added to any IRoutingInputs classes to provide discovery-based routing - /// on those destinations. - /// - public static class IRoutingInputsExtensions - { - private static Dictionary RouteRequests = new Dictionary(); - /// - /// Gets any existing RouteDescriptor for a destination, clears it using ReleaseRoute - /// and then attempts a new Route and if sucessful, stores that RouteDescriptor - /// in RouteDescriptorCollection.DefaultCollection - /// - public static void ReleaseAndMakeRoute(this IRoutingSink destination, IRoutingOutputs source, eRoutingSignalType signalType) - { - var routeRequest = new RouteRequest { - Destination = destination, - Source = source, - SignalType = signalType - }; - - var coolingDevice = destination as IWarmingCooling; - - RouteRequest existingRouteRequest; - - //We already have a route request for this device, and it's a cooling device and is cooling - if (RouteRequests.TryGetValue(destination.Key, out existingRouteRequest) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true) - { - coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRouteRequest.HandleCooldown; - - coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown; - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro.DM; + +using PepperDash.Core; + + +namespace PepperDash.Essentials.Core +{ + public class RouteRequest + { + public IRoutingSink Destination {get; set;} + public IRoutingOutputs Source {get; set;} + public eRoutingSignalType SignalType {get; set;} + + public void HandleCooldown(object sender, FeedbackEventArgs args) + { + var coolingDevice = sender as IWarmingCooling; + + if(args.BoolValue == false) + { + Destination.ReleaseAndMakeRoute(Source, SignalType); + + if(sender == null) return; + + coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown; + } + } + } + + /// + /// Extensions added to any IRoutingInputs classes to provide discovery-based routing + /// on those destinations. + /// + public static class IRoutingInputsExtensions + { + private static Dictionary RouteRequests = new Dictionary(); + /// + /// Gets any existing RouteDescriptor for a destination, clears it using ReleaseRoute + /// and then attempts a new Route and if sucessful, stores that RouteDescriptor + /// in RouteDescriptorCollection.DefaultCollection + /// + public static void ReleaseAndMakeRoute(this IRoutingSink destination, IRoutingOutputs source, eRoutingSignalType signalType) + { + var routeRequest = new RouteRequest { + Destination = destination, + Source = source, + SignalType = signalType + }; + + var coolingDevice = destination as IWarmingCooling; + + RouteRequest existingRouteRequest; + + //We already have a route request for this device, and it's a cooling device and is cooling + if (RouteRequests.TryGetValue(destination.Key, out existingRouteRequest) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true) + { + coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRouteRequest.HandleCooldown; + + coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown; + RouteRequests[destination.Key] = routeRequest; - Debug.Console(2, "******************************************************** Device: {0} is cooling down and already has a routing request stored. Storing new route request to route to source key: {1}", destination.Key, routeRequest.Source.Key); - - return; - } - - //New Request - if (coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true) - { - coolingDevice.IsCoolingDownFeedback.OutputChange -= routeRequest.HandleCooldown; - - coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown; - + Debug.Console(2, "******************************************************** Device: {0} is cooling down and already has a routing request stored. Storing new route request to route to source key: {1}", destination.Key, routeRequest.Source.Key); + + return; + } + + //New Request + if (coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true) + { + coolingDevice.IsCoolingDownFeedback.OutputChange -= routeRequest.HandleCooldown; + + coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown; + RouteRequests.Add(destination.Key, routeRequest); Debug.Console(2, "******************************************************** Device: {0} is cooling down. Storing route request to route to source key: {1}", destination.Key, routeRequest.Source.Key); - return; - } - - if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false) - { + return; + } + + if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false) + { RouteRequests.Remove(destination.Key); Debug.Console(2, "******************************************************** Device: {0} is NOT cooling down. Removing stored route request and routing to source key: {1}", destination.Key, routeRequest.Source.Key); - } - - destination.ReleaseRoute(); - - RunRouteRequest(routeRequest); - } - - public static void RunRouteRequest(RouteRequest request) - { - if (request.Source == null) return; - var newRoute = request.Destination.GetRouteToSource(request.Source, request.SignalType); - if (newRoute == null) return; - RouteDescriptorCollection.DefaultCollection.AddRouteDescriptor(newRoute); - Debug.Console(2, request.Destination, "Executing full route"); - newRoute.ExecuteRoutes(); - } - - /// - /// Will release the existing route on the destination, if it is found in - /// RouteDescriptorCollection.DefaultCollection - /// - /// - public static void ReleaseRoute(this IRoutingSink destination) - { - RouteRequest existingRequest; - - if (RouteRequests.TryGetValue(destination.Key, out existingRequest) && destination is IWarmingCooling) - { - var coolingDevice = destination as IWarmingCooling; - - coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRequest.HandleCooldown; - } - - RouteRequests.Remove(destination.Key); - - var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination); - if (current != null) - { - Debug.Console(1, destination, "Releasing current route: {0}", current.Source.Key); - current.ReleaseRoutes(); - } - } - - /// - /// Builds a RouteDescriptor that contains the steps necessary to make a route between devices. - /// Routes of type AudioVideo will be built as two separate routes, audio and video. If - /// a route is discovered, a new RouteDescriptor is returned. If one or both parts - /// of an audio/video route are discovered a route descriptor is returned. If no route is - /// discovered, then null is returned - /// - public static RouteDescriptor GetRouteToSource(this IRoutingSink destination, IRoutingOutputs source, eRoutingSignalType signalType) - { - var routeDescr = new RouteDescriptor(source, destination, signalType); - // if it's a single signal type, find the route - if ((signalType & (eRoutingSignalType.Audio & eRoutingSignalType.Video)) == (eRoutingSignalType.Audio & eRoutingSignalType.Video)) - { - Debug.Console(1, destination, "Attempting to build source route from {0}", source.Key); - if (!destination.GetRouteToSource(source, null, null, signalType, 0, routeDescr)) - routeDescr = null; - } - // otherwise, audioVideo needs to be handled as two steps. - else - { - Debug.Console(1, destination, "Attempting to build audio and video routes from {0}", source.Key); - var audioSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Audio, 0, routeDescr); - if (!audioSuccess) - Debug.Console(1, destination, "Cannot find audio route to {0}", source.Key); - var videoSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Video, 0, routeDescr); - if (!videoSuccess) - Debug.Console(1, destination, "Cannot find video route to {0}", source.Key); - if (!audioSuccess && !videoSuccess) - routeDescr = null; - } - - //Debug.Console(1, destination, "Route{0} discovered", routeDescr == null ? " NOT" : ""); - return routeDescr; - } - - /// - /// The recursive part of this. Will stop on each device, search its inputs for the - /// desired source and if not found, invoke this function for the each input port - /// hoping to find the source. - /// - /// - /// - /// The RoutingOutputPort whose link is being checked for a route - /// Prevents Devices from being twice-checked - /// This recursive function should not be called with AudioVideo - /// Just an informational counter - /// The RouteDescriptor being populated as the route is discovered - /// true if source is hit - static bool GetRouteToSource(this IRoutingInputs destination, IRoutingOutputs source, - RoutingOutputPort outputPortToUse, List alreadyCheckedDevices, - eRoutingSignalType signalType, int cycle, RouteDescriptor routeTable) - { - cycle++; - Debug.Console(2, "GetRouteToSource: {0} {1}--> {2}", cycle, source.Key, destination.Key); - - RoutingInputPort goodInputPort = null; - var destDevInputTies = TieLineCollection.Default.Where(t => - t.DestinationPort.ParentDevice == destination && (t.Type == signalType || (t.Type & (eRoutingSignalType.Audio | eRoutingSignalType.Video)) == (eRoutingSignalType.Audio | eRoutingSignalType.Video))); - - // find a direct tie - var directTie = destDevInputTies.FirstOrDefault( - t => t.DestinationPort.ParentDevice == destination - && t.SourcePort.ParentDevice == source); - if (directTie != null) // Found a tie directly to the source - { - goodInputPort = directTie.DestinationPort; - } - else // no direct-connect. Walk back devices. - { - Debug.Console(2, destination, "is not directly connected to {0}. Walking down tie lines", source.Key); - - // No direct tie? Run back out on the inputs' attached devices... - // Only the ones that are routing devices - var attachedMidpoints = destDevInputTies.Where(t => t.SourcePort.ParentDevice is IRoutingInputsOutputs); - - //Create a list for tracking already checked devices to avoid loops, if it doesn't already exist from previous iteration - if (alreadyCheckedDevices == null) - alreadyCheckedDevices = new List(); - alreadyCheckedDevices.Add(destination as IRoutingInputsOutputs); - - foreach (var inputTieToTry in attachedMidpoints) - { - var upstreamDeviceOutputPort = inputTieToTry.SourcePort; - var upstreamRoutingDevice = upstreamDeviceOutputPort.ParentDevice as IRoutingInputsOutputs; - Debug.Console(2, destination, "Trying to find route on {0}", upstreamRoutingDevice.Key); - - // Check if this previous device has already been walked - if (alreadyCheckedDevices.Contains(upstreamRoutingDevice)) - { - Debug.Console(2, destination, "Skipping input {0} on {1}, this was already checked", upstreamRoutingDevice.Key, destination.Key); - continue; - } - // haven't seen this device yet. Do it. Pass the output port to the next - // level to enable switching on success - var upstreamRoutingSuccess = upstreamRoutingDevice.GetRouteToSource(source, upstreamDeviceOutputPort, - alreadyCheckedDevices, signalType, cycle, routeTable); - if (upstreamRoutingSuccess) - { - Debug.Console(2, destination, "Upstream device route found"); - goodInputPort = inputTieToTry.DestinationPort; - break; // Stop looping the inputs in this cycle - } - } - } - - // we have a route on corresponding inputPort. *** Do the route *** - if (goodInputPort != null) - { - //Debug.Console(2, destination, "adding RouteDescriptor"); - if (outputPortToUse == null) - { - // it's a sink device - routeTable.Routes.Add(new RouteSwitchDescriptor(goodInputPort)); - } - else if (destination is IRouting) - { - routeTable.Routes.Add(new RouteSwitchDescriptor (outputPortToUse, goodInputPort)); - } - else // device is merely IRoutingInputOutputs - Debug.Console(2, destination, " No routing. Passthrough device"); - //Debug.Console(2, destination, "Exiting cycle {0}", cycle); - return true; - } - - Debug.Console(2, destination, "No route found to {0}", source.Key); - return false; - } - } - - - - - - // MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE - - - /// - /// A collection of RouteDescriptors - typically the static DefaultCollection is used - /// - public class RouteDescriptorCollection - { - public static RouteDescriptorCollection DefaultCollection - { - get - { - if (_DefaultCollection == null) - _DefaultCollection = new RouteDescriptorCollection(); - return _DefaultCollection; - } - } - static RouteDescriptorCollection _DefaultCollection; - - List RouteDescriptors = new List(); - - /// - /// Adds a RouteDescriptor to the list. If an existing RouteDescriptor for the - /// destination exists already, it will not be added - in order to preserve - /// proper route releasing. - /// - /// - public void AddRouteDescriptor(RouteDescriptor descriptor) - { - if (RouteDescriptors.Any(t => t.Destination == descriptor.Destination)) - { - Debug.Console(1, descriptor.Destination, - "Route to [{0}] already exists in global routes table", descriptor.Source.Key); - return; - } - RouteDescriptors.Add(descriptor); - } - - /// - /// Gets the RouteDescriptor for a destination - /// - /// null if no RouteDescriptor for a destination exists - public RouteDescriptor GetRouteDescriptorForDestination(IRoutingInputs destination) - { - return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination); - } - - /// - /// Returns the RouteDescriptor for a given destination AND removes it from collection. - /// Returns null if no route with the provided destination exists. - /// - public RouteDescriptor RemoveRouteDescriptor(IRoutingInputs destination) - { - var descr = GetRouteDescriptorForDestination(destination); - if (descr != null) - RouteDescriptors.Remove(descr); - return descr; - } - } - - /// - /// Represents an collection of individual route steps between Source and Destination - /// - public class RouteDescriptor - { - public IRoutingInputs Destination { get; private set; } - public IRoutingOutputs Source { get; private set; } - public eRoutingSignalType SignalType { get; private set; } - public List Routes { get; private set; } - - - public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, eRoutingSignalType signalType) - { - Destination = destination; - Source = source; - SignalType = signalType; - Routes = new List(); - } - - /// - /// Executes all routes described in this collection. Typically called via - /// extension method IRoutingInputs.ReleaseAndMakeRoute() - /// - public void ExecuteRoutes() - { - foreach (var route in Routes) - { - Debug.Console(2, "ExecuteRoutes: {0}", route.ToString()); - if (route.SwitchingDevice is IRoutingSink) - { - var device = route.SwitchingDevice as IRoutingSinkWithSwitching; - if (device == null) - continue; - - device.ExecuteSwitch(route.InputPort.Selector); - } - else if (route.SwitchingDevice is IRouting) - { - (route.SwitchingDevice as IRouting).ExecuteSwitch(route.InputPort.Selector, route.OutputPort.Selector, SignalType); - route.OutputPort.InUseTracker.AddUser(Destination, "destination-" + SignalType); - Debug.Console(2, "Output port {0} routing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); - } - } - } - - /// - /// Releases all routes in this collection. Typically called via - /// extension method IRoutingInputs.ReleaseAndMakeRoute() - /// - public void ReleaseRoutes() - { - foreach (var route in Routes) - { - if (route.SwitchingDevice is IRouting) - { - // Pull the route from the port. Whatever is watching the output's in use tracker is - // responsible for responding appropriately. - route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType); - Debug.Console(2, "Port {0} releasing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); - } - } - } - - public override string ToString() - { - var routesText = Routes.Select(r => r.ToString()).ToArray(); - return string.Format("Route table from {0} to {1}:\r{2}", Source.Key, Destination.Key, string.Join("\r", routesText)); - } - } - - /// - /// Represents an individual link for a route - /// - public class RouteSwitchDescriptor - { - public IRoutingInputs SwitchingDevice { get { return InputPort.ParentDevice; } } - public RoutingOutputPort OutputPort { get; set; } - public RoutingInputPort InputPort { get; set; } - - public RouteSwitchDescriptor(RoutingInputPort inputPort) - { - InputPort = inputPort; - } - - public RouteSwitchDescriptor(RoutingOutputPort outputPort, RoutingInputPort inputPort) - { - InputPort = inputPort; - OutputPort = outputPort; - } - - public override string ToString() - { - if(SwitchingDevice is IRouting) - return string.Format("{0} switches output '{1}' to input '{2}'", SwitchingDevice.Key, OutputPort.Selector, InputPort.Selector); - else - return string.Format("{0} switches to input '{1}'", SwitchingDevice.Key, InputPort.Selector); - - } - } + } + + destination.ReleaseRoute(); + + RunRouteRequest(routeRequest); + } + + public static void RunRouteRequest(RouteRequest request) + { + if (request.Source == null) return; + var newRoute = request.Destination.GetRouteToSource(request.Source, request.SignalType); + if (newRoute == null) return; + RouteDescriptorCollection.DefaultCollection.AddRouteDescriptor(newRoute); + Debug.Console(2, request.Destination, "Executing full route"); + newRoute.ExecuteRoutes(); + } + + /// + /// Will release the existing route on the destination, if it is found in + /// RouteDescriptorCollection.DefaultCollection + /// + /// + public static void ReleaseRoute(this IRoutingSink destination) + { + RouteRequest existingRequest; + + if (RouteRequests.TryGetValue(destination.Key, out existingRequest) && destination is IWarmingCooling) + { + var coolingDevice = destination as IWarmingCooling; + + coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRequest.HandleCooldown; + } + + RouteRequests.Remove(destination.Key); + + var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination); + if (current != null) + { + Debug.Console(1, destination, "Releasing current route: {0}", current.Source.Key); + current.ReleaseRoutes(); + } + } + + /// + /// Builds a RouteDescriptor that contains the steps necessary to make a route between devices. + /// Routes of type AudioVideo will be built as two separate routes, audio and video. If + /// a route is discovered, a new RouteDescriptor is returned. If one or both parts + /// of an audio/video route are discovered a route descriptor is returned. If no route is + /// discovered, then null is returned + /// + public static RouteDescriptor GetRouteToSource(this IRoutingSink destination, IRoutingOutputs source, eRoutingSignalType signalType) + { + var routeDescr = new RouteDescriptor(source, destination, signalType); + // if it's a single signal type, find the route + if ((signalType & (eRoutingSignalType.Audio & eRoutingSignalType.Video)) == (eRoutingSignalType.Audio & eRoutingSignalType.Video)) + { + Debug.Console(1, destination, "Attempting to build source route from {0}", source.Key); + if (!destination.GetRouteToSource(source, null, null, signalType, 0, routeDescr)) + routeDescr = null; + } + // otherwise, audioVideo needs to be handled as two steps. + else + { + Debug.Console(1, destination, "Attempting to build audio and video routes from {0}", source.Key); + var audioSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Audio, 0, routeDescr); + if (!audioSuccess) + Debug.Console(1, destination, "Cannot find audio route to {0}", source.Key); + var videoSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Video, 0, routeDescr); + if (!videoSuccess) + Debug.Console(1, destination, "Cannot find video route to {0}", source.Key); + if (!audioSuccess && !videoSuccess) + routeDescr = null; + } + + //Debug.Console(1, destination, "Route{0} discovered", routeDescr == null ? " NOT" : ""); + return routeDescr; + } + + /// + /// The recursive part of this. Will stop on each device, search its inputs for the + /// desired source and if not found, invoke this function for the each input port + /// hoping to find the source. + /// + /// + /// + /// The RoutingOutputPort whose link is being checked for a route + /// Prevents Devices from being twice-checked + /// This recursive function should not be called with AudioVideo + /// Just an informational counter + /// The RouteDescriptor being populated as the route is discovered + /// true if source is hit + static bool GetRouteToSource(this IRoutingInputs destination, IRoutingOutputs source, + RoutingOutputPort outputPortToUse, List alreadyCheckedDevices, + eRoutingSignalType signalType, int cycle, RouteDescriptor routeTable) + { + cycle++; + Debug.Console(2, "GetRouteToSource: {0} {1}--> {2}", cycle, source.Key, destination.Key); + + RoutingInputPort goodInputPort = null; + var destDevInputTies = TieLineCollection.Default.Where(t => + t.DestinationPort.ParentDevice == destination && (t.Type == signalType || (t.Type & (eRoutingSignalType.Audio | eRoutingSignalType.Video)) == (eRoutingSignalType.Audio | eRoutingSignalType.Video))); + + // find a direct tie + var directTie = destDevInputTies.FirstOrDefault( + t => t.DestinationPort.ParentDevice == destination + && t.SourcePort.ParentDevice == source); + if (directTie != null) // Found a tie directly to the source + { + goodInputPort = directTie.DestinationPort; + } + else // no direct-connect. Walk back devices. + { + Debug.Console(2, destination, "is not directly connected to {0}. Walking down tie lines", source.Key); + + // No direct tie? Run back out on the inputs' attached devices... + // Only the ones that are routing devices + var attachedMidpoints = destDevInputTies.Where(t => t.SourcePort.ParentDevice is IRoutingInputsOutputs); + + //Create a list for tracking already checked devices to avoid loops, if it doesn't already exist from previous iteration + if (alreadyCheckedDevices == null) + alreadyCheckedDevices = new List(); + alreadyCheckedDevices.Add(destination as IRoutingInputsOutputs); + + foreach (var inputTieToTry in attachedMidpoints) + { + var upstreamDeviceOutputPort = inputTieToTry.SourcePort; + var upstreamRoutingDevice = upstreamDeviceOutputPort.ParentDevice as IRoutingInputsOutputs; + Debug.Console(2, destination, "Trying to find route on {0}", upstreamRoutingDevice.Key); + + // Check if this previous device has already been walked + if (alreadyCheckedDevices.Contains(upstreamRoutingDevice)) + { + Debug.Console(2, destination, "Skipping input {0} on {1}, this was already checked", upstreamRoutingDevice.Key, destination.Key); + continue; + } + // haven't seen this device yet. Do it. Pass the output port to the next + // level to enable switching on success + var upstreamRoutingSuccess = upstreamRoutingDevice.GetRouteToSource(source, upstreamDeviceOutputPort, + alreadyCheckedDevices, signalType, cycle, routeTable); + if (upstreamRoutingSuccess) + { + Debug.Console(2, destination, "Upstream device route found"); + goodInputPort = inputTieToTry.DestinationPort; + break; // Stop looping the inputs in this cycle + } + } + } + + // we have a route on corresponding inputPort. *** Do the route *** + if (goodInputPort != null) + { + //Debug.Console(2, destination, "adding RouteDescriptor"); + if (outputPortToUse == null) + { + // it's a sink device + routeTable.Routes.Add(new RouteSwitchDescriptor(goodInputPort)); + } + else if (destination is IRouting) + { + routeTable.Routes.Add(new RouteSwitchDescriptor (outputPortToUse, goodInputPort)); + } + else // device is merely IRoutingInputOutputs + Debug.Console(2, destination, " No routing. Passthrough device"); + //Debug.Console(2, destination, "Exiting cycle {0}", cycle); + return true; + } + + Debug.Console(2, destination, "No route found to {0}", source.Key); + return false; + } + } + + + + + + // MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE + + + /// + /// A collection of RouteDescriptors - typically the static DefaultCollection is used + /// + public class RouteDescriptorCollection + { + public static RouteDescriptorCollection DefaultCollection + { + get + { + if (_DefaultCollection == null) + _DefaultCollection = new RouteDescriptorCollection(); + return _DefaultCollection; + } + } + static RouteDescriptorCollection _DefaultCollection; + + List RouteDescriptors = new List(); + + /// + /// Adds a RouteDescriptor to the list. If an existing RouteDescriptor for the + /// destination exists already, it will not be added - in order to preserve + /// proper route releasing. + /// + /// + public void AddRouteDescriptor(RouteDescriptor descriptor) + { + if (RouteDescriptors.Any(t => t.Destination == descriptor.Destination)) + { + Debug.Console(1, descriptor.Destination, + "Route to [{0}] already exists in global routes table", descriptor.Source.Key); + return; + } + RouteDescriptors.Add(descriptor); + } + + /// + /// Gets the RouteDescriptor for a destination + /// + /// null if no RouteDescriptor for a destination exists + public RouteDescriptor GetRouteDescriptorForDestination(IRoutingInputs destination) + { + return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination); + } + + /// + /// Returns the RouteDescriptor for a given destination AND removes it from collection. + /// Returns null if no route with the provided destination exists. + /// + public RouteDescriptor RemoveRouteDescriptor(IRoutingInputs destination) + { + var descr = GetRouteDescriptorForDestination(destination); + if (descr != null) + RouteDescriptors.Remove(descr); + return descr; + } + } + + /// + /// Represents an collection of individual route steps between Source and Destination + /// + public class RouteDescriptor + { + public IRoutingInputs Destination { get; private set; } + public IRoutingOutputs Source { get; private set; } + public eRoutingSignalType SignalType { get; private set; } + public List Routes { get; private set; } + + + public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, eRoutingSignalType signalType) + { + Destination = destination; + Source = source; + SignalType = signalType; + Routes = new List(); + } + + /// + /// Executes all routes described in this collection. Typically called via + /// extension method IRoutingInputs.ReleaseAndMakeRoute() + /// + public void ExecuteRoutes() + { + foreach (var route in Routes) + { + Debug.Console(2, "ExecuteRoutes: {0}", route.ToString()); + if (route.SwitchingDevice is IRoutingSink) + { + var device = route.SwitchingDevice as IRoutingSinkWithSwitching; + if (device == null) + continue; + + device.ExecuteSwitch(route.InputPort.Selector); + } + else if (route.SwitchingDevice is IRouting) + { + (route.SwitchingDevice as IRouting).ExecuteSwitch(route.InputPort.Selector, route.OutputPort.Selector, SignalType); + route.OutputPort.InUseTracker.AddUser(Destination, "destination-" + SignalType); + Debug.Console(2, "Output port {0} routing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); + } + } + } + + /// + /// Releases all routes in this collection. Typically called via + /// extension method IRoutingInputs.ReleaseAndMakeRoute() + /// + public void ReleaseRoutes() + { + foreach (var route in Routes) + { + if (route.SwitchingDevice is IRouting) + { + // Pull the route from the port. Whatever is watching the output's in use tracker is + // responsible for responding appropriately. + route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType); + Debug.Console(2, "Port {0} releasing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); + } + } + } + + public override string ToString() + { + var routesText = Routes.Select(r => r.ToString()).ToArray(); + return string.Format("Route table from {0} to {1}:\r{2}", Source.Key, Destination.Key, string.Join("\r", routesText)); + } + } + + /// + /// Represents an individual link for a route + /// + public class RouteSwitchDescriptor + { + public IRoutingInputs SwitchingDevice { get { return InputPort.ParentDevice; } } + public RoutingOutputPort OutputPort { get; set; } + public RoutingInputPort InputPort { get; set; } + + public RouteSwitchDescriptor(RoutingInputPort inputPort) + { + InputPort = inputPort; + } + + public RouteSwitchDescriptor(RoutingOutputPort outputPort, RoutingInputPort inputPort) + { + InputPort = inputPort; + OutputPort = outputPort; + } + + public override string ToString() + { + if(SwitchingDevice is IRouting) + return string.Format("{0} switches output '{1}' to input '{2}'", SwitchingDevice.Key, OutputPort.Selector, InputPort.Selector); + else + return string.Format("{0} switches to input '{1}'", SwitchingDevice.Key, InputPort.Selector); + + } + } } \ No newline at end of file From 6414631debcc762e26ecd59e2dbd74c8de160e5a Mon Sep 17 00:00:00 2001 From: jdevito Date: Tue, 17 Jan 2023 09:49:16 -0600 Subject: [PATCH 02/26] feat: added crestron web server (cws) to Essentials_Core --- .../CrestronWebServerBase.cs | 197 ++++++++++++++++++ .../CrestronWebServerFactory.cs | 20 ++ .../RequestHandlerUnknown.cs | 19 ++ 3 files changed, 236 insertions(+) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs new file mode 100644 index 00000000..d9649a7d --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs @@ -0,0 +1,197 @@ +using System; +using Crestron.SimplSharp; +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core +{ + public class CrestronWebServerBase : EssentialsDevice, IDisposable + { + private HttpCwsServer _server; + private readonly CCriticalSection _serverLock = new CCriticalSection(); + + /// + /// CWS base path + /// + public string BasePath { get; private set; } + + /// + /// Constructor + /// + /// + /// + /// + public CrestronWebServerBase(string key, string name, string basePath) + : base(key, name) + { + Key = key; + + BasePath = string.IsNullOrEmpty(basePath) ? "/api" : basePath; + + CrestronEnvironment.ProgramStatusEventHandler += programEvent => + { + if (programEvent != eProgramStatusEventType.Stopping) + return; + + Dispose(true); + }; + } + + /// + /// Initializes the CWS class + /// + public override void Initialize() + { + ServerStart(); + base.Initialize(); + } + + /// + /// Starts the CWS server + /// + public void ServerStart() + { + try + { + _serverLock.Enter(); + + if (_server != null) + { + Debug.Console(1, this, "Server is already running"); + return; + } + + Debug.Console(1, this, "Starting server"); + + _server = new HttpCwsServer(BasePath) + { + HttpRequestHandler = new RequestHandlerUnknown() + }; + + // TODO [ ] Add server paths + } + catch (Exception ex) + { + Debug.Console(1, this, "ServerStart Exception Message: {0}", ex.Message); + Debug.Console(2, this, "ServerStart Exception StackTrace: {0}", ex.StackTrace); + if (ex.InnerException != null) + Debug.Console(2, this, "ServerStart Exception InnerException: {0}", ex.InnerException); + } + finally + { + _serverLock.Leave(); + } + } + + /// + /// Stops the CWS server + /// + public void ServerStop() + { + try + { + _serverLock.Enter(); + if (_server == null) + { + Debug.Console(1, this, "Server is already stopped"); + return; + } + + _server.Unregister(); + _server.Dispose(); + _server = null; + } + catch (Exception ex) + { + Debug.Console(1, this, "ServerStop Exception Message: {0}", ex.Message); + Debug.Console(2, this, "ServerStop Exception StackTrace: {0}", ex.StackTrace); + if (ex.InnerException != null) + Debug.Console(2, this, "ServerStop Exception InnerException: {0}", ex.InnerException); + } + finally + { + _serverLock.Leave(); + } + } + + /// + /// Received request handler + /// + /// + /// + public void ReceivedRequestEventHandler(object sender, HttpCwsRequestEventArgs args) + { + try + { + // TODO [ ] Add logic for received requests + Debug.Console(1, this, @"RecieveRequestEventHandler +Method: {0} +Path: {1} +PathInfo: {2} +PhysicalPath: {3} +ContentType: {4} +RawUrl: {5} +Url: {6} +UserAgent: {7} +UserHostAddress: {8} +UserHostName: {9}", + args.Context.Request.HttpMethod, + args.Context.Request.Path, + args.Context.Request.PathInfo, + args.Context.Request.PhysicalPath, + args.Context.Request.ContentType, + args.Context.Request.RawUrl, + args.Context.Request.Url, + args.Context.Request.UserAgent, + args.Context.Request.UserHostAddress, + args.Context.Request.UserHostName); + + } + catch (Exception ex) + { + Debug.Console(1, this, "ReceivedRequestEventHandler Exception Message: {0}", ex.Message); + Debug.Console(2, this, "ReceivedRequestEventHandler Exception StackTrace: {0}", ex.StackTrace); + if (ex.InnerException != null) + Debug.Console(2, this, "ReceivedRequestEventHandler Exception InnerException: {0}", ex.InnerException); + } + } + + #region Dispose + + /// + /// Tracks if the CWS is disposed + /// + public bool Disposed { get; private set; } + + /// + /// Disposes of the CWS + /// + public void Dispose() + { + Dispose(true); + CrestronEnvironment.GC.SuppressFinalize(this); + } + + protected void Dispose(bool disposing) + { + if (Disposed) + { + Debug.Console(1, this, "Server has already been disposed"); + return; + } + + if (!disposing) return; + + if (_server != null) ServerStop(); + + Disposed = _server == null; + } + + ~CrestronWebServerBase() + { + Dispose(true); + } + + #endregion + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs new file mode 100644 index 00000000..ab442ecb --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using PepperDash.Core; +using PepperDash.Essentials.Core.Config; + +namespace PepperDash.Essentials.Core +{ + public class CrestronWebServerFactory : EssentialsDeviceFactory + { + public CrestronWebServerFactory() + { + TypeNames = new List { "crestroncws", "cws" }; + } + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Crestron CWS Device"); + + return new CrestronWebServerBase(dc.Key, dc.Name, ""); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs new file mode 100644 index 00000000..71cf383a --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs @@ -0,0 +1,19 @@ +using Crestron.SimplSharp.WebScripting; + +namespace PepperDash.Essentials.Core +{ + /// + /// Crestron CWS unknown request handler + /// + public class RequestHandlerUnknown : IHttpCwsHandler + { + + public void ProcessRequest(HttpCwsContext context) + { + // TODO [ ] Modify unknown request handler + context.Response.StatusCode = 418; + context.Response.ContentType = "application/json"; + context.Response.Write(string.Format("{0} {1}", context.Request.HttpMethod, context.Request.RawUrl), true); + } + } +} \ No newline at end of file From b52bee5714385232bff2e06ca33fa647fc344ed9 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 18 Jan 2023 15:26:24 -0600 Subject: [PATCH 03/26] refactor: Changed CWS references to WebApi, re-organized Web folder; added generic request handlers to align with API, handlers need to be completed --- .../CrestronWebServerBase.cs | 197 ------------------ .../CrestronWebServerFactory.cs | 20 -- .../RequestHandlerUnknown.cs | 19 -- .../PepperDash_Essentials_Core.csproj | 17 ++ ...perDash_Essentials_Core.csproj.DotSettings | 3 + .../Web/EssemtialsWebApi.cs | 160 ++++++++++++++ .../Web/EssentialsWebApiFactory.cs | 25 +++ .../Web/EssentialsWebApiPropertiesConfig.cs | 10 + .../RequestHandlers/AppDebugRequestHandler.cs | 111 ++++++++++ .../RequestHandlers/DevJsonRequestHandler.cs | 111 ++++++++++ .../RequestHandlers/DevListRequestHandler.cs | 111 ++++++++++ .../RequestHandlers/DevPropsRequestHandler.cs | 111 ++++++++++ .../DisableAllStreamDebugRequestHandler.cs | 111 ++++++++++ .../GetJoinMapRequestHandler.cs | 111 ++++++++++ .../RequestHandlers/GetTypesRequestHandler.cs | 111 ++++++++++ .../ReportVersionsRequestHandler.cs | 111 ++++++++++ .../SetDeviceStreamDebugRequestHandler.cs | 111 ++++++++++ .../ShowConfigRequestHandler.cs | 111 ++++++++++ packages.config | 2 +- 19 files changed, 1326 insertions(+), 237 deletions(-) delete mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs delete mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs delete mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj.DotSettings create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiFactory.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiPropertiesConfig.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs deleted file mode 100644 index d9649a7d..00000000 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerBase.cs +++ /dev/null @@ -1,197 +0,0 @@ -using System; -using Crestron.SimplSharp; -using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; - -namespace PepperDash.Essentials.Core -{ - public class CrestronWebServerBase : EssentialsDevice, IDisposable - { - private HttpCwsServer _server; - private readonly CCriticalSection _serverLock = new CCriticalSection(); - - /// - /// CWS base path - /// - public string BasePath { get; private set; } - - /// - /// Constructor - /// - /// - /// - /// - public CrestronWebServerBase(string key, string name, string basePath) - : base(key, name) - { - Key = key; - - BasePath = string.IsNullOrEmpty(basePath) ? "/api" : basePath; - - CrestronEnvironment.ProgramStatusEventHandler += programEvent => - { - if (programEvent != eProgramStatusEventType.Stopping) - return; - - Dispose(true); - }; - } - - /// - /// Initializes the CWS class - /// - public override void Initialize() - { - ServerStart(); - base.Initialize(); - } - - /// - /// Starts the CWS server - /// - public void ServerStart() - { - try - { - _serverLock.Enter(); - - if (_server != null) - { - Debug.Console(1, this, "Server is already running"); - return; - } - - Debug.Console(1, this, "Starting server"); - - _server = new HttpCwsServer(BasePath) - { - HttpRequestHandler = new RequestHandlerUnknown() - }; - - // TODO [ ] Add server paths - } - catch (Exception ex) - { - Debug.Console(1, this, "ServerStart Exception Message: {0}", ex.Message); - Debug.Console(2, this, "ServerStart Exception StackTrace: {0}", ex.StackTrace); - if (ex.InnerException != null) - Debug.Console(2, this, "ServerStart Exception InnerException: {0}", ex.InnerException); - } - finally - { - _serverLock.Leave(); - } - } - - /// - /// Stops the CWS server - /// - public void ServerStop() - { - try - { - _serverLock.Enter(); - if (_server == null) - { - Debug.Console(1, this, "Server is already stopped"); - return; - } - - _server.Unregister(); - _server.Dispose(); - _server = null; - } - catch (Exception ex) - { - Debug.Console(1, this, "ServerStop Exception Message: {0}", ex.Message); - Debug.Console(2, this, "ServerStop Exception StackTrace: {0}", ex.StackTrace); - if (ex.InnerException != null) - Debug.Console(2, this, "ServerStop Exception InnerException: {0}", ex.InnerException); - } - finally - { - _serverLock.Leave(); - } - } - - /// - /// Received request handler - /// - /// - /// - public void ReceivedRequestEventHandler(object sender, HttpCwsRequestEventArgs args) - { - try - { - // TODO [ ] Add logic for received requests - Debug.Console(1, this, @"RecieveRequestEventHandler -Method: {0} -Path: {1} -PathInfo: {2} -PhysicalPath: {3} -ContentType: {4} -RawUrl: {5} -Url: {6} -UserAgent: {7} -UserHostAddress: {8} -UserHostName: {9}", - args.Context.Request.HttpMethod, - args.Context.Request.Path, - args.Context.Request.PathInfo, - args.Context.Request.PhysicalPath, - args.Context.Request.ContentType, - args.Context.Request.RawUrl, - args.Context.Request.Url, - args.Context.Request.UserAgent, - args.Context.Request.UserHostAddress, - args.Context.Request.UserHostName); - - } - catch (Exception ex) - { - Debug.Console(1, this, "ReceivedRequestEventHandler Exception Message: {0}", ex.Message); - Debug.Console(2, this, "ReceivedRequestEventHandler Exception StackTrace: {0}", ex.StackTrace); - if (ex.InnerException != null) - Debug.Console(2, this, "ReceivedRequestEventHandler Exception InnerException: {0}", ex.InnerException); - } - } - - #region Dispose - - /// - /// Tracks if the CWS is disposed - /// - public bool Disposed { get; private set; } - - /// - /// Disposes of the CWS - /// - public void Dispose() - { - Dispose(true); - CrestronEnvironment.GC.SuppressFinalize(this); - } - - protected void Dispose(bool disposing) - { - if (Disposed) - { - Debug.Console(1, this, "Server has already been disposed"); - return; - } - - if (!disposing) return; - - if (_server != null) ServerStop(); - - Disposed = _server == null; - } - - ~CrestronWebServerBase() - { - Dispose(true); - } - - #endregion - } -} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs deleted file mode 100644 index ab442ecb..00000000 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/CrestronWebServerFactory.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using PepperDash.Core; -using PepperDash.Essentials.Core.Config; - -namespace PepperDash.Essentials.Core -{ - public class CrestronWebServerFactory : EssentialsDeviceFactory - { - public CrestronWebServerFactory() - { - TypeNames = new List { "crestroncws", "cws" }; - } - public override EssentialsDevice BuildDevice(DeviceConfig dc) - { - Debug.Console(1, "Factory Attempting to create new Crestron CWS Device"); - - return new CrestronWebServerBase(dc.Key, dc.Name, ""); - } - } -} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs deleted file mode 100644 index 71cf383a..00000000 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron Web Server/RequestHandlerUnknown.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Crestron.SimplSharp.WebScripting; - -namespace PepperDash.Essentials.Core -{ - /// - /// Crestron CWS unknown request handler - /// - public class RequestHandlerUnknown : IHttpCwsHandler - { - - public void ProcessRequest(HttpCwsContext context) - { - // TODO [ ] Modify unknown request handler - context.Response.StatusCode = 418; - context.Response.ContentType = "application/json"; - context.Response.Write(string.Format("{0} {1}", context.Request.HttpMethod, context.Request.RawUrl), true); - } - } -} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 2cf2928c..fb861df6 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -92,6 +92,10 @@ ..\..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll False + + False + ..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCWSHelperInterface.dll + False ..\..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll @@ -193,6 +197,19 @@ + + + + + + + + + + + + + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj.DotSettings b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj.DotSettings new file mode 100644 index 00000000..cb991a69 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj.DotSettings @@ -0,0 +1,3 @@ + + True + False \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs new file mode 100644 index 00000000..9e6fe64c --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs @@ -0,0 +1,160 @@ +using System.Collections.Generic; +using Crestron.SimplSharp; +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; +using PepperDash.Essentials.Core.Web.RequestHandlers; + +namespace PepperDash.Essentials.Core.Web +{ + public class EssemtialsWebApi : EssentialsDevice + { + private readonly GenericCwsBase _server; + + private const string DefaultBasePath = "/api"; + + private const int DebugTrace = 0; + private const int DebugInfo = 1; + private const int DebugVerbose = 2; + + /// + /// CWS base path + /// + public string BasePath { get; private set; } + + /// + /// Tracks if CWS is registered + /// + public bool IsRegistered + { + get { return _server.IsRegistered; } + } + + /// + /// Constructor + /// + /// + /// + /// + public EssemtialsWebApi(string key, string name, EssentialsWebApiPropertiesConfig config) + : base(key, name) + { + Key = key; + + BasePath = string.IsNullOrEmpty(config.BasePath) ? DefaultBasePath : config.BasePath; + + _server = new GenericCwsBase(Key, Name, BasePath); + } + + /// + /// Custom activate, add routes + /// + /// + public override bool CustomActivate() + { + var routes = new List + { + new HttpCwsRoute("reportversions") + { + Name = "ReportVersions", + RouteHandler = new ReportVersionsRequestHandler() + }, + new HttpCwsRoute("appdebug") + { + Name = "AppDebug", + RouteHandler = new AppDebugRequestHandler() + }, + new HttpCwsRoute("devlist") + { + Name = "DevList", + RouteHandler = new DevListRequestHandler() + }, + new HttpCwsRoute("devprops/{key}") + { + Name = "DevProps", + RouteHandler = new DevPropsRequestHandler() + }, + new HttpCwsRoute("devjson") + { + Name = "DevJson", + RouteHandler = new DevJsonRequestHandler() + }, + new HttpCwsRoute("setdevicestreamdebug/{deviceKey}/{state}") + { + Name = "SetDeviceStreamDebug", + RouteHandler = new SetDeviceStreamDebugRequestHandler() + }, + new HttpCwsRoute("disableallstreamdebug") + { + Name = "DisableAllStreamDebug", + RouteHandler = new DisableAllStreamDebugRequestHandler() + }, + new HttpCwsRoute("showconfig") + { + Name = "ShowConfig", + RouteHandler = new ShowConfigRequestHandler() + }, + new HttpCwsRoute("gettypes/all") + { + Name = "GetTypesAll", + RouteHandler = new GetTypesRequestHandler() + }, + new HttpCwsRoute("gettypes/{filter}") + { + Name = "GetTypesByFilter", + RouteHandler = new GetTypesRequestHandler() + }, + new HttpCwsRoute("getjoinmap/{bridgeKey}/all") + { + Name = "GetJoinMapsByBridgeKey", + RouteHandler = new GetJoinMapRequestHandler() + }, + new HttpCwsRoute("getjoinmap/{bridgeKey}/{deviceKey}") + { + Name = "GetJoinMapsForBridgeKeyFilteredByDeviceKey", + RouteHandler = new GetJoinMapRequestHandler() + } + }; + + foreach (var route in routes) + { + _server.AddRoute(route); + } + + return base.CustomActivate(); + } + + /// + /// Initializes the CWS class + /// + public override void Initialize() + { + // If running on an appliance + if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance) + { + /* + RMC4> + WEBSERVER [ON | OFF | TIMEOUT | MAXSESSIONSPERUSER ] + WEBSERVER [TIMEOUT] will display current session timeout value + WEBSERVER MAXSESSIONSPERUSER will display current max web sessions per user + WEBSERVER ALLOWSHAREDSESSION will display whether 'samesite = none' would be set on cookies + No parameter - displays current setting + */ + var response = string.Empty; + CrestronConsole.SendControlSystemCommand("webserver", ref response); + if (response.Contains("OFF")) return; + + var is4Series = eCrestronSeries.Series4 == (Global.ProcessorSeries & eCrestronSeries.Series4); + Debug.Console(DebugTrace, Debug.ErrorLogLevel.Notice, "Starting Essentials CWS on {0} Appliance", is4Series ? "4-series" : "3-series"); + + _server.Start(); + + return; + } + + // Automatically start CWS when running on a server (Linux OS, Virtual Control) + Debug.Console(DebugTrace, Debug.ErrorLogLevel.Notice, "Starting Essentials CWS on Virtual Control Server"); + + _server.Start(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiFactory.cs new file mode 100644 index 00000000..51361c2c --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiFactory.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using PepperDash.Core; +using PepperDash.Essentials.Core.Config; + +namespace PepperDash.Essentials.Core.Web +{ + public class EssentialsWebApiFactory : EssentialsDeviceFactory + { + public EssentialsWebApiFactory() + { + TypeNames = new List { "EssentialsWebApi" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Essentials Web API Server"); + + var props = dc.Properties.ToObject(); + if (props != null) return new EssemtialsWebApi(dc.Key, dc.Name, props); + + Debug.Console(1, "Factory failed to create new Essentials Web API Server"); + return null; + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiPropertiesConfig.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiPropertiesConfig.cs new file mode 100644 index 00000000..a57e1ce9 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiPropertiesConfig.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace PepperDash.Essentials.Core.Web +{ + public class EssentialsWebApiPropertiesConfig + { + [JsonProperty("basePath")] + public string BasePath { get; set; } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs new file mode 100644 index 00000000..0ec54343 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class AppDebugRequestHandler : CwsBaseHandler + { + public AppDebugRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs new file mode 100644 index 00000000..c5f76089 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DevJsonRequestHandler : CwsBaseHandler + { + public DevJsonRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs new file mode 100644 index 00000000..2e8290fd --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DevListRequestHandler : CwsBaseHandler + { + public DevListRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs new file mode 100644 index 00000000..e37bafa7 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DevPropsRequestHandler : CwsBaseHandler + { + public DevPropsRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs new file mode 100644 index 00000000..8ddeebd6 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DisableAllStreamDebugRequestHandler : CwsBaseHandler + { + public DisableAllStreamDebugRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs new file mode 100644 index 00000000..59c6ef4c --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class GetJoinMapRequestHandler : CwsBaseHandler + { + public GetJoinMapRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs new file mode 100644 index 00000000..f3761173 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class GetTypesRequestHandler : CwsBaseHandler + { + public GetTypesRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs new file mode 100644 index 00000000..dddf0e02 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class ReportVersionsRequestHandler : CwsBaseHandler + { + public ReportVersionsRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs new file mode 100644 index 00000000..146a0c1a --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class SetDeviceStreamDebugRequestHandler : CwsBaseHandler + { + public SetDeviceStreamDebugRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs new file mode 100644 index 00000000..ad28d26c --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -0,0 +1,111 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class ShowConfigRequestHandler : CwsBaseHandler + { + public ShowConfigRequestHandler() + { + } + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/packages.config b/packages.config index ffea92a5..aeeba3c1 100644 --- a/packages.config +++ b/packages.config @@ -1,3 +1,3 @@ - + \ No newline at end of file From f4a5d6737e1fc94e719f64832b3fe09ea33f0d0c Mon Sep 17 00:00:00 2001 From: jdevito Date: Thu, 19 Jan 2023 11:50:48 -0600 Subject: [PATCH 04/26] fix: updated packages.config reference for PepperDash_Core to latest WebAPI build --- packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages.config b/packages.config index aeeba3c1..d7e637ee 100644 --- a/packages.config +++ b/packages.config @@ -1,3 +1,3 @@ - + \ No newline at end of file From 03d5c24dc46793e5a48be0ed0bebe2d0101e5da6 Mon Sep 17 00:00:00 2001 From: jdevito Date: Thu, 19 Jan 2023 12:00:32 -0600 Subject: [PATCH 05/26] fix: updated Essentials WebAPI and Request Handlers using statements to reflect PepperDash Core updates in 1.1.5-alpha-286 --- .../PepperDashEssentialsBase/Web/EssemtialsWebApi.cs | 5 +++-- .../Web/RequestHandlers/AppDebugRequestHandler.cs | 4 ++-- .../Web/RequestHandlers/DevJsonRequestHandler.cs | 4 ++-- .../Web/RequestHandlers/DevListRequestHandler.cs | 4 ++-- .../Web/RequestHandlers/DevPropsRequestHandler.cs | 4 ++-- .../RequestHandlers/DisableAllStreamDebugRequestHandler.cs | 4 ++-- .../Web/RequestHandlers/GetJoinMapRequestHandler.cs | 4 ++-- .../Web/RequestHandlers/GetTypesRequestHandler.cs | 4 ++-- .../Web/RequestHandlers/ReportVersionsRequestHandler.cs | 4 ++-- .../RequestHandlers/SetDeviceStreamDebugRequestHandler.cs | 4 ++-- .../Web/RequestHandlers/ShowConfigRequestHandler.cs | 4 ++-- 11 files changed, 23 insertions(+), 22 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs index 9e6fe64c..e069e7a6 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs @@ -2,13 +2,14 @@ using Crestron.SimplSharp; using Crestron.SimplSharp.WebScripting; using PepperDash.Core; +using PepperDash.Core.Web; using PepperDash.Essentials.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web { public class EssemtialsWebApi : EssentialsDevice { - private readonly GenericCwsBase _server; + private readonly WebApiServer _server; private const string DefaultBasePath = "/api"; @@ -42,7 +43,7 @@ namespace PepperDash.Essentials.Core.Web BasePath = string.IsNullOrEmpty(config.BasePath) ? DefaultBasePath : config.BasePath; - _server = new GenericCwsBase(Key, Name, BasePath); + _server = new WebApiServer(Key, Name, BasePath); } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs index 0ec54343..e550b3f0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class AppDebugRequestHandler : CwsBaseHandler + public class AppDebugRequestHandler : WebApiBaseRequestHandler { public AppDebugRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index c5f76089..c7206739 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class DevJsonRequestHandler : CwsBaseHandler + public class DevJsonRequestHandler : WebApiBaseRequestHandler { public DevJsonRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs index 2e8290fd..77cd9bbe 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class DevListRequestHandler : CwsBaseHandler + public class DevListRequestHandler : WebApiBaseRequestHandler { public DevListRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index e37bafa7..d1cdb09a 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class DevPropsRequestHandler : CwsBaseHandler + public class DevPropsRequestHandler : WebApiBaseRequestHandler { public DevPropsRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs index 8ddeebd6..fa93c5ff 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class DisableAllStreamDebugRequestHandler : CwsBaseHandler + public class DisableAllStreamDebugRequestHandler : WebApiBaseRequestHandler { public DisableAllStreamDebugRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs index 59c6ef4c..53abb868 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class GetJoinMapRequestHandler : CwsBaseHandler + public class GetJoinMapRequestHandler : WebApiBaseRequestHandler { public GetJoinMapRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs index f3761173..e2e8fc51 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class GetTypesRequestHandler : CwsBaseHandler + public class GetTypesRequestHandler : WebApiBaseRequestHandler { public GetTypesRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index dddf0e02..a0e68722 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class ReportVersionsRequestHandler : CwsBaseHandler + public class ReportVersionsRequestHandler : WebApiBaseRequestHandler { public ReportVersionsRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index 146a0c1a..4c485205 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class SetDeviceStreamDebugRequestHandler : CwsBaseHandler + public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler { public SetDeviceStreamDebugRequestHandler() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs index ad28d26c..2a42c4a3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -1,9 +1,9 @@ using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class ShowConfigRequestHandler : CwsBaseHandler + public class ShowConfigRequestHandler : WebApiBaseRequestHandler { public ShowConfigRequestHandler() { From 555944011d4c6cc3e57f2a955403b57aba567e68 Mon Sep 17 00:00:00 2001 From: jdevito Date: Thu, 19 Jan 2023 12:19:27 -0600 Subject: [PATCH 06/26] fix: added continue to resolve warning of possible empty statement when compiled locally --- .../PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs index 6ffb16cc..67a5740f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs @@ -579,7 +579,7 @@ namespace PepperDash.Essentials.Core var errorKey = string.Empty; foreach (var item in dataArray) { - if (item.Value.TrimEnd() == placeholder) ; + if (item.Value.TrimEnd() == placeholder) continue; errorKey = item.Key; break; } From 0c2896f9aa0142b641b7c4801988ea94c26f1148 Mon Sep 17 00:00:00 2001 From: jdevito Date: Tue, 24 Jan 2023 12:22:40 -0600 Subject: [PATCH 07/26] fix: updated packages.config to reference PepperDashCore.1.1.5-alpha-291, built on latest development branch; removed empty constructor from request handlers --- .../PepperDashEssentialsBase/Comm and IR/CommFactory.cs | 2 ++ .../Web/RequestHandlers/AppDebugRequestHandler.cs | 4 ---- .../Web/RequestHandlers/DevJsonRequestHandler.cs | 4 ---- .../Web/RequestHandlers/DevListRequestHandler.cs | 4 ---- .../Web/RequestHandlers/DevPropsRequestHandler.cs | 4 ---- .../RequestHandlers/DisableAllStreamDebugRequestHandler.cs | 4 ---- .../Web/RequestHandlers/GetJoinMapRequestHandler.cs | 4 ---- .../Web/RequestHandlers/GetTypesRequestHandler.cs | 4 ---- .../Web/RequestHandlers/ReportVersionsRequestHandler.cs | 4 ---- .../Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs | 4 ---- .../Web/RequestHandlers/ShowConfigRequestHandler.cs | 4 ---- packages.config | 2 +- 12 files changed, 3 insertions(+), 41 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs index 8a5efe47..9667b5b9 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs @@ -183,6 +183,8 @@ namespace PepperDash.Essentials.Core [JsonConverter(typeof(ComSpecJsonConverter))] public ComPort.ComPortSpec ComParams { get; set; } + public string RoomId { get; set; } + public string CresnetId { get; set; } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs index e550b3f0..ef19e2d5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class AppDebugRequestHandler : WebApiBaseRequestHandler { - public AppDebugRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index c7206739..ea7b0d0f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevJsonRequestHandler : WebApiBaseRequestHandler { - public DevJsonRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs index 77cd9bbe..2bccc435 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevListRequestHandler : WebApiBaseRequestHandler { - public DevListRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index d1cdb09a..08eb6853 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevPropsRequestHandler : WebApiBaseRequestHandler { - public DevPropsRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs index fa93c5ff..489bfd55 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DisableAllStreamDebugRequestHandler : WebApiBaseRequestHandler { - public DisableAllStreamDebugRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs index 53abb868..c08846e2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetJoinMapRequestHandler : WebApiBaseRequestHandler { - public GetJoinMapRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs index e2e8fc51..ce33866d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetTypesRequestHandler : WebApiBaseRequestHandler { - public GetTypesRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index a0e68722..2ee3fec4 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class ReportVersionsRequestHandler : WebApiBaseRequestHandler { - public ReportVersionsRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index 4c485205..58280f57 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler { - public SetDeviceStreamDebugRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs index 2a42c4a3..5edb50da 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -5,10 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class ShowConfigRequestHandler : WebApiBaseRequestHandler { - public ShowConfigRequestHandler() - { - } - /// /// Handles CONNECT method requests /// diff --git a/packages.config b/packages.config index d7e637ee..87f5b8c1 100644 --- a/packages.config +++ b/packages.config @@ -1,3 +1,3 @@ - + \ No newline at end of file From 1bae7dc91bc1c417102dfcdd1188790ab6374f8e Mon Sep 17 00:00:00 2001 From: jta Date: Mon, 30 Jan 2023 15:19:14 -0500 Subject: [PATCH 08/26] feature: add workflow to push to project --- .github/workflows/add-issues-to-project.yml | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/add-issues-to-project.yml diff --git a/.github/workflows/add-issues-to-project.yml b/.github/workflows/add-issues-to-project.yml new file mode 100644 index 00000000..8811c0cc --- /dev/null +++ b/.github/workflows/add-issues-to-project.yml @@ -0,0 +1,37 @@ +name: Add bugs to bugs project + +on: + issues: + types: + - opened + - labeled + +jobs: + check-secret: + runs-on: ubuntu-latest + outputs: + my-key: ${{ steps.my-key.outputs.defined }} + steps: + - id: my-key + if: "${{ env.MY_KEY != '' }}" + run: echo "::set-output name=defined::true" + env: + MY_KEY: ${{ secrets.PROJECT_URL }} + throw-error: + name: Check + runs-on: ubuntu-latest + needs: [check-secret] + if: needs.check-secret.outputs.my-key != 'true' + steps: + - run: echo "The Project URL Repo Secret is empty" + add-to-project: + name: Add issue to project + runs-on: ubuntu-latest + needs: [check-secret] + if: needs.check-secret.outputs.my-key == 'true' + steps: + - uses: actions/add-to-project@main + with: + project-url: ${{ secrets.PROJECT_URL }} + github-token: ${{ secrets.GH_PROJECTS_PASSWORD }} + From 705e750419262a1328035fa2344263a179ebf61c Mon Sep 17 00:00:00 2001 From: jdevito Date: Mon, 30 Jan 2023 17:17:12 -0600 Subject: [PATCH 09/26] fix: resolved issue with default handlers, removed debug statements that were not accessed; fix: updated default handler, reportversions handler, devlist handler --- PepperDashEssentials/ControlSystem.cs | 2 + .../PepperDash_Essentials_Core.csproj | 1 + .../Web/EssemtialsWebApi.cs | 82 +++++++++++-- .../RequestHandlers/DefaultRequestHandler.cs | 112 ++++++++++++++++++ .../RequestHandlers/DevListRequestHandler.cs | 39 +++++- .../ReportVersionsRequestHandler.cs | 33 +++++- 6 files changed, 254 insertions(+), 15 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 1ab3b28e..736a250f 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -13,6 +13,7 @@ using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Fusion; +using PepperDash.Essentials.Core.Web; using PepperDash.Essentials.Devices.Common; using PepperDash.Essentials.DM; using PepperDash.Essentials.Fusion; @@ -353,6 +354,7 @@ namespace PepperDash.Essentials // Build the processor wrapper class DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor")); + DeviceManager.AddDevice(new EssemtialsWebApi("essentialsWebApi","Essentials Web API")); // Add global System Monitor device if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index fb861df6..077bdac9 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -198,6 +198,7 @@ + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs index e069e7a6..f708d011 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs @@ -1,6 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using Crestron.SimplSharp; using Crestron.SimplSharp.WebScripting; +using Crestron.SimplSharpPro.Diagnostics; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using PepperDash.Core; using PepperDash.Core.Web; using PepperDash.Essentials.Core.Web.RequestHandlers; @@ -11,11 +16,17 @@ namespace PepperDash.Essentials.Core.Web { private readonly WebApiServer _server; - private const string DefaultBasePath = "/api"; + /// + /// http(s)://{ipaddress}/cws/{basePath} + /// http(s)://{ipaddress}/VirtualControl/Rooms/{roomId}/cws/{basePath} + /// + private readonly string _defaultBasePath = + CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance ? string.Format("/app{0:00}/api", InitialParametersClass.ApplicationNumber) : "/api"; + // TODO [ ] Reset debug levels to proper value Trace = 0, Info = 1, Verbose = 2 private const int DebugTrace = 0; - private const int DebugInfo = 1; - private const int DebugVerbose = 2; + private const int DebugInfo = 0; + private const int DebugVerbose = 0; /// /// CWS base path @@ -30,6 +41,16 @@ namespace PepperDash.Essentials.Core.Web get { return _server.IsRegistered; } } + /// + /// Constructor + /// + /// + /// + public EssemtialsWebApi(string key, string name) + : this(key, name, null) + { + } + /// /// Constructor /// @@ -41,7 +62,10 @@ namespace PepperDash.Essentials.Core.Web { Key = key; - 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); } @@ -116,9 +140,10 @@ namespace PepperDash.Essentials.Core.Web } }; - foreach (var route in routes) + foreach (var route in routes.Where(route => route != null)) { - _server.AddRoute(route); + var r = route; + _server.AddRoute(r); } return base.CustomActivate(); @@ -145,17 +170,56 @@ namespace PepperDash.Essentials.Core.Web if (response.Contains("OFF")) return; var is4Series = eCrestronSeries.Series4 == (Global.ProcessorSeries & eCrestronSeries.Series4); - Debug.Console(DebugTrace, Debug.ErrorLogLevel.Notice, "Starting Essentials CWS on {0} Appliance", is4Series ? "4-series" : "3-series"); + Debug.Console(DebugTrace, Debug.ErrorLogLevel.Notice, "Starting Essentials Web API on {0} Appliance", is4Series ? "4-series" : "3-series"); _server.Start(); + GetPaths(); + return; } // Automatically start CWS when running on a server (Linux OS, Virtual Control) - Debug.Console(DebugTrace, Debug.ErrorLogLevel.Notice, "Starting Essentials CWS on Virtual Control Server"); + Debug.Console(DebugTrace, Debug.ErrorLogLevel.Notice, "Starting Essentials Web API on Virtual Control Server"); _server.Start(); } + + /// + /// Print the available pahts + /// + /// + /// http(s)://{ipaddress}/cws/{basePath} + /// http(s)://{ipaddress}/VirtualControl/Rooms/{roomId}/cws/{basePath} + /// + public void GetPaths() + { + Debug.Console(DebugTrace, this, "{0}", 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 + ? string.Format("http(s)://{0}/virtualcontrol/rooms/{1}/cws{2}", hostname, InitialParametersClass.RoomId, BasePath) + : string.Format("http(s)://{0}/cws{1}", currentIp, BasePath); + + Debug.Console(DebugTrace, this, "Server:{0}", path); + + var routeCollection = _server.GetRouteCollection(); + if (routeCollection == null) + { + Debug.Console(DebugTrace, this, "Server route collection is null"); + return; + } + Debug.Console(DebugTrace, this, "Configured Routes:"); + foreach (var route in routeCollection) + { + Debug.Console(DebugTrace, this, "{0}: {1}/{2}", route.Name, path, route.Url); + } + Debug.Console(DebugTrace, this, "{0}", new String('-', 50)); + } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs new file mode 100644 index 00000000..2cd55d4d --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs @@ -0,0 +1,112 @@ +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core.Web.RequestHandlers; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DefaultRequestHandler : WebApiBaseRequestHandler + { + private const string Key = "DefaultRequestHandler"; + private const uint Trace = 0; + private const uint Info = 1; + private const uint Verbose = 2; + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs index 2bccc435..cc7a1528 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -1,10 +1,20 @@ -using Crestron.SimplSharp.WebScripting; +using System.Diagnostics; +using System.Linq; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; +using Debug = PepperDash.Core.Debug; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevListRequestHandler : WebApiBaseRequestHandler { + private const string Key = "DevListRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -33,8 +43,31 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + var allDevices = DeviceManager.AllDevices; + allDevices.Sort((a, b) => System.String.Compare(a.Key, b.Key, System.StringComparison.Ordinal)); + + var devices = allDevices.Select(device => new + { + Key = device.Key, + Name = device is IKeyName ? (device as IKeyName).Name : "---" + + }).Cast().ToList(); + + var js = JsonConvert.SerializeObject(devices, Formatting.Indented, new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore, + MissingMemberHandling = MissingMemberHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore, + TypeNameHandling = TypeNameHandling.None + }); + //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + + 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(); } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index 2ee3fec4..a8b36eb5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -1,10 +1,18 @@ -using Crestron.SimplSharp.WebScripting; +using System.Linq; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class ReportVersionsRequestHandler : WebApiBaseRequestHandler { + private const string Key = "ReportVersionsRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -33,8 +41,27 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + var assemblies = PluginLoader.LoadedAssemblies.Select(assembly => new + { + Name = assembly.Name, + Version = assembly.Version + }).Cast().ToList(); + + var js = JsonConvert.SerializeObject(assemblies, Formatting.Indented, new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore, + MissingMemberHandling = MissingMemberHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore, + TypeNameHandling = TypeNameHandling.None + }); + //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + + 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(); } From dd2aca9aa472a8fa9370362e2a2ecf0c3e7c852c Mon Sep 17 00:00:00 2001 From: jdevito Date: Mon, 30 Jan 2023 22:08:13 -0600 Subject: [PATCH 10/26] feat: worked on adding get/post for appdebug, devprops, devjson, disableallstreamdebug, setdevicestreamdebug --- .../Room/Types/EssentialsTechRoom.cs | 2 +- .../Web/EssemtialsWebApi.cs | 18 +++++-- .../RequestHandlers/AppDebugRequestHandler.cs | 48 +++++++++++++++++-- .../RequestHandlers/DevJsonRequestHandler.cs | 23 +++++++-- .../RequestHandlers/DevListRequestHandler.cs | 4 +- .../RequestHandlers/DevPropsRequestHandler.cs | 41 ++++++++++++++-- .../DisableAllStreamDebugRequestHandler.cs | 6 ++- .../ReportVersionsRequestHandler.cs | 1 - .../SetDeviceStreamDebugRequestHandler.cs | 47 ++++++++++++++++-- 9 files changed, 165 insertions(+), 25 deletions(-) diff --git a/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs b/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs index b97ef9c4..65cc52fa 100644 --- a/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs +++ b/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs @@ -272,7 +272,7 @@ namespace PepperDash.Essentials { Debug.Console(2, this, @"Attempting to run action: -DeviceKey: {0} +Key: {0} MethodName: {1} Params: {2}" , a.DeviceKey, a.MethodName, a.Params); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs index f708d011..8b0f7c86 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs @@ -93,21 +93,31 @@ namespace PepperDash.Essentials.Core.Web Name = "DevList", RouteHandler = new DevListRequestHandler() }, - new HttpCwsRoute("devprops/{key}") + new HttpCwsRoute("devprops") { Name = "DevProps", RouteHandler = new DevPropsRequestHandler() }, + //new HttpCwsRoute("devprops/{key}") + //{ + // Name = "DevProps", + // RouteHandler = new DevPropsRequestHandler() + //}, new HttpCwsRoute("devjson") { Name = "DevJson", RouteHandler = new DevJsonRequestHandler() }, - new HttpCwsRoute("setdevicestreamdebug/{deviceKey}/{state}") + new HttpCwsRoute("setdevicestreamdebug") { - Name = "SetDeviceStreamDebug", - RouteHandler = new SetDeviceStreamDebugRequestHandler() + Name = "SetDeviceStreamDebug", + RouteHandler = new SetDeviceStreamDebugRequestHandler() }, + //new HttpCwsRoute("setdevicestreamdebug/{deviceKey}/{state}") + //{ + // Name = "SetDeviceStreamDebug", + // RouteHandler = new SetDeviceStreamDebugRequestHandler() + //}, new HttpCwsRoute("disableallstreamdebug") { Name = "DisableAllStreamDebug", diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs index ef19e2d5..f88ae849 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -1,10 +1,19 @@ -using Crestron.SimplSharp.WebScripting; +using System; +using System.Text; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class AppDebugRequestHandler : WebApiBaseRequestHandler { + private const string Key = "AppDebugRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -33,8 +42,14 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + var o = new AppDebug(); + o.Level = Debug.Level; + + var body = JsonConvert.SerializeObject(o, Formatting.Indented); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.Write(body, false); context.Response.End(); } @@ -77,8 +92,25 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + if (context.Request.ContentLength < 0) return; + + var bytes = new Byte[context.Request.ContentLength]; + context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); + var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); + //Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); + + var o = new AppDebug(); + var requestBody = JsonConvert.DeserializeAnonymousType(data, o); + + Debug.SetDebugLevel(requestBody.Level); + + o.Level = Debug.Level; + + var responseBody = JsonConvert.SerializeObject(o, Formatting.Indented); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.Write(responseBody, false); context.Response.End(); } @@ -104,4 +136,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers context.Response.End(); } } + + public class AppDebug + { + [JsonProperty("level", NullValueHandling = NullValueHandling.Ignore)] + public int Level { get; set; } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index ea7b0d0f..fb9e8261 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -1,10 +1,18 @@ -using Crestron.SimplSharp.WebScripting; +using System; +using System.Text; +using Crestron.SimplSharp.WebScripting; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevJsonRequestHandler : WebApiBaseRequestHandler { + private const string Key = "DevJsonRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -77,8 +85,17 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + if (context.Request.ContentLength < 0) return; + + var bytes = new Byte[context.Request.ContentLength]; + context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); + var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); + Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); + + DeviceJsonApi.DoDeviceActionWithJson(data); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; context.Response.End(); } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs index cc7a1528..faa0fff3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -1,10 +1,8 @@ -using System.Diagnostics; -using System.Linq; +using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; -using Debug = PepperDash.Core.Debug; namespace PepperDash.Essentials.Core.Web.RequestHandlers { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index 08eb6853..34ab4f77 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -1,10 +1,19 @@ -using Crestron.SimplSharp.WebScripting; +using System; +using System.Text; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevPropsRequestHandler : WebApiBaseRequestHandler { + private const string Key = "DevPropsRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -77,8 +86,34 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + if (context.Request.ContentLength < 0) return; + + var bytes = new Byte[context.Request.ContentLength]; + context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); + var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); + //Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); + + var o = new DeviceActionWrapper(); + var body = JsonConvert.DeserializeAnonymousType(data, o); + + if (string.IsNullOrEmpty(body.DeviceKey)) + { + Debug.Console(Info, "[{0}] Request body is null or empty", Key.ToLower()); + + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var deviceProps = DeviceJsonApi.GetProperties(body.DeviceKey); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.ContentType = "application/json"; + context.Response.ContentEncoding = Encoding.UTF8; + context.Response.Write(deviceProps, false); context.Response.End(); } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs index 489bfd55..8cfc7315 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs @@ -77,8 +77,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + DeviceManager.DisableAllDeviceStreamDebugging(); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; context.Response.End(); } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index a8b36eb5..ab0e4d8d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -1,7 +1,6 @@ using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index 58280f57..ce026b04 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -1,10 +1,20 @@ -using Crestron.SimplSharp.WebScripting; +using System; +using System.Text; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler { + private const string Key = "SetDeviceStreamDebugRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -77,8 +87,39 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + if (context.Request.ContentLength < 0) return; + + var bytes = new Byte[context.Request.ContentLength]; + context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); + var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); + Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); + + var o = new + { + DeviceKey = "", + Type = "", + Timeout = 15 + }; + + var body = JsonConvert.DeserializeAnonymousType(data, o); + + if (string.IsNullOrEmpty(body.DeviceKey) || string.IsNullOrEmpty(body.Type) + || !body.Type.ToLower().Contains("off") + || !body.Type.ToLower().Contains("tx") + || !body.Type.ToLower().Contains("rx") + || !body.Type.ToLower().Contains("both")) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + DeviceManager.SetDeviceStreamDebugging(string.Format("setdevicestreamdebug {0} {1} {2}", body.DeviceKey, body.Type, body.Timeout)); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; context.Response.End(); } From c68d46f9713be87cc322401443bf868c56265ba5 Mon Sep 17 00:00:00 2001 From: jdevito Date: Tue, 31 Jan 2023 18:27:14 -0600 Subject: [PATCH 11/26] fix: Updated showconfig, gettypes, getjoinmap handlers; updated BridgeBase to expose joinmaps; updated DeviceFactory to introduce method for getting dictionary --- .../Bridges/BridgeBase.cs | 2 +- .../Factory/DeviceFactory.cs | 12 ++ .../PepperDash_Essentials_Core.csproj | 4 +- .../Web/EssemtialsWebApi.cs | 16 +- .../RequestHandlers/DevJsonRequestHandler.cs | 17 +- .../GetJoinMapForBridgeKeyRequestHandler.cs | 175 ++++++++++++++++ .../GetJoinMapForDeviceKeyRequestHandler.cs | 196 ++++++++++++++++++ ...r.cs => GetTypesByFilterRequestHandler.cs} | 66 +++++- .../RequestHandlers/GetTypesRequestHandler.cs | 43 +++- .../SetDeviceStreamDebugRequestHandler.cs | 1 - .../ShowConfigRequestHandler.cs | 16 +- 11 files changed, 525 insertions(+), 23 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs rename essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/{GetJoinMapRequestHandler.cs => GetTypesByFilterRequestHandler.cs} (56%) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs index 11b8f4ff..cb937235 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs @@ -109,7 +109,7 @@ namespace PepperDash.Essentials.Core.Bridges { public EiscApiPropertiesConfig PropertiesConfig { get; private set; } - protected Dictionary JoinMaps { get; private set; } + public Dictionary JoinMaps { get; private set; } public BasicTriList Eisc { get; private set; } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs index ebdc87b1..9cbd8731 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs @@ -204,5 +204,17 @@ namespace PepperDash.Essentials.Core Description: {2}", type.Key, cType, description); } } + + /// + /// Returns the device factory dictionary + /// + /// + /// + public static Dictionary GetDeviceFactoryDictionary(string filter) + { + return !string.IsNullOrEmpty(filter) + ? FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value) + : FactoryMethods; + } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 077bdac9..4742a04f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -198,6 +198,8 @@ + + @@ -206,7 +208,7 @@ - + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs index 8b0f7c86..149cc021 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs @@ -128,25 +128,25 @@ namespace PepperDash.Essentials.Core.Web Name = "ShowConfig", RouteHandler = new ShowConfigRequestHandler() }, - new HttpCwsRoute("gettypes/all") + new HttpCwsRoute("gettypes") { - Name = "GetTypesAll", + Name = "GetTypes", RouteHandler = new GetTypesRequestHandler() }, new HttpCwsRoute("gettypes/{filter}") { Name = "GetTypesByFilter", - RouteHandler = new GetTypesRequestHandler() + RouteHandler = new GetTypesByFilterRequestHandler() }, - new HttpCwsRoute("getjoinmap/{bridgeKey}/all") + new HttpCwsRoute("getjoinmap/{bridgeKey}") { - Name = "GetJoinMapsByBridgeKey", - RouteHandler = new GetJoinMapRequestHandler() + Name = "GetJoinMapsForBridgeKey", + RouteHandler = new GetJoinMapForBridgeKeyRequestHandler() }, new HttpCwsRoute("getjoinmap/{bridgeKey}/{deviceKey}") { - Name = "GetJoinMapsForBridgeKeyFilteredByDeviceKey", - RouteHandler = new GetJoinMapRequestHandler() + Name = "GetJoinMapsForDeviceKey", + RouteHandler = new GetJoinMapForDeviceKeyRequestHandler() } }; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index fb9e8261..d4cdac38 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -92,11 +92,20 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); - DeviceJsonApi.DoDeviceActionWithJson(data); + try + { + DeviceJsonApi.DoDeviceActionWithJson(data); - context.Response.StatusCode = 200; - context.Response.StatusDescription = "OK"; - context.Response.End(); + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.End(); + } + catch (Exception ex) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + } } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs new file mode 100644 index 00000000..0421266f --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs @@ -0,0 +1,175 @@ +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; +using PepperDash.Essentials.Core.Bridges; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class GetJoinMapForBridgeKeyRequestHandler : WebApiBaseRequestHandler + { + private const string Key = "GetJoinMapForBridgeKeyRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + 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 routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); + Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); + + + object bridgeObj; + if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj)) + { + Debug.Console(Verbose, "TryGetValue bridgeKey failed"); + + 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; + if (joinMap == null) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore, + MissingMemberHandling = MissingMemberHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore, + TypeNameHandling = TypeNameHandling.None + }); + Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + + 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(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs new file mode 100644 index 00000000..863e3d29 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs @@ -0,0 +1,196 @@ +using System.Collections.Generic; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; +using PepperDash.Essentials.Core.Bridges; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class GetJoinMapForDeviceKeyRequestHandler : WebApiBaseRequestHandler + { + private const string Key = "GetJoinMapForDeviceKeyRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + 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 routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); + Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); + + + object bridgeObj; + if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj)) + { + Debug.Console(Verbose, "TryGetValue bridgeKey failed"); + + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + object deviceObj; + if (!routeData.Values.TryGetValue("deviceKey", out deviceObj)) + { + Debug.Console(Verbose, "TryGetValue deviceKey failed"); + + 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; + } + + JoinMapBaseAdvanced deviceJoinMap; + if (!bridge.JoinMaps.TryGetValue(deviceObj.ToString(), out deviceJoinMap)) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var joinMap = new Dictionary + { + { + 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 + }); + Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + + 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(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs similarity index 56% rename from essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs rename to essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs index c08846e2..42cf84c0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs @@ -1,10 +1,18 @@ using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; +using PepperDash.Essentials.Core.Bridges; namespace PepperDash.Essentials.Core.Web.RequestHandlers { - public class GetJoinMapRequestHandler : WebApiBaseRequestHandler + public class GetTypesByFilterRequestHandler : WebApiBaseRequestHandler { + private const string Key = "GetTypesByFilterRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -33,8 +41,60 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + var routeData = context.Request.RouteData; + if (routeData == null) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + + var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); + Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); + + + object filterObj; + if (!routeData.Values.TryGetValue("filter", out filterObj)) + { + Debug.Console(Verbose, "TryGetValue filter failed"); + + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var types = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString()); + if (types == null) + { + Debug.Console(Verbose, "Get device type from dictionary failed"); + + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore, + MissingMemberHandling = MissingMemberHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore, + TypeNameHandling = TypeNameHandling.None + }); + Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + + 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(); } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs index ce33866d..bd1b967a 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -1,10 +1,18 @@ -using Crestron.SimplSharp.WebScripting; +using System.Linq; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetTypesRequestHandler : WebApiBaseRequestHandler { + private const string Key = "GetTypesRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -33,8 +41,37 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + // TODO [ ] DeviceFactory.FactoryMethods dictionary is private and the method GetDeviceFactoryTypes has a return type void + // added new public method to return the DeviceFactory.FactoryMethod dictionary + var types = DeviceFactory.GetDeviceFactoryDictionary(null); + if (types == null) + { + Debug.Console(Verbose, "Get device factory dictionary failed"); + + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + types.OrderBy(t => t.Key); + + var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore, + MissingMemberHandling = MissingMemberHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore, + TypeNameHandling = TypeNameHandling.None + }); + //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + + 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(); } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index ce026b04..989cb663 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -2,7 +2,6 @@ using System.Text; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs index 5edb50da..e8621e33 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -1,10 +1,17 @@ using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; using PepperDash.Core.Web.RequestHandlers; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class ShowConfigRequestHandler : WebApiBaseRequestHandler { + private const string Key = "ShowConfigRequestHandler"; + private const uint Trace = 0; + private const uint Info = 0; + private const uint Verbose = 0; + /// /// Handles CONNECT method requests /// @@ -33,8 +40,13 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + 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(); } From 15efed02a5332231eabdb69eec68d5a6d1375308 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 09:43:52 -0600 Subject: [PATCH 12/26] fix: resolved issue with GetTypes request handlers causing a 500 error response; updated debug constants to default levels --- .../Factory/DeviceFactory.cs | 6 +- .../RequestHandlers/AppDebugRequestHandler.cs | 4 +- .../RequestHandlers/DefaultRequestHandler.cs | 36 +++++----- .../RequestHandlers/DevJsonRequestHandler.cs | 4 +- .../RequestHandlers/DevListRequestHandler.cs | 4 +- .../RequestHandlers/DevPropsRequestHandler.cs | 4 +- .../DisableAllStreamDebugRequestHandler.cs | 5 ++ .../GetJoinMapForBridgeKeyRequestHandler.cs | 4 +- .../GetJoinMapForDeviceKeyRequestHandler.cs | 4 +- .../GetTypesByFilterRequestHandler.cs | 57 ++++++++------- .../RequestHandlers/GetTypesRequestHandler.cs | 69 ++++++++++++------- .../ReportVersionsRequestHandler.cs | 4 +- .../SetDeviceStreamDebugRequestHandler.cs | 4 +- .../ShowConfigRequestHandler.cs | 4 +- 14 files changed, 122 insertions(+), 87 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs index 9cbd8731..bad3e531 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs @@ -212,9 +212,9 @@ namespace PepperDash.Essentials.Core /// public static Dictionary GetDeviceFactoryDictionary(string filter) { - return !string.IsNullOrEmpty(filter) - ? FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value) - : FactoryMethods; + return string.IsNullOrEmpty(filter) + ? FactoryMethods + : FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value); } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs index f88ae849..ad413b7f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "AppDebugRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs index 2cd55d4d..19bc8cb3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs @@ -16,8 +16,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleConnect(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -27,8 +27,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleDelete(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -38,8 +38,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -49,8 +49,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleHead(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -60,8 +60,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleOptions(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -71,8 +71,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePatch(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -82,8 +82,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -93,8 +93,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePut(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } @@ -104,8 +104,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleTrace(HttpCwsContext context) { - context.Response.StatusCode = 501; - context.Response.StatusDescription = "Not Implemented"; + context.Response.StatusCode = 418; + context.Response.StatusDescription = "I'm a teapot"; context.Response.End(); } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index d4cdac38..300b36f7 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -10,8 +10,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "DevJsonRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs index faa0fff3..a10e66fb 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -10,8 +10,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "DevListRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index 34ab4f77..9f254ec5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "DevPropsRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs index 8cfc7315..cec258be 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs @@ -5,6 +5,11 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DisableAllStreamDebugRequestHandler : WebApiBaseRequestHandler { + private const string Key = "DisableAllStreamDebugRequestHandler"; + private const uint Trace = 0; + private const uint Info = 1; + private const uint Verbose = 2; + /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs index 0421266f..766cda57 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs @@ -10,8 +10,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "GetJoinMapForBridgeKeyRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs index 863e3d29..fd7a11dd 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs @@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "GetJoinMapForDeviceKeyRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs index 42cf84c0..ee839c06 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs @@ -1,8 +1,9 @@ -using Crestron.SimplSharp.WebScripting; +using System; +using System.Linq; +using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; -using PepperDash.Essentials.Core.Bridges; namespace PepperDash.Essentials.Core.Web.RequestHandlers { @@ -10,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "GetTypesByFilterRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests @@ -51,10 +52,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); - Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); - + Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson); object filterObj; if (!routeData.Values.TryGetValue("filter", out filterObj)) @@ -68,11 +67,15 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var types = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString()); + var types = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString()).Select(type => new + { + Type = type.Key, + Description = type.Value.Description, + CType = type.Value.CType == null ? "---" : type.Value.CType.ToString() + }).Cast().ToList(); + if (types == null) { - Debug.Console(Verbose, "Get device type from dictionary failed"); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); @@ -80,22 +83,28 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings + try { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore, - MissingMemberHandling = MissingMemberHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore, - TypeNameHandling = TypeNameHandling.None - }); - Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + var js = JsonConvert.SerializeObject(types, Formatting.Indented); + //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); - 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(); + 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(); + } + catch (Exception ex) + { + Debug.Console(Info, "[{0}] HandleGet Exception Message: {1}", Key.ToLower(), ex.Message); + Debug.Console(Verbose, "[{0}] HandleGet Exception StackTrace: {1}", Key.ToLower(), ex.StackTrace); + if (ex.InnerException != null) Debug.Console(Verbose, "[{0}] HandleGet Exception InnerException: {1}", Key.ToLower(), ex.InnerException); + + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Internal Server Error"; + context.Response.End(); + } } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs index bd1b967a..16f1f6b0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; using PepperDash.Core; @@ -10,8 +12,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "GetTypesRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests @@ -41,13 +43,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - // TODO [ ] DeviceFactory.FactoryMethods dictionary is private and the method GetDeviceFactoryTypes has a return type void - // added new public method to return the DeviceFactory.FactoryMethod dictionary - var types = DeviceFactory.GetDeviceFactoryDictionary(null); - if (types == null) + var routeData = context.Request.RouteData; + if (routeData == null) { - Debug.Console(Verbose, "Get device factory dictionary failed"); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); @@ -55,24 +53,47 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - types.OrderBy(t => t.Key); + var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); + Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson); - var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings + var types = DeviceFactory.GetDeviceFactoryDictionary(string.Empty).Select(type => new { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore, - MissingMemberHandling = MissingMemberHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore, - TypeNameHandling = TypeNameHandling.None - }); - //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + Type = type.Key, + Description = type.Value.Description, + CType = type.Value.CType == null ? "---" : type.Value.CType.ToString() + }).Cast().ToList(); - 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(); + if (types == null) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + try + { + var js = JsonConvert.SerializeObject(types, Formatting.Indented); + //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + + 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(); + } + catch (Exception ex) + { + Debug.Console(Info, "[{0}] HandleGet Exception Message: {1}", Key.ToLower(), ex.Message); + Debug.Console(Verbose, "[{0}] HandleGet Exception StackTrace: {1}", Key.ToLower(), ex.StackTrace); + if (ex.InnerException != null) Debug.Console(Verbose, "[{0}] HandleGet Exception InnerException: {1}", Key.ToLower(), ex.InnerException); + + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Internal Server Error"; + context.Response.End(); + } } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index ab0e4d8d..90960902 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -9,8 +9,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "ReportVersionsRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index 989cb663..0874db11 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "SetDeviceStreamDebugRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs index e8621e33..d3cbbe99 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -9,8 +9,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { private const string Key = "ShowConfigRequestHandler"; private const uint Trace = 0; - private const uint Info = 0; - private const uint Verbose = 0; + private const uint Info = 1; + private const uint Verbose = 2; /// /// Handles CONNECT method requests From 0793a0909525bfd87a3e93fef2b9c707fba96a5b Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 11:15:13 -0600 Subject: [PATCH 13/26] feat: added static methods for GetJoinMaps, added GetFeedbacksForDevice request handler --- .../PepperDash_Essentials_Core.csproj | 2 + .../Web/EssemtialsWebApi.cs | 5 + .../GetFeedbacksForDeviceRequestHandler.cs | 191 ++++++++++++++++++ .../GetJoinMapForBridgeKeyRequestHandler.cs | 22 +- .../GetJoinMapForDeviceKeyRequestHandler.cs | 10 +- .../Web/RequestHandlers/GetJoinMapHelpers.cs | 37 ++++ 6 files changed, 246 insertions(+), 21 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapHelpers.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 4742a04f..361d64c9 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -198,6 +198,8 @@ + + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs index 149cc021..2299cfbd 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs @@ -147,6 +147,11 @@ namespace PepperDash.Essentials.Core.Web { Name = "GetJoinMapsForDeviceKey", RouteHandler = new GetJoinMapForDeviceKeyRequestHandler() + }, + new HttpCwsRoute("feedbacks/{deviceKey}") + { + Name = "GetFeedbacksForDeviceKey", + RouteHandler = new GetFeedbacksForDeviceRequestHandler() } }; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs new file mode 100644 index 00000000..06c7b4af --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs @@ -0,0 +1,191 @@ +using System; +using System.Linq; +using System.Runtime.CompilerServices; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class GetFeedbacksForDeviceRequestHandler : WebApiBaseRequestHandler + { + private const string Key = "GetFeedbacksForDeviceRequestHandler"; + private const uint Trace = 0; + private const uint Info = 1; + private const uint Verbose = 2; + + /// + /// Handles CONNECT method requests + /// + /// + protected override void HandleConnect(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles DELETE method requests + /// + /// + protected override void HandleDelete(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles GET method requests + /// + /// + 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 routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); + //Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson); + + object deviceObj; + if (!routeData.Values.TryGetValue("deviceKey", out deviceObj)) + { + Debug.Console(Verbose, "TryGetValue filter failed"); + + 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() + where !string.IsNullOrEmpty(feedback.Key) + select new + { + FeedbackKey = feedback.Key, + Value = feedback.BoolValue + }; + + var intFeedback = + from feedback in device.Feedbacks.OfType() + where !string.IsNullOrEmpty(feedback.Key) + select new + { + FeedbackKey = feedback.Key, + Value = feedback.IntValue + }; + + var stringFeedback = + from feedback in device.Feedbacks.OfType() + where !string.IsNullOrEmpty(feedback.Key) + select new + { + FeedbackKey = feedback.Key, + Value = feedback.StringValue ?? string.Empty + }; + + var respnse = new + { + BoolValues = boolFeedback, + IntValues = intFeedback, + SerialValues = stringFeedback + }; + + var final = JsonConvert.SerializeObject(respnse, 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(final, false); + context.Response.End(); + } + + /// + /// Handles HEAD method requests + /// + /// + protected override void HandleHead(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles OPTIONS method requests + /// + /// + protected override void HandleOptions(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PATCH method requests + /// + /// + protected override void HandlePatch(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles PUT method requests + /// + /// + protected override void HandlePut(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + + /// + /// Handles TRACE method requests + /// + /// + protected override void HandleTrace(HttpCwsContext context) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Not Implemented"; + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs index 766cda57..d7a5a0d3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs @@ -1,4 +1,7 @@ -using Crestron.SimplSharp.WebScripting; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; @@ -51,10 +54,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); - Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); - + //Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); object bridgeObj; if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj)) @@ -78,7 +79,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var joinMap = bridge.JoinMaps; + var joinMap = bridge.JoinMaps.Select(j => GetJoinMapHelpers.MapJoinToObject(j)).ToList(); if (joinMap == null) { context.Response.StatusCode = 400; @@ -88,14 +89,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore, - MissingMemberHandling = MissingMemberHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore, - TypeNameHandling = TypeNameHandling.None - }); + var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented); Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); context.Response.StatusCode = 200; @@ -171,5 +165,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers context.Response.StatusDescription = "Not Implemented"; context.Response.End(); } + + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs index fd7a11dd..da12303d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; using PepperDash.Core; @@ -100,15 +101,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - - var joinMap = new Dictionary - { - { - deviceObj.ToString(), - deviceJoinMap - } - }; + var joinMap = GetJoinMapHelpers.MapJoinToObject(deviceObj.ToString(), deviceJoinMap); var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapHelpers.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapHelpers.cs new file mode 100644 index 00000000..8789067c --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapHelpers.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Linq; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class GetJoinMapHelpers + { + public static object MapJoinToObject(string key, JoinMapBaseAdvanced join) + { + var kp = new KeyValuePair(key, join); + + return MapJoinToObject(kp); + } + + public static object MapJoinToObject(KeyValuePair join) + { + return new + { + DeviceKey = join.Key, + Joins = join.Value.Joins.Select(j => MapJoinDatacompleteToObject(j)) + }; + } + + public static object MapJoinDatacompleteToObject(KeyValuePair 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() + }; + } + } +} \ No newline at end of file From 55a5cc53c990a2b37138ae4810d47b61e0b5b941 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 11:30:35 -0600 Subject: [PATCH 14/26] refactor: moved and renamed GetJoinHelper class to EssentialsWebApiHelpers, added func for loaded assemblies --- .../PepperDash_Essentials_Core.csproj | 2 +- ...pHelpers.cs => EssentialsWebApiHelpers.cs} | 13 ++++++++++-- .../RequestHandlers/AppDebugRequestHandler.cs | 20 ++++++------------- .../RequestHandlers/DefaultRequestHandler.cs | 5 ----- .../GetJoinMapForBridgeKeyRequestHandler.cs | 2 +- .../GetJoinMapForDeviceKeyRequestHandler.cs | 2 +- .../ReportVersionsRequestHandler.cs | 20 +++++++++---------- 7 files changed, 29 insertions(+), 35 deletions(-) rename essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/{RequestHandlers/GetJoinMapHelpers.cs => EssentialsWebApiHelpers.cs} (76%) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 361d64c9..9c4a73c5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -199,7 +199,7 @@ - + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapHelpers.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs similarity index 76% rename from essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapHelpers.cs rename to essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs index 8789067c..e978657d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapHelpers.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs @@ -1,10 +1,19 @@ using System.Collections.Generic; using System.Linq; -namespace PepperDash.Essentials.Core.Web.RequestHandlers +namespace PepperDash.Essentials.Core.Web { - public class GetJoinMapHelpers + public class EssentialsWebApiHelpers { + public static object MapToAssemblyObject(LoadedAssembly assembly) + { + return new + { + Name = assembly.Name, + Version = assembly.Version + }; + } + public static object MapJoinToObject(string key, JoinMapBaseAdvanced join) { var kp = new KeyValuePair(key, join); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs index ad413b7f..134fbbf2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -9,11 +9,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class AppDebugRequestHandler : WebApiBaseRequestHandler { - private const string Key = "AppDebugRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -42,10 +37,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - var o = new AppDebug(); - o.Level = Debug.Level; + var appDebug = new AppDebug {Level = Debug.Level}; - var body = JsonConvert.SerializeObject(o, Formatting.Indented); + var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; @@ -97,16 +91,14 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var bytes = new Byte[context.Request.ContentLength]; context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); - //Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); - var o = new AppDebug(); - var requestBody = JsonConvert.DeserializeAnonymousType(data, o); + var appDebug = new AppDebug(); + var requestBody = JsonConvert.DeserializeAnonymousType(data, appDebug); Debug.SetDebugLevel(requestBody.Level); - o.Level = Debug.Level; - - var responseBody = JsonConvert.SerializeObject(o, Formatting.Indented); + appDebug.Level = Debug.Level; + var responseBody = JsonConvert.SerializeObject(appDebug, Formatting.Indented); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs index 19bc8cb3..4ffa500a 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DefaultRequestHandler.cs @@ -5,11 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DefaultRequestHandler : WebApiBaseRequestHandler { - private const string Key = "DefaultRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs index d7a5a0d3..dfc6fcb8 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs @@ -79,7 +79,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var joinMap = bridge.JoinMaps.Select(j => GetJoinMapHelpers.MapJoinToObject(j)).ToList(); + var joinMap = bridge.JoinMaps.Select(j => EssentialsWebApiHelpers.MapJoinToObject(j)).ToList(); if (joinMap == null) { context.Response.StatusCode = 400; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs index da12303d..a71f193c 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs @@ -102,7 +102,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var joinMap = GetJoinMapHelpers.MapJoinToObject(deviceObj.ToString(), deviceJoinMap); + var joinMap = EssentialsWebApiHelpers.MapJoinToObject(deviceObj.ToString(), deviceJoinMap); var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index 90960902..b12cba09 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -7,11 +7,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class ReportVersionsRequestHandler : WebApiBaseRequestHandler { - private const string Key = "ReportVersionsRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -40,11 +35,15 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - var assemblies = PluginLoader.LoadedAssemblies.Select(assembly => new + var loadAssemblies = PluginLoader.LoadedAssemblies; + if (loadAssemblies == null) { - Name = assembly.Name, - Version = assembly.Version - }).Cast().ToList(); + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; + context.Response.End(); + } + + var assemblies = loadAssemblies.Select(a => EssentialsWebApiHelpers.MapToAssemblyObject(a)).ToList(); var js = JsonConvert.SerializeObject(assemblies, Formatting.Indented, new JsonSerializerSettings { @@ -54,8 +53,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers DefaultValueHandling = DefaultValueHandling.Ignore, TypeNameHandling = TypeNameHandling.None }); - //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); - + context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; context.Response.ContentType = "application/json"; From 8bb670c43b50bd47e93e91e81b34ce9d71c9a9c8 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 11:31:52 -0600 Subject: [PATCH 15/26] fix: changed response status to 500 if loaded assemblies is null --- .../Web/RequestHandlers/ReportVersionsRequestHandler.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index b12cba09..117363c6 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -38,9 +38,11 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var loadAssemblies = PluginLoader.LoadedAssemblies; if (loadAssemblies == null) { - context.Response.StatusCode = 404; - context.Response.StatusDescription = "Not Found"; + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Internal Server Error"; context.Response.End(); + + return; } var assemblies = loadAssemblies.Select(a => EssentialsWebApiHelpers.MapToAssemblyObject(a)).ToList(); From 087e74b2075248c2a09b13489c9ae02bc3ee80e0 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 11:32:19 -0600 Subject: [PATCH 16/26] fix: removed json serial settings --- .../Web/RequestHandlers/ReportVersionsRequestHandler.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs index 117363c6..6ba3cb7a 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -47,14 +47,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var assemblies = loadAssemblies.Select(a => EssentialsWebApiHelpers.MapToAssemblyObject(a)).ToList(); - var js = JsonConvert.SerializeObject(assemblies, Formatting.Indented, new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore, - MissingMemberHandling = MissingMemberHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore, - TypeNameHandling = TypeNameHandling.None - }); + var js = JsonConvert.SerializeObject(assemblies, Formatting.Indented); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; From faaa2a354eb53c7f06a01d6d120dad7599b08fe1 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 11:34:36 -0600 Subject: [PATCH 17/26] refactor: removed debug statements, added 400 return if request content length is < 0 --- .../RequestHandlers/DevJsonRequestHandler.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index 300b36f7..36bfd7f6 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -8,11 +8,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevJsonRequestHandler : WebApiBaseRequestHandler { - private const string Key = "DevJsonRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -85,12 +80,20 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - if (context.Request.ContentLength < 0) return; + if (context.Request.ContentLength < 0) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } var bytes = new Byte[context.Request.ContentLength]; context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); - Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); + + //Debug.Console(0, "Request data:\n{0}", data); try { From 4dc6d5b5accc9155e020172d0c547e7bad890a66 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 11:50:26 -0600 Subject: [PATCH 18/26] refactor: devlist request handler, added static method for creating list --- .../Web/EssentialsWebApiHelpers.cs | 18 +++++++++-- .../RequestHandlers/DevListRequestHandler.cs | 31 +++++++------------ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs index e978657d..7186c9ec 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using PepperDash.Core; namespace PepperDash.Essentials.Core.Web { @@ -14,23 +15,34 @@ namespace PepperDash.Essentials.Core.Web }; } + public static object MapToDeviceListObject(IKeyed device) + { + return new + { + Key = device.Key, + Name = (device is IKeyName) + ? (device as IKeyName).Name + : "---" + }; + } + public static object MapJoinToObject(string key, JoinMapBaseAdvanced join) { var kp = new KeyValuePair(key, join); return MapJoinToObject(kp); } - + public static object MapJoinToObject(KeyValuePair join) { return new { DeviceKey = join.Key, - Joins = join.Value.Joins.Select(j => MapJoinDatacompleteToObject(j)) + Joins = join.Value.Joins.Select(j => MapJoinDataCompleteToObject(j)) }; } - public static object MapJoinDatacompleteToObject(KeyValuePair joinData) + public static object MapJoinDataCompleteToObject(KeyValuePair joinData) { return new { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs index a10e66fb..0c57ded0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -8,11 +8,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevListRequestHandler : WebApiBaseRequestHandler { - private const string Key = "DevListRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -42,24 +37,20 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers 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) => System.String.Compare(a.Key, b.Key, System.StringComparison.Ordinal)); - var devices = allDevices.Select(device => new - { - Key = device.Key, - Name = device is IKeyName ? (device as IKeyName).Name : "---" + var deviceList = allDevices.Select(d => EssentialsWebApiHelpers.MapToDeviceListObject(d)).ToList(); - }).Cast().ToList(); - - var js = JsonConvert.SerializeObject(devices, Formatting.Indented, new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore, - MissingMemberHandling = MissingMemberHandling.Ignore, - DefaultValueHandling = DefaultValueHandling.Ignore, - TypeNameHandling = TypeNameHandling.None - }); - //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + var js = JsonConvert.SerializeObject(deviceList, Formatting.Indented); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; From 12f3f519ccef5caf2327422a0825fa856c2de2eb Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 11:58:22 -0600 Subject: [PATCH 19/26] refactor: cleaned up devprops handler --- .../RequestHandlers/DevPropsRequestHandler.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index 9f254ec5..1a2e9157 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -9,11 +9,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DevPropsRequestHandler : WebApiBaseRequestHandler { - private const string Key = "DevPropsRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -91,15 +86,12 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var bytes = new Byte[context.Request.ContentLength]; context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); - //Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); var o = new DeviceActionWrapper(); var body = JsonConvert.DeserializeAnonymousType(data, o); if (string.IsNullOrEmpty(body.DeviceKey)) { - Debug.Console(Info, "[{0}] Request body is null or empty", Key.ToLower()); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); @@ -108,6 +100,14 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers } var deviceProps = DeviceJsonApi.GetProperties(body.DeviceKey); + if (deviceProps == null || deviceProps.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"; From 1c1eabcef682e802b81c1d86a6c1caa6f4b6117f Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 12:02:05 -0600 Subject: [PATCH 20/26] refactor: cleaned up unused using statements --- .../RequestHandlers/DevJsonRequestHandler.cs | 1 - .../RequestHandlers/DevListRequestHandler.cs | 1 - .../RequestHandlers/DevPropsRequestHandler.cs | 1 - .../DisableAllStreamDebugRequestHandler.cs | 5 ---- .../GetFeedbacksForDeviceRequestHandler.cs | 15 +--------- .../GetJoinMapForBridgeKeyRequestHandler.cs | 20 ++----------- .../GetJoinMapForDeviceKeyRequestHandler.cs | 30 ++++--------------- .../RequestHandlers/GetTypesRequestHandler.cs | 1 - 8 files changed, 10 insertions(+), 64 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index 36bfd7f6..7806095e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -1,7 +1,6 @@ using System; using System.Text; using Crestron.SimplSharp.WebScripting; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs index 0c57ded0..c34542e2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevListRequestHandler.cs @@ -1,7 +1,6 @@ using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index 1a2e9157..c9f89c46 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -2,7 +2,6 @@ using System.Text; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs index cec258be..8cfc7315 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DisableAllStreamDebugRequestHandler.cs @@ -5,11 +5,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DisableAllStreamDebugRequestHandler : WebApiBaseRequestHandler { - private const string Key = "DisableAllStreamDebugRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs index 06c7b4af..7e5c7be2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs @@ -1,20 +1,12 @@ -using System; -using System.Linq; -using System.Runtime.CompilerServices; +using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetFeedbacksForDeviceRequestHandler : WebApiBaseRequestHandler { - private const string Key = "GetFeedbacksForDeviceRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -53,14 +45,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - //var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); - //Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson); - object deviceObj; if (!routeData.Values.TryGetValue("deviceKey", out deviceObj)) { - Debug.Console(Verbose, "TryGetValue filter failed"); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs index dfc6fcb8..d037b9e6 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForBridgeKeyRequestHandler.cs @@ -1,9 +1,6 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; using PepperDash.Essentials.Core.Bridges; @@ -11,11 +8,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetJoinMapForBridgeKeyRequestHandler : WebApiBaseRequestHandler { - private const string Key = "GetJoinMapForBridgeKeyRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -54,14 +46,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); - //Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); - object bridgeObj; if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj)) { - Debug.Console(Verbose, "TryGetValue bridgeKey failed"); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); @@ -82,15 +69,14 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var joinMap = bridge.JoinMaps.Select(j => EssentialsWebApiHelpers.MapJoinToObject(j)).ToList(); if (joinMap == null) { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; context.Response.End(); return; } var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented); - Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs index a71f193c..63ca47a0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetJoinMapForDeviceKeyRequestHandler.cs @@ -1,8 +1,5 @@ -using System.Collections.Generic; -using System.Linq; -using Crestron.SimplSharp.WebScripting; +using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; using PepperDash.Essentials.Core.Bridges; @@ -10,11 +7,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetJoinMapForDeviceKeyRequestHandler : WebApiBaseRequestHandler { - private const string Key = "GetJoinMapForDeviceKeyRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -53,16 +45,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - - var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); - Debug.Console(Verbose, "routeData:\n{0}", routeDataJson); - - object bridgeObj; if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj)) { - Debug.Console(Verbose, "TryGetValue bridgeKey failed"); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); @@ -73,8 +58,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers object deviceObj; if (!routeData.Values.TryGetValue("deviceKey", out deviceObj)) { - Debug.Console(Verbose, "TryGetValue deviceKey failed"); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); @@ -85,8 +68,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var bridge = DeviceManager.GetDeviceForKey(bridgeObj.ToString()) as EiscApiAdvanced; if (bridge == null) { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; context.Response.End(); return; @@ -95,8 +78,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers JoinMapBaseAdvanced deviceJoinMap; if (!bridge.JoinMaps.TryGetValue(deviceObj.ToString(), out deviceJoinMap)) { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Internal Server Error"; context.Response.End(); return; @@ -111,8 +94,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers DefaultValueHandling = DefaultValueHandling.Ignore, TypeNameHandling = TypeNameHandling.None }); - Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); - + context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; context.Response.ContentType = "application/json"; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs index 16f1f6b0..d83660f7 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; From a3346d5ef4a93f3bf78feebe7ace855213569c74 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 12:22:52 -0600 Subject: [PATCH 21/26] refactor: added 400 bad request responses --- .../Web/EssentialsWebApiHelpers.cs | 17 ++++++ .../RequestHandlers/AppDebugRequestHandler.cs | 9 ++- .../RequestHandlers/DevPropsRequestHandler.cs | 9 ++- .../GetTypesByFilterRequestHandler.cs | 57 +++++-------------- .../RequestHandlers/GetTypesRequestHandler.cs | 55 +++++------------- .../SetDeviceStreamDebugRequestHandler.cs | 18 +++--- .../ShowConfigRequestHandler.cs | 5 -- 7 files changed, 68 insertions(+), 102 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs index 7186c9ec..37a749f9 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs @@ -54,5 +54,22 @@ namespace PepperDash.Essentials.Core.Web JoinCapabilities = joinData.Value.Metadata.JoinCapabilities.ToString() }; } + + public static object MapDeviceTypeToObject(string key, DeviceFactoryWrapper device) + { + var kp = new KeyValuePair(key, device); + + return MapDeviceTypeToObject(kp); + } + + public static object MapDeviceTypeToObject(KeyValuePair device) + { + return new + { + Type = device.Key, + Description = device.Value.Description, + CType = device.Value.CType == null ? "---": device.Value.CType.ToString() + }; + } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs index 134fbbf2..4d6ff236 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -86,7 +86,14 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - if (context.Request.ContentLength < 0) return; + if (context.Request.ContentLength < 0) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } var bytes = new Byte[context.Request.ContentLength]; context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index c9f89c46..4ff70aad 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -80,7 +80,14 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - if (context.Request.ContentLength < 0) return; + if (context.Request.ContentLength < 0) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } var bytes = new Byte[context.Request.ContentLength]; context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs index ee839c06..be7347fb 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs @@ -1,19 +1,12 @@ -using System; -using System.Linq; +using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetTypesByFilterRequestHandler : WebApiBaseRequestHandler { - private const string Key = "GetTypesByFilterRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -52,14 +45,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); - Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson); - object filterObj; if (!routeData.Values.TryGetValue("filter", out filterObj)) { - Debug.Console(Verbose, "TryGetValue filter failed"); - context.Response.StatusCode = 400; context.Response.StatusDescription = "Bad Request"; context.Response.End(); @@ -67,44 +55,25 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var types = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString()).Select(type => new + var deviceFactory = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString()); + if (deviceFactory == null) { - Type = type.Key, - Description = type.Value.Description, - CType = type.Value.CType == null ? "---" : type.Value.CType.ToString() - }).Cast().ToList(); - - if (types == null) - { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; context.Response.End(); return; } - try - { - var js = JsonConvert.SerializeObject(types, Formatting.Indented); - //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + 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(); - } - catch (Exception ex) - { - Debug.Console(Info, "[{0}] HandleGet Exception Message: {1}", Key.ToLower(), ex.Message); - Debug.Console(Verbose, "[{0}] HandleGet Exception StackTrace: {1}", Key.ToLower(), ex.StackTrace); - if (ex.InnerException != null) Debug.Console(Verbose, "[{0}] HandleGet Exception InnerException: {1}", Key.ToLower(), ex.InnerException); - - context.Response.StatusCode = 500; - context.Response.StatusDescription = "Internal Server Error"; - 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(js, false); + context.Response.End(); } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs index d83660f7..f2630063 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -1,19 +1,12 @@ -using System; -using System.Linq; +using System.Linq; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class GetTypesRequestHandler : WebApiBaseRequestHandler { - private const string Key = "GetTypesRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -52,47 +45,25 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented); - Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson); - - var types = DeviceFactory.GetDeviceFactoryDictionary(string.Empty).Select(type => new + var deviceFactory = DeviceFactory.GetDeviceFactoryDictionary(null); + if (deviceFactory == null) { - Type = type.Key, - Description = type.Value.Description, - CType = type.Value.CType == null ? "---" : type.Value.CType.ToString() - }).Cast().ToList(); - - if (types == null) - { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; context.Response.End(); return; } - try - { - var js = JsonConvert.SerializeObject(types, Formatting.Indented); - //Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js); + 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(); - } - catch (Exception ex) - { - Debug.Console(Info, "[{0}] HandleGet Exception Message: {1}", Key.ToLower(), ex.Message); - Debug.Console(Verbose, "[{0}] HandleGet Exception StackTrace: {1}", Key.ToLower(), ex.StackTrace); - if (ex.InnerException != null) Debug.Console(Verbose, "[{0}] HandleGet Exception InnerException: {1}", Key.ToLower(), ex.InnerException); - - context.Response.StatusCode = 500; - context.Response.StatusDescription = "Internal Server Error"; - 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(js, false); + context.Response.End(); } /// diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index 0874db11..3625fcdd 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -2,18 +2,12 @@ using System.Text; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; -using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class SetDeviceStreamDebugRequestHandler : WebApiBaseRequestHandler { - private const string Key = "SetDeviceStreamDebugRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// @@ -86,13 +80,19 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - if (context.Request.ContentLength < 0) return; + if (context.Request.ContentLength < 0) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } var bytes = new Byte[context.Request.ContentLength]; context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); - Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data); - + var o = new { DeviceKey = "", diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs index d3cbbe99..4dded8b5 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -7,11 +7,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class ShowConfigRequestHandler : WebApiBaseRequestHandler { - private const string Key = "ShowConfigRequestHandler"; - private const uint Trace = 0; - private const uint Info = 1; - private const uint Verbose = 2; - /// /// Handles CONNECT method requests /// From e1d7374f1eb1184b8feca405cd0eae23014db098 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 13:22:12 -0600 Subject: [PATCH 22/26] fix: resolved issues with setDeviceStreamDebug; refactor: added static method GetRequestBody --- .../Web/EssentialsWebApiHelpers.cs | 14 ++- .../RequestHandlers/AppDebugRequestHandler.cs | 12 +- .../RequestHandlers/DevJsonRequestHandler.cs | 14 ++- .../RequestHandlers/DevPropsRequestHandler.cs | 12 +- .../GetFeedbacksForDeviceRequestHandler.cs | 7 +- .../SetDeviceStreamDebugRequestHandler.cs | 105 ++++++++++++++---- 6 files changed, 129 insertions(+), 35 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs index 37a749f9..4830edb4 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssentialsWebApiHelpers.cs @@ -1,11 +1,23 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using System.Text; +using Crestron.SimplSharp.WebScripting; using PepperDash.Core; namespace PepperDash.Essentials.Core.Web { public class EssentialsWebApiHelpers { + public static string GetRequestBody(HttpCwsRequest request) + { + var bytes = new Byte[request.ContentLength]; + + request.InputStream.Read(bytes, 0, request.ContentLength); + + return Encoding.UTF8.GetString(bytes, 0, bytes.Length); + } + public static object MapToAssemblyObject(LoadedAssembly assembly) { return new diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs index 4d6ff236..f80f9f7f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -95,9 +95,15 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var bytes = new Byte[context.Request.ContentLength]; - context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); - var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); + var data = EssentialsWebApiHelpers.GetRequestBody(context.Request); + if (string.IsNullOrEmpty(data)) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } var appDebug = new AppDebug(); var requestBody = JsonConvert.DeserializeAnonymousType(data, appDebug); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs index 7806095e..6080465b 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevJsonRequestHandler.cs @@ -88,12 +88,16 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var bytes = new Byte[context.Request.ContentLength]; - context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); - var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); - - //Debug.Console(0, "Request data:\n{0}", data); + var data = EssentialsWebApiHelpers.GetRequestBody(context.Request); + if (string.IsNullOrEmpty(data)) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + return; + } + try { DeviceJsonApi.DoDeviceActionWithJson(data); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs index 4ff70aad..b7dcc511 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -89,9 +89,15 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var bytes = new Byte[context.Request.ContentLength]; - context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); - var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); + var data = EssentialsWebApiHelpers.GetRequestBody(context.Request); + if (string.IsNullOrEmpty(data)) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } var o = new DeviceActionWrapper(); var body = JsonConvert.DeserializeAnonymousType(data, o); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs index 7e5c7be2..2f892f2b 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/GetFeedbacksForDeviceRequestHandler.cs @@ -93,19 +93,20 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers Value = feedback.StringValue ?? string.Empty }; - var respnse = new + var responseObj = new { BoolValues = boolFeedback, IntValues = intFeedback, SerialValues = stringFeedback }; - var final = JsonConvert.SerializeObject(respnse, Formatting.Indented); + 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(final, false); + context.Response.Write(js, false); context.Response.End(); } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs index 3625fcdd..bb7cc12f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/RequestHandlers/SetDeviceStreamDebugRequestHandler.cs @@ -1,7 +1,7 @@ using System; -using System.Text; using Crestron.SimplSharp.WebScripting; using Newtonsoft.Json; +using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers @@ -89,24 +89,28 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - var bytes = new Byte[context.Request.ContentLength]; - context.Request.InputStream.Read(bytes, 0, context.Request.ContentLength); - var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length); - - var o = new + var data = EssentialsWebApiHelpers.GetRequestBody(context.Request); + if (data == null) { - DeviceKey = "", - Type = "", - Timeout = 15 - }; + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Internal Server Error"; + context.Response.End(); - var body = JsonConvert.DeserializeAnonymousType(data, o); + return; + } - if (string.IsNullOrEmpty(body.DeviceKey) || string.IsNullOrEmpty(body.Type) - || !body.Type.ToLower().Contains("off") - || !body.Type.ToLower().Contains("tx") - || !body.Type.ToLower().Contains("rx") - || !body.Type.ToLower().Contains("both")) + 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"; @@ -115,11 +119,52 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - DeviceManager.SetDeviceStreamDebugging(string.Format("setdevicestreamdebug {0} {1} {2}", body.DeviceKey, body.Type, body.Timeout)); + var device = DeviceManager.GetDeviceForKey(body.DeviceKey) as IStreamDebugging; + if (device == null) + { + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; + context.Response.End(); - context.Response.StatusCode = 200; - context.Response.StatusDescription = "OK"; - context.Response.End(); + return; + } + + eStreamDebuggingSetting debugSetting; + try + { + debugSetting = (eStreamDebuggingSetting) Enum.Parse(typeof (eStreamDebuggingSetting), body.Setting, true); + } + catch (Exception ex) + { + 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) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Internal Server Error"; + context.Response.End(); + } } /// @@ -144,4 +189,24 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers context.Response.End(); } } + + + public class SetDeviceStreamDebugConfig + { + [JsonProperty("deviceKey", NullValueHandling = NullValueHandling.Include)] + public string DeviceKey { get; set; } + + [JsonProperty("setting", NullValueHandling = NullValueHandling.Include)] + public string Setting { get; set; } + + [JsonProperty("timeout")] + public int Timeout { get; set; } + + public SetDeviceStreamDebugConfig() + { + DeviceKey = null; + Setting = null; + Timeout = 15; + } + } } \ No newline at end of file From 34d3b705fa323999a8074ad54e734a010acebaf3 Mon Sep 17 00:00:00 2001 From: jdevito Date: Wed, 1 Feb 2023 15:30:21 -0600 Subject: [PATCH 23/26] fix: aded GetPaths method call when running on a server --- .../PepperDashEssentialsBase/Web/EssemtialsWebApi.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs index 2299cfbd..973b303b 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Web/EssemtialsWebApi.cs @@ -198,6 +198,8 @@ namespace PepperDash.Essentials.Core.Web Debug.Console(DebugTrace, Debug.ErrorLogLevel.Notice, "Starting Essentials Web API on Virtual Control Server"); _server.Start(); + + GetPaths(); } /// @@ -218,7 +220,7 @@ namespace PepperDash.Essentials.Core.Web CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0); var path = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server - ? string.Format("http(s)://{0}/virtualcontrol/rooms/{1}/cws{2}", hostname, InitialParametersClass.RoomId, BasePath) + ? string.Format("http(s)://{0}/VirtualControl/Rooms/{1}/cws{2}", hostname, InitialParametersClass.RoomId, BasePath) : string.Format("http(s)://{0}/cws{1}", currentIp, BasePath); Debug.Console(DebugTrace, this, "Server:{0}", path); From cbec2f211925a2da2ee487bc1afa7c8f24307f40 Mon Sep 17 00:00:00 2001 From: jdevito Date: Thu, 2 Feb 2023 12:31:11 -0600 Subject: [PATCH 24/26] fix: updates to resolve directory issues updateDirectoryXsig logic to resolve showing contacts in root when folders are in use (ZoomRooms). LinkVideoCodecDirectoryToApi to resolve analog value driving total number of contacts when folders are in use (ZoomRooms). ConvertZoomContactsToGeneric to reference roomFolder.FolderId and contactFolder.FolderId in foreach loops. --- .../VideoCodec/VideoCodecBase.cs | 71 +++++++++++-------- .../VideoCodec/ZoomRoom/ResponseObjects.cs | 12 +++- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/VideoCodecBase.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/VideoCodecBase.cs index 19c61b9f..c0048a68 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/VideoCodecBase.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/VideoCodecBase.cs @@ -1004,7 +1004,9 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec if (codec.DirectoryRoot != null) { - trilist.SetUshort(joinMap.DirectoryRowCount.JoinNumber, (ushort)codec.DirectoryRoot.CurrentDirectoryResults.Count); + var contactsCount = codec.DirectoryRoot.CurrentDirectoryResults.Where(c => c.ParentFolderId.Equals("root")).ToList().Count; + trilist.SetUshort(joinMap.DirectoryRowCount.JoinNumber, (ushort)contactsCount); + Debug.Console(2, this, ">>> contactsCount: {0}", contactsCount); var clearBytes = XSigHelpers.ClearOutputs(); @@ -1020,7 +1022,13 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec codec.DirectoryResultReturned += (sender, args) => { - trilist.SetUshort(joinMap.DirectoryRowCount.JoinNumber, (ushort)args.Directory.CurrentDirectoryResults.Count); + var isRoot = codec.CurrentDirectoryResultIsNotDirectoryRoot.BoolValue == false; + var argsCount = isRoot + ? args.Directory.CurrentDirectoryResults.Where(a => a.ParentFolderId.Equals("root")).ToList().Count + : args.Directory.CurrentDirectoryResults.Count; + + trilist.SetUshort(joinMap.DirectoryRowCount.JoinNumber, (ushort)argsCount); + Debug.Console(2, this, ">>> argsCount: {0}", argsCount); var clearBytes = XSigHelpers.ClearOutputs(); @@ -1184,46 +1192,47 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec return GetXSigString(tokenArray); } - private string UpdateDirectoryXSig(CodecDirectory directory, bool isRoot) - { - var xSigMaxIndex = 1023; - var tokenArray = new XSigToken[directory.CurrentDirectoryResults.Count > xSigMaxIndex - ? xSigMaxIndex - : directory.CurrentDirectoryResults.Count]; + private string UpdateDirectoryXSig(CodecDirectory directory, bool isRoot) + { + var xSigMaxIndex = 1023; + var tokenArray = new XSigToken[directory.CurrentDirectoryResults.Count > xSigMaxIndex + ? xSigMaxIndex + : directory.CurrentDirectoryResults.Count]; - Debug.Console(2, this, "IsRoot: {0}, Directory Count: {1}, TokenArray.Length: {2}", isRoot, - directory.CurrentDirectoryResults.Count, tokenArray.Length); + Debug.Console(2, this, "IsRoot: {0}, Directory Count: {1}, TokenArray.Length: {2}", isRoot, directory.CurrentDirectoryResults.Count, tokenArray.Length); - var contacts = directory.CurrentDirectoryResults.Count > xSigMaxIndex - ? directory.CurrentDirectoryResults.Take(xSigMaxIndex) - : directory.CurrentDirectoryResults; + var contacts = directory.CurrentDirectoryResults.Count > xSigMaxIndex + ? directory.CurrentDirectoryResults.Take(xSigMaxIndex) + : directory.CurrentDirectoryResults; - var counterIndex = 1; - foreach (var entry in contacts) - { - var arrayIndex = counterIndex - 1; - var entryIndex = counterIndex; + var contactsToDisplay = isRoot + ? contacts.Where(c => c.ParentFolderId == "root") + : contacts.Where(c => c.ParentFolderId != "root"); - Debug.Console(2, this, "Entry{2:0000} Name: {0}, Folder ID: {1}", entry.Name, entry.FolderId, entryIndex); + var counterIndex = 1; + foreach (var entry in contactsToDisplay) + { + var arrayIndex = counterIndex - 1; + var entryIndex = counterIndex; - if (entry is DirectoryFolder && entry.ParentFolderId == "root") - { - tokenArray[arrayIndex] = new XSigSerialToken(entryIndex, String.Format("[+] {0}", entry.Name)); + Debug.Console(2, this, "Entry{2:0000} Name: {0}, Folder ID: {1}, Type: {3}, ParentFolderId: {4}", + entry.Name, entry.FolderId, entryIndex, entry.GetType().GetCType().FullName, entry.ParentFolderId); - counterIndex++; - counterIndex++; + if (entry is DirectoryFolder) + { + tokenArray[arrayIndex] = new XSigSerialToken(entryIndex, String.Format("[+] {0}", entry.Name)); - continue; - } + counterIndex++; - tokenArray[arrayIndex] = new XSigSerialToken(entryIndex, entry.Name); + continue; + } - counterIndex++; - } - - return GetXSigString(tokenArray); + tokenArray[arrayIndex] = new XSigSerialToken(entryIndex, entry.Name); + counterIndex++; + } + return GetXSigString(tokenArray); } private void LinkVideoCodecCallControlsToApi(BasicTriList trilist, VideoCodecControllerJoinMap joinMap) diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ResponseObjects.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ResponseObjects.cs index 0075b657..79a5395d 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ResponseObjects.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ResponseObjects.cs @@ -303,11 +303,19 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom { var contact = new InvitableDirectoryContact { Name = c.ScreenName, ContactId = c.Jid }; - contact.ContactMethods.Add(new ContactMethod() { Number = c.Jid, Device = eContactMethodDevice.Video, CallType = eContactMethodCallType.Video, ContactMethodId = c.Jid }); + contact.ContactMethods.Add(new ContactMethod() + { + Number = c.Jid, + Device = eContactMethodDevice.Video, + CallType = eContactMethodCallType.Video, + ContactMethodId = c.Jid + }); if (folders.Count > 0) { - contact.ParentFolderId = c.IsZoomRoom ? "rooms" : "contacts"; + contact.ParentFolderId = c.IsZoomRoom + ? roomFolder.FolderId // "rooms" + : contactFolder.FolderId; // "contacts" } contacts.Add(contact); From e05186defdf01ae4f6ea417e62e3b75ce7398c86 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 7 Feb 2023 09:33:46 -0700 Subject: [PATCH 25/26] chore: update packages to use 1.1.5-beta-317 --- packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages.config b/packages.config index 87f5b8c1..ea9f8e18 100644 --- a/packages.config +++ b/packages.config @@ -1,3 +1,3 @@ - + \ No newline at end of file From 88f843250a3aa41c8cae17ed982f30151bb9cc2e Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Fri, 17 Feb 2023 00:47:50 -0600 Subject: [PATCH 26/26] feat: cleanup getjoinmap console return resolves: Issue #928 --- .../JoinMaps/JoinMapBase.cs | 80 +++++++++---------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs index 67a5740f..8f484121 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Data; using System.Globalization; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using Crestron.SimplSharp.Reflection; using Crestron.SimplSharp.CrestronIO; @@ -236,25 +234,45 @@ namespace PepperDash.Essentials.Core /// public void PrintJoinMapInfo() { - Debug.Console(0, "{0}:\n", GetType().Name); + var sb = JoinmapStringBuilder(); + + CrestronConsole.ConsoleCommandResponse(sb.ToString()); + } + + private StringBuilder JoinmapStringBuilder() + { + var sb = new StringBuilder(); // Get the joins of each type and print them - Debug.Console(0, "Digitals:"); - var digitals = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Digital Joins", digitals.Count); - PrintJoinList(GetSortedJoins(digitals)); + sb.AppendLine(String.Format("# {0}", GetType().Name)); + sb.AppendLine(); + sb.AppendLine("## Digitals"); + sb.AppendLine(); + // Get the joins of each type and print them + var digitals = + Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital) + .ToDictionary(j => j.Key, j => j.Value); + var digitalSb = AppendJoinList(GetSortedJoins(digitals)); + digitalSb.AppendLine("## Analogs"); + digitalSb.AppendLine(); - Debug.Console(0, "Analogs:"); - var analogs = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Analog Joins", analogs.Count); - PrintJoinList(GetSortedJoins(analogs)); + var analogs = + Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog) + .ToDictionary(j => j.Key, j => j.Value); + var analogSb = AppendJoinList(GetSortedJoins(analogs)); + analogSb.AppendLine("## Serials"); + analogSb.AppendLine(); - Debug.Console(0, "Serials:"); - var serials = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Serial Joins", serials.Count); - PrintJoinList(GetSortedJoins(serials)); + var serials = + Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial) + .ToDictionary(j => j.Key, j => j.Value); + var serialSb = AppendJoinList(GetSortedJoins(serials)); + sb.EnsureCapacity(sb.Length + digitalSb.Length + analogSb.Length + serialSb.Length); + sb.Append(digitalSb).Append(analogSb).Append(serialSb); + return sb; } + /// /// Prints the join information to console /// @@ -264,35 +282,9 @@ namespace PepperDash.Essentials.Core Debug.Console(0, "{0}:\n", pluginType); - var sb = new StringBuilder(); - sb.AppendLine(String.Format("# {0}", GetType().Name)); - sb.AppendLine(String.Format("Generated from '{0}' on bridge '{1}'", deviceKey, bridgeKey)); - sb.AppendLine(); - sb.AppendLine("## Digitals"); - // Get the joins of each type and print them - var digitals = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Digital Joins", digitals.Count); - var digitalSb = AppendJoinList(GetSortedJoins(digitals)); - digitalSb.AppendLine("## Analogs"); - digitalSb.AppendLine(); - Debug.Console(0, "Analogs:"); - var analogs = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Analog Joins", analogs.Count); - var analogSb = AppendJoinList(GetSortedJoins(analogs)); - analogSb.AppendLine("## Serials"); - analogSb.AppendLine(); - - Debug.Console(0, "Serials:"); - var serials = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); - Debug.Console(2, "Found {0} Serial Joins", serials.Count); - var serialSb = AppendJoinList(GetSortedJoins(serials)); - - sb.EnsureCapacity(sb.Length + digitalSb.Length + analogSb.Length + serialSb.Length); - sb.Append(digitalSb).Append(analogSb).Append(serialSb); - - WriteJoinmapMarkdown(sb, pluginType, bridgeKey, deviceKey); + WriteJoinmapMarkdown(JoinmapStringBuilder(), pluginType, bridgeKey, deviceKey); } @@ -313,7 +305,7 @@ namespace PepperDash.Essentials.Core /// /// /// - List> GetSortedJoins(Dictionary joins) + static List> GetSortedJoins(Dictionary joins) { var sortedJoins = joins.ToList(); @@ -322,7 +314,7 @@ namespace PepperDash.Essentials.Core return sortedJoins; } - void PrintJoinList(List> joins) + void PrintJoinList(IEnumerable> joins) { foreach (var join in joins) {