From 1cad1976eedb719fe926318f911f317eac0b686d Mon Sep 17 00:00:00 2001 From: Jason Alborough Date: Wed, 16 Dec 2020 14:39:53 -0500 Subject: [PATCH 1/4] #499 Adds interfaces ILogStrings and ILogStringsWithLevel to PepperDash_Essentials_Core.Interfaces --- .../Interfaces/ILogStrings.cs | 17 +++++++++++++++++ .../Interfaces/ILogStringsWithLevel.cs | 18 ++++++++++++++++++ .../PepperDash_Essentials_Core.csproj | 2 ++ 3 files changed, 37 insertions(+) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs new file mode 100644 index 00000000..441292e8 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using PepperDash.Core.IKeyed; + +namespace PepperDash_Essentials_Core.Interfaces +{ + public interface ILogStrings : IKeyed + { + /// + /// Defines a class that is capable of logging a string + /// + void SendToLog(IKeyed device, string logMessage); + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs new file mode 100644 index 00000000..636128c9 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using PepperDash.Core; + +namespace PepperDash_Essentials_Core.Interfaces +{ + public interface ILogStringsWithLevel + { + /// + /// Defines a class that is capable of logging a string with an int level + /// + void SendToLog(IKeyed device, Debug.ErrorLogLevel level,string logMessage); + } + +} \ 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 6d4def73..39e68257 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -223,6 +223,8 @@ + + From fc91ba7c1e3a57cd9e01a9a9727f158632c1c4c8 Mon Sep 17 00:00:00 2001 From: Jason Alborough Date: Wed, 16 Dec 2020 15:00:30 -0500 Subject: [PATCH 2/4] Fixes Namespace and Implements IKeyed in both interfaces. --- .../PepperDashEssentialsBase/Interfaces/ILogStrings.cs | 4 ++-- .../Interfaces/ILogStringsWithLevel.cs | 4 ++-- .../Essentials_DM/PepperDash_Essentials_DM.csproj | 6 +++--- .../Essentials Devices Common.csproj | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs index 441292e8..92557319 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStrings.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; -using PepperDash.Core.IKeyed; +using PepperDash.Core; -namespace PepperDash_Essentials_Core.Interfaces +namespace PepperDash.Essentials.Core.Interfaces { public interface ILogStrings : IKeyed { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs index 636128c9..c43c4e6c 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Interfaces/ILogStringsWithLevel.cs @@ -5,9 +5,9 @@ using System.Text; using Crestron.SimplSharp; using PepperDash.Core; -namespace PepperDash_Essentials_Core.Interfaces +namespace PepperDash.Essentials.Core.Interfaces { - public interface ILogStringsWithLevel + public interface ILogStringsWithLevel : IKeyed { /// /// Defines a class that is capable of logging a string with an int level diff --git a/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj b/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj index 69045ea5..b1ea1b42 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj +++ b/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj @@ -65,12 +65,12 @@ False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll + ..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll False False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll + ..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll False @@ -79,7 +79,7 @@ False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpPro.exe + ..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpPro.exe False diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj index 54d37613..bfee822e 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj @@ -69,12 +69,12 @@ False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll + ..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll False False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll + ..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll False @@ -83,7 +83,7 @@ False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpPro.exe + ..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpPro.exe False From 0a34f48e0a3b45ffbb8dfc0f3b02f2413eab2800 Mon Sep 17 00:00:00 2001 From: Jason Alborough Date: Fri, 18 Dec 2020 17:07:20 -0500 Subject: [PATCH 3/4] Fixes for the static GetPropertyByName method in DeviceJsonApi...now returns a property object rather than a PropertyInfo object --- .../PepperDashEssentialsBase/Devices/DeviceJsonApi.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceJsonApi.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceJsonApi.cs index c7bc7c68..51d5882f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceJsonApi.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceJsonApi.cs @@ -83,13 +83,13 @@ namespace PepperDash.Essentials.Core /// public static object GetPropertyByName(string deviceObjectPath, string propertyName) { - var obj = FindObjectOnPath(deviceObjectPath); - if(obj == null) + var dev = FindObjectOnPath(deviceObjectPath); + if(dev == null) return "{ \"error\":\"No Device\"}"; + + object prop = dev.GetType().GetCType().GetProperty(propertyName).GetValue(dev, null); - CType t = obj.GetType(); - - var prop = t.GetProperty(propertyName); + // var prop = t.GetProperty(propertyName); if (prop != null) { return prop; From 08fe408dc1f1736dfb8d67c23b23de7e3e5c31b0 Mon Sep 17 00:00:00 2001 From: Maxim Batourine Date: Thu, 7 Jan 2021 19:31:24 -0500 Subject: [PATCH 4/4] Add safety check for casting device into interface (device as IRoutingInputsOutputs).InputPorts will throw Exception on accessing InputPorts property if device do not implement such interface. --- .../PepperDashEssentialsBase/Devices/DeviceManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs index 0e4efa10..55bc523a 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/DeviceManager.cs @@ -360,9 +360,9 @@ namespace PepperDash.Essentials.Core { var device = GetDeviceForKey(s); - if (device == null) return; - var inputPorts = (device as IRoutingInputsOutputs).InputPorts; - var outputPorts = (device as IRoutingInputsOutputs).OutputPorts; + if (device == null) return; + var inputPorts = ((device as IRoutingInputs) != null) ? (device as IRoutingInputs).InputPorts : null; + var outputPorts = ((device as IRoutingOutputs) != null) ? (device as IRoutingOutputs).OutputPorts : null; if (inputPorts != null) { Debug.Console(0, "Device {0} has {1} Input Ports:", s, inputPorts.Count);