Merge pull request #87 from PepperDash/feature/updated-IDeviceFactory-for-plugin-implementation

Feature/updated i device factory for plugin implementation
This commit is contained in:
Andrew Welker
2020-04-04 11:27:19 -06:00
committed by GitHub
16 changed files with 488 additions and 287 deletions

View File

@@ -1,21 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 10.00 Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008 # Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDashEssentials", ".\PepperDashEssentials\PepperDashEssentials.csproj", "{1BED5BA9-88C4-4365-9362-6F4B128071D3}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDashEssentials", "PepperDashEssentials\PepperDashEssentials.csproj", "{1BED5BA9-88C4-4365-9362-6F4B128071D3}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{892B761C-E479-44CE-BD74-243E9214AF13} = {892B761C-E479-44CE-BD74-243E9214AF13} {892B761C-E479-44CE-BD74-243E9214AF13} = {892B761C-E479-44CE-BD74-243E9214AF13}
{9199CE8A-0C9F-4952-8672-3EED798B284F} = {9199CE8A-0C9F-4952-8672-3EED798B284F} {9199CE8A-0C9F-4952-8672-3EED798B284F} = {9199CE8A-0C9F-4952-8672-3EED798B284F}
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDash_Essentials_Core", ".\essentials-framework\Essentials Core\PepperDashEssentialsBase\PepperDash_Essentials_Core.csproj", "{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDash_Essentials_Core", "essentials-framework\Essentials Core\PepperDashEssentialsBase\PepperDash_Essentials_Core.csproj", "{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials Devices Common", ".\essentials-framework\Essentials Devices Common\Essentials Devices Common\Essentials Devices Common.csproj", "{892B761C-E479-44CE-BD74-243E9214AF13}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials Devices Common", "essentials-framework\Essentials Devices Common\Essentials Devices Common\Essentials Devices Common.csproj", "{892B761C-E479-44CE-BD74-243E9214AF13}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials_DM", ".\essentials-framework\Essentials DM\Essentials_DM\Essentials_DM.csproj", "{9199CE8A-0C9F-4952-8672-3EED798B284F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDash_Essentials_DM", "essentials-framework\Essentials DM\Essentials_DM\PepperDash_Essentials_DM.csproj", "{9199CE8A-0C9F-4952-8672-3EED798B284F}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} = {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}
EndProjectSection EndProjectSection

View File

@@ -20,6 +20,46 @@ using PepperDash.Essentials.DM;
namespace PepperDash.Essentials.Bridges namespace PepperDash.Essentials.Bridges
{ {
/// <summary>
/// Helper methods for bridges
/// </summary>
public static class BridgeHelper
{
public static void PrintJoinMap(string command)
{
string bridgeKey = "";
string deviceKey = "";
var targets = command.Split(' ');
bridgeKey = targets[0].Trim();
var bridge = DeviceManager.GetDeviceForKey(bridgeKey) as EiscApi;
if (bridge == null)
{
Debug.Console(0, "Unable to find bridge with key: '{0}'", bridgeKey);
return;
}
if (targets.Length > 1)
{
deviceKey = targets[1].Trim();
if (!string.IsNullOrEmpty(deviceKey))
{
bridge.PrintJoinMapForDevice(deviceKey);
return;
}
}
else
{
bridge.PrintJoinMaps();
}
}
}
/// <summary> /// <summary>
/// Base class for all bridge class variants /// Base class for all bridge class variants
/// </summary> /// </summary>
@@ -61,6 +101,8 @@ namespace PepperDash.Essentials.Bridges
public EiscApi(DeviceConfig dc) : public EiscApi(DeviceConfig dc) :
base(dc.Key) base(dc.Key)
{ {
JoinMaps = new Dictionary<string, JoinMapBaseAdvanced>();
PropertiesConfig = JsonConvert.DeserializeObject<EiscApiPropertiesConfig>(dc.Properties.ToString()); PropertiesConfig = JsonConvert.DeserializeObject<EiscApiPropertiesConfig>(dc.Properties.ToString());
Eisc = new ThreeSeriesTcpIpEthernetIntersystemCommunications(PropertiesConfig.Control.IpIdInt, PropertiesConfig.Control.TcpSshProperties.Address, Global.ControlSystem); Eisc = new ThreeSeriesTcpIpEthernetIntersystemCommunications(PropertiesConfig.Control.IpIdInt, PropertiesConfig.Control.TcpSshProperties.Address, Global.ControlSystem);
@@ -79,11 +121,19 @@ namespace PepperDash.Essentials.Bridges
if (device != null) if (device != null)
{ {
Debug.Console(1, this, "Linking Device: '{0}'", device.Key);
if (device is IBridge) // Check for this first to allow bridges in plugins to override existing bridges that apply to the same type. if (device is IBridge) // Check for this first to allow bridges in plugins to override existing bridges that apply to the same type.
{ {
(device as IBridge).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); (device as IBridge).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
continue; continue;
} }
else if (device is IBridgeAdvanced)
{
Debug.Console(2, this, "'{0}' is IBridgeAdvanced", device.Key);
(device as IBridgeAdvanced).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this);
}
else if (device is PepperDash.Essentials.Core.Monitoring.SystemMonitorController) else if (device is PepperDash.Essentials.Core.Monitoring.SystemMonitorController)
{ {
(device as PepperDash.Essentials.Core.Monitoring.SystemMonitorController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); (device as PepperDash.Essentials.Core.Monitoring.SystemMonitorController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
@@ -99,16 +149,18 @@ namespace PepperDash.Essentials.Bridges
(device as CameraBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this); (device as CameraBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this);
continue; continue;
} }
else if (device is PepperDash.Essentials.Core.DisplayBase) else if (device is PepperDash.Essentials.Core.DisplayBase)
{ {
(device as DisplayBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); (device as DisplayBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
continue; continue;
} }
else if (device is DmChassisController) { else if (device is DmChassisController)
{
(device as DmChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); (device as DmChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
continue; continue;
} }
else if (device is DmBladeChassisController) { else if (device is DmBladeChassisController)
{
(device as DmBladeChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); (device as DmBladeChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
continue; continue;
} }
@@ -206,6 +258,38 @@ namespace PepperDash.Essentials.Bridges
} }
} }
/// <summary>
/// Prints all the join maps on this bridge
/// </summary>
public void PrintJoinMaps()
{
Debug.Console(0, this, "Join Maps for EISC IPID: {0}", Eisc.ID.ToString("X"));
foreach (var joinMap in JoinMaps)
{
Debug.Console(0, "Join map for device '{0}':", joinMap.Key);
joinMap.Value.PrintJoinMapInfo();
}
}
/// <summary>
/// Prints the join map for a device by key
/// </summary>
/// <param name="deviceKey"></param>
public void PrintJoinMapForDevice(string deviceKey)
{
var joinMap = JoinMaps[deviceKey];
if (joinMap == null)
{
Debug.Console(0, this, "Unable to find joinMap for device with key: '{0}'", deviceKey);
return;
}
Debug.Console(0, "Join map for device '{0}' on EISC '{1}':", deviceKey, this.Key);
joinMap.PrintJoinMapInfo();
}
/// <summary> /// <summary>
/// Used for debugging to trigger an action based on a join number and type /// Used for debugging to trigger an action based on a join number and type
/// </summary> /// </summary>

View File

@@ -7,8 +7,20 @@ using Crestron.SimplSharpPro.DeviceSupport;
namespace PepperDash.Essentials.Bridges namespace PepperDash.Essentials.Bridges
{ {
/// <summary>
/// Defines a device that uses the legacy JoinMapBase for its join map
/// </summary>
[Obsolete("IBridgeAdvanced should be used going forward with JoinMapBaseAdvanced")]
public interface IBridge public interface IBridge
{ {
void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey); void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey);
} }
/// <summary>
/// Defines a device that uses JoinMapBaseAdvanced for its join map
/// </summary>
public interface IBridgeAdvanced
{
void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApi bridge);
}
} }

View File

@@ -49,7 +49,10 @@ namespace PepperDash.Essentials
CrestronConsole.AddNewConsoleCommand(PluginLoader.ReportAssemblyVersions, "reportversions", "Reports the versions of the loaded assemblies", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(PluginLoader.ReportAssemblyVersions, "reportversions", "Reports the versions of the loaded assemblies", ConsoleAccessLevelEnum.AccessOperator);
// CrestronConsole.AddNewConsoleCommand(S => { ConfigWriter.WriteConfigFile(null); }, "writeconfig", "writes the current config to a file", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(PepperDash.Essentials.Core.DeviceFactory.GetDeviceFactoryTypes, "gettypes", "Gets the device types that can be built. Accepts a filter string.", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(PepperDash.Essentials.Bridges.BridgeHelper.PrintJoinMap, "getjoinmap", "map(s) for bridge or device on bridge [brKey [devKey]]", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.AddNewConsoleCommand(s =>
{ {
Debug.Console(0, Debug.ErrorLogLevel.Notice, "CONSOLE MESSAGE: {0}", s); Debug.Console(0, Debug.ErrorLogLevel.Notice, "CONSOLE MESSAGE: {0}", s);
@@ -287,12 +290,13 @@ namespace PepperDash.Essentials
/// </summary> /// </summary>
public void LoadDevices() public void LoadDevices()
{ {
// Instantiate the Device Factories
new CoreDeviceFactory();
// Build the processor wrapper class // Build the processor wrapper class
DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor")); DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor"));
// Add global System Monitor device // Add global System Monitor device
DeviceManager.AddDevice(new PepperDash.Essentials.Core.Monitoring.SystemMonitorController("systemMonitor")); DeviceManager.AddDevice(new PepperDash.Essentials.Core.Monitoring.SystemMonitorController("systemMonitor"));

View File

@@ -7,7 +7,7 @@
<ProjectGuid>{1BED5BA9-88C4-4365-9362-6F4B128071D3}</ProjectGuid> <ProjectGuid>{1BED5BA9-88C4-4365-9362-6F4B128071D3}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PepperDash.Essentials</RootNamespace> <RootNamespace>PepperDashEssentials</RootNamespace>
<AssemblyName>PepperDashEssentials</AssemblyName> <AssemblyName>PepperDashEssentials</AssemblyName>
<ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92230};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92230};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PlatformFamilyName>WindowsCE</PlatformFamilyName> <PlatformFamilyName>WindowsCE</PlatformFamilyName>

View File

@@ -13,14 +13,11 @@ using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>
/// Serves as a generic wrapper class for all styles of IBasicCommuncation ports /// Serves as a generic wrapper class for all styles of IBasicCommuncation ports
/// </summary> /// </summary>
public class GenericComm : ReconfigurableDevice public class GenericComm : ReconfigurableDevice
{ {
EssentialsControlPropertiesConfig PropertiesConfig; EssentialsControlPropertiesConfig PropertiesConfig;
public IBasicCommunication CommPort { get; private set; } public IBasicCommunication CommPort { get; private set; }
@@ -32,7 +29,6 @@ namespace PepperDash.Essentials.Core
CommPort = CommFactory.CreateCommForDevice(config); CommPort = CommFactory.CreateCommForDevice(config);
} }
public static IKeyed BuildDevice(DeviceConfig dc) public static IKeyed BuildDevice(DeviceConfig dc)
@@ -61,22 +57,19 @@ namespace PepperDash.Essentials.Core
ConfigWriter.UpdateDeviceConfig(config); ConfigWriter.UpdateDeviceConfig(config);
} }
}
public class Factory : Essentials.Core.Factory public class GenericCommFactory : Essentials.Core.EssentialsDeviceFactory<GenericComm>
{
public GenericCommFactory()
{ {
#region IDeviceFactory Members TypeNames = new List<string>() { "genericComm" };
List<string> TypeNames = new List<string>() { "genericComm" };
#endregion
public override IKeyed BuildDevice(DeviceConfig dc)
{
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc);
}
} }
}
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc);
}
}
} }

View File

@@ -19,15 +19,30 @@ namespace PepperDash.Essentials.Core
{ {
} }
protected EssentialsDevice(string key, string name)
: base(key, name)
{
}
} }
public abstract class Factory : IDeviceFactory /// <summary>
/// Devices the basic needs for a Device Factory
/// </summary>
public abstract class EssentialsDeviceFactory<T> : IDeviceFactory where T:EssentialsDevice
{ {
#region IDeviceFactory Members #region IDeviceFactory Members
/// <summary>
/// A list of strings that can be used in the type property of a DeviceConfig object to build an instance of this device
/// </summary>
public List<string> TypeNames { get; protected set; } public List<string> TypeNames { get; protected set; }
public virtual void LoadTypeFactories() /// <summary>
/// Loads an item to the DeviceFactory.FactoryMethods dictionary for each entry in the TypeNames list
/// </summary>
public void LoadTypeFactories()
{ {
foreach (var typeName in TypeNames) foreach (var typeName in TypeNames)
{ {
@@ -35,13 +50,24 @@ namespace PepperDash.Essentials.Core
} }
} }
/// <summary>
/// The method that will build the device
/// </summary>
/// <param name="dc">The device config</param>
/// <returns>An instance of the device</returns>
public abstract EssentialsDevice BuildDevice(DeviceConfig dc);
#endregion #endregion
}
public abstract IKeyed BuildDevice(DeviceConfig dc); /// <summary>
/// Devices the basic needs for a Device Factory
protected Factory() /// </summary>
{ public abstract class EssentialsPluginDeviceFactory<T> : EssentialsDeviceFactory<T>, IPluginDeviceFactory where T : EssentialsDevice
TypeNames = new List<string>(); {
} /// <summary>
/// Specifies the minimum version of Essentials required for a plugin to run. Must use the format Major.Minor.Build (ex. "1.4.33")
/// </summary>
public string MinimumEssentialsFrameworkVersion { get; protected set; }
} }
} }

View File

@@ -48,7 +48,6 @@ namespace PepperDash.Essentials.Core
var typeName = dc.Type.ToLower(); var typeName = dc.Type.ToLower();
// Check for types that have been added by plugin dlls. // Check for types that have been added by plugin dlls.
if (FactoryMethods.ContainsKey(typeName)) if (FactoryMethods.ContainsKey(typeName))
{ {
@@ -57,11 +56,11 @@ namespace PepperDash.Essentials.Core
} }
// Check "core" types // Check "core" types
if (typeName == "genericcomm") //if (typeName == "genericcomm")
{ //{
Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); // Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc); // return new GenericComm(dc);
} //}
if (typeName == "ceniodigin104") if (typeName == "ceniodigin104")
{ {
var control = CommFactory.GetControlPropertiesConfig(dc); var control = CommFactory.GetControlPropertiesConfig(dc);
@@ -86,6 +85,31 @@ namespace PepperDash.Essentials.Core
return null; return null;
} }
/// <summary>
/// Prints the type names fromt the FactoryMethods collection.
/// </summary>
/// <param name="command"></param>
public static void GetDeviceFactoryTypes(string filter)
{
List<string> typeNames = new List<string>();
if (!string.IsNullOrEmpty(filter))
{
typeNames = FactoryMethods.Keys.Where(k => k.Contains(filter)).ToList();
}
else
{
typeNames = FactoryMethods.Keys.ToList();
}
Debug.Console(0, "Device Types:");
foreach (var type in typeNames)
{
Debug.Console(0, "type: '{0}'", type);
}
}
} }
@@ -96,7 +120,7 @@ namespace PepperDash.Essentials.Core
{ {
public CoreDeviceFactory() public CoreDeviceFactory()
{ {
var genComm = new GenericComm.Factory() as IDeviceFactory; var genComm = new GenericCommFactory() as IDeviceFactory;
genComm.LoadTypeFactories(); genComm.LoadTypeFactories();
} }
} }

View File

@@ -4,6 +4,9 @@ using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>

View File

@@ -48,16 +48,17 @@ namespace PepperDash.Essentials.Core
if (joinMapSerialzed != null) if (joinMapSerialzed != null)
{ {
var joinMap = JsonConvert.DeserializeObject<Dictionary<string, JoinData>>(joinMapSerialzed); var joinMapData = JsonConvert.DeserializeObject<Dictionary<string, JoinData>>(joinMapSerialzed);
if (joinMap != null) if (joinMapData != null)
return joinMap; return joinMapData;
else else
return null; return null;
} }
else else
return null; return null;
} }
} }
/// <summary> /// <summary>
@@ -87,14 +88,17 @@ namespace PepperDash.Essentials.Core
// Get the joins of each type and print them // Get the joins of each type and print them
Debug.Console(0, "Digitals:"); Debug.Console(0, "Digitals:");
var digitals = Joins.Where(j => (j.Value.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); var digitals = Joins.Where(j => (j.Value.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Digital Joins", digitals.Count);
PrintJoinList(GetSortedJoins(digitals)); PrintJoinList(GetSortedJoins(digitals));
Debug.Console(0, "Analogs:"); Debug.Console(0, "Analogs:");
var analogs = Joins.Where(j => (j.Value.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); var analogs = Joins.Where(j => (j.Value.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Analog Joins", analogs.Count);
PrintJoinList(GetSortedJoins(analogs)); PrintJoinList(GetSortedJoins(analogs));
Debug.Console(0, "Serials:"); Debug.Console(0, "Serials:");
var serials = Joins.Where(j => (j.Value.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); var serials = Joins.Where(j => (j.Value.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value);
Debug.Console(2, "Found {0} Serial Joins", serials.Count);
PrintJoinList(GetSortedJoins(serials)); PrintJoinList(GetSortedJoins(serials));
} }
@@ -165,24 +169,43 @@ namespace PepperDash.Essentials.Core
/// <summary> /// <summary>
/// The collection of joins and associated metadata /// The collection of joins and associated metadata
/// </summary> /// </summary>
public Dictionary<string, JoinDataComplete> Joins = new Dictionary<string, JoinDataComplete>(); public Dictionary<string, JoinDataComplete> Joins { get; private set; }
protected JoinMapBaseAdvanced(uint joinStart) protected JoinMapBaseAdvanced(uint joinStart)
{ {
Joins = new Dictionary<string, JoinDataComplete>();
_joinOffset = joinStart - 1; _joinOffset = joinStart - 1;
// Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset // Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset
Joins = GetType() Joins = this.GetType()
.GetCType() .GetCType()
.GetProperties() .GetFields(BindingFlags.Public | BindingFlags.Instance)
.Where(prop => prop.IsDefined(typeof(JoinNameAttribute), false)) .Where(field => field.IsDefined(typeof(JoinNameAttribute), false))
.Select(prop => (JoinDataComplete)prop.GetValue(this, null)) .Select(prop => (JoinDataComplete)prop.GetValue(this))
.ToDictionary(join => join.GetNameAttribute(), join => .ToDictionary(join => join.GetNameAttribute(), join =>
{ {
join.SetJoinOffset(_joinOffset); join.SetJoinOffset(_joinOffset);
return join; return join;
}); });
//var type = this.GetType();
//var cType = type.GetCType();
//var fields = cType.GetFields(BindingFlags.Public | BindingFlags.Instance);
//foreach (var field in fields)
//{
// if (field.IsDefined(typeof(JoinNameAttribute), true))
// {
// var value = field.GetValue(this) as JoinDataComplete;
// if (value != null)
// {
// value.SetJoinOffset(_joinOffset);
// Joins.Add(value.GetNameAttribute(), value);
// }
// }
//}
PrintJoinMapInfo(); PrintJoinMapInfo();
} }
@@ -196,14 +219,17 @@ namespace PepperDash.Essentials.Core
// Get the joins of each type and print them // Get the joins of each type and print them
Debug.Console(0, "Digitals:"); Debug.Console(0, "Digitals:");
var digitals = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value); 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)); PrintJoinList(GetSortedJoins(digitals));
Debug.Console(0, "Analogs:"); Debug.Console(0, "Analogs:");
var analogs = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value); 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)); PrintJoinList(GetSortedJoins(analogs));
Debug.Console(0, "Serials:"); Debug.Console(0, "Serials:");
var serials = Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value); 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)); PrintJoinList(GetSortedJoins(serials));
} }
@@ -255,6 +281,8 @@ namespace PepperDash.Essentials.Core
Debug.Console(2, "No mathcing key found in join map for: '{0}'", customJoinData.Key); Debug.Console(2, "No mathcing key found in join map for: '{0}'", customJoinData.Key);
} }
} }
PrintJoinMapInfo();
} }
///// <summary> ///// <summary>

View File

@@ -7,7 +7,7 @@
<ProjectGuid>{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}</ProjectGuid> <ProjectGuid>{A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PepperDash.Essentials.Core</RootNamespace> <RootNamespace>PepperDash_Essentials_Core</RootNamespace>
<AssemblyName>PepperDash_Essentials_Core</AssemblyName> <AssemblyName>PepperDash_Essentials_Core</AssemblyName>
<ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92300};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92300};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PlatformFamilyName>WindowsCE</PlatformFamilyName> <PlatformFamilyName>WindowsCE</PlatformFamilyName>
@@ -161,7 +161,6 @@
<Compile Include="Plugins\PluginLoader.cs" /> <Compile Include="Plugins\PluginLoader.cs" />
<Compile Include="Presets\PresetBase.cs" /> <Compile Include="Presets\PresetBase.cs" />
<Compile Include="Plugins\IPluginDeviceFactory.cs" /> <Compile Include="Plugins\IPluginDeviceFactory.cs" />
<Compile Include="Plugins\PluginEntrypointAttribute.cs" />
<Compile Include="Ramps and Increments\ActionIncrementer.cs" /> <Compile Include="Ramps and Increments\ActionIncrementer.cs" />
<Compile Include="Config\Comm and IR\CommFactory.cs" /> <Compile Include="Config\Comm and IR\CommFactory.cs" />
<Compile Include="Config\Comm and IR\CommunicationExtras.cs" /> <Compile Include="Config\Comm and IR\CommunicationExtras.cs" />

View File

@@ -1,19 +0,0 @@
using System;
namespace PepperDash.Essentials.Core.Plugins
{
[AttributeUsage(AttributeTargets.Class)]
public sealed class PluginEntryPointAttribute : Attribute
{
private readonly string _uniqueKey;
public string UniqueKey {
get { return _uniqueKey; }
}
public PluginEntryPointAttribute(string key)
{
_uniqueKey = key;
}
}
}

View File

@@ -69,6 +69,11 @@ namespace PepperDash.Essentials
{ {
version = Global.AssemblyVersion; version = Global.AssemblyVersion;
assembly = Assembly.GetExecutingAssembly(); assembly = Assembly.GetExecutingAssembly();
break;
}
case ("PepperDashEssentialsBase.dll"):
{
break; break;
} }
case ("PepperDash_Core.dll"): case ("PepperDash_Core.dll"):
@@ -338,47 +343,19 @@ namespace PepperDash.Essentials
{ {
try try
{ {
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static); if (typeof(IPluginDeviceFactory).IsAssignableFrom(type))
var loadPlugin = methods.FirstOrDefault(m => m.Name.Equals("LoadPlugin"));
if (loadPlugin != null)
{ {
Debug.Console(2, "LoadPlugin method found in {0}", type.Name); var plugin = (IPluginDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
LoadCustomPlugin(plugin, loadedAssembly);
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static); }
else
var minimumVersion = fields.FirstOrDefault(p => p.Name.Equals("MinimumEssentialsFrameworkVersion")); {
if (minimumVersion != null) var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
var loadPlugin = methods.FirstOrDefault(m => m.Name.Equals("LoadPlugin"));
if (loadPlugin != null)
{ {
Debug.Console(2, "MinimumEssentialsFrameworkVersion found"); LoadCustomLegacyPlugin(type, loadPlugin, loadedAssembly);
var minimumVersionString = minimumVersion.GetValue(null) as string;
if (!string.IsNullOrEmpty(minimumVersionString))
{
var passed = Global.IsRunningMinimumVersionOrHigher(minimumVersionString);
if (!passed)
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "Plugin indicates minimum Essentials version {0}. Dependency check failed. Skipping Plugin", minimumVersionString);
continue;
}
else
{
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Passed plugin passed dependency check (required version {0})", minimumVersionString);
}
}
else
{
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion found but not set. Loading plugin, but your mileage may vary.");
}
} }
else
{
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion not found. Loading plugin, but your mileage may vary.");
}
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding plugin: {0}", loadedAssembly.Name);
loadPlugin.Invoke(null, null);
} }
} }
catch (Exception e) catch (Exception e)
@@ -400,6 +377,75 @@ namespace PepperDash.Essentials
Debug.Console(0, "Done Loading Custom Plugin Types."); Debug.Console(0, "Done Loading Custom Plugin Types.");
} }
/// <summary>
/// Loads a
/// </summary>
/// <param name="plugin"></param>
static void LoadCustomPlugin(IPluginDeviceFactory plugin, LoadedAssembly loadedAssembly)
{
var passed = Global.IsRunningMinimumVersionOrHigher(plugin.MinimumEssentialsFrameworkVersion);
if (!passed)
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "Plugin indicates minimum Essentials version {0}. Dependency check failed. Skipping Plugin", plugin.MinimumEssentialsFrameworkVersion);
return;
}
else
{
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Passed plugin passed dependency check (required version {0})", plugin.MinimumEssentialsFrameworkVersion);
}
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading plugin: {0}", loadedAssembly.Name);
plugin.LoadTypeFactories();
}
/// <summary>
/// Loads a a custom plugin via the legacy method
/// </summary>
/// <param name="type"></param>
/// <param name="loadPlugin"></param>
static void LoadCustomLegacyPlugin(CType type, MethodInfo loadPlugin, LoadedAssembly loadedAssembly)
{
Debug.Console(2, "LoadPlugin method found in {0}", type.Name);
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);
var minimumVersion = fields.FirstOrDefault(p => p.Name.Equals("MinimumEssentialsFrameworkVersion"));
if (minimumVersion != null)
{
Debug.Console(2, "MinimumEssentialsFrameworkVersion found");
var minimumVersionString = minimumVersion.GetValue(null) as string;
if (!string.IsNullOrEmpty(minimumVersionString))
{
var passed = Global.IsRunningMinimumVersionOrHigher(minimumVersionString);
if (!passed)
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "Plugin indicates minimum Essentials version {0}. Dependency check failed. Skipping Plugin", minimumVersionString);
return;
}
else
{
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Passed plugin passed dependency check (required version {0})", minimumVersionString);
}
}
else
{
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion found but not set. Loading plugin, but your mileage may vary.");
}
}
else
{
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion not found. Loading plugin, but your mileage may vary.");
}
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading legacy plugin: {0}", loadedAssembly.Name);
loadPlugin.Invoke(null, null);
}
/// <summary> /// <summary>
/// Loads plugins /// Loads plugins
/// </summary> /// </summary>
@@ -415,15 +461,17 @@ namespace PepperDash.Essentials
// Deal with any .cplz files // Deal with any .cplz files
UnzipAndMoveCplzArchives(); UnzipAndMoveCplzArchives();
if(Directory.Exists(_loadedPluginsDirectoryPath)) { if (Directory.Exists(_loadedPluginsDirectoryPath))
// Load the assemblies from the loadedPlugins folder into the AppDomain {
LoadPluginAssemblies(); // Load the assemblies from the loadedPlugins folder into the AppDomain
LoadPluginAssemblies();
// Load the types from any custom plugin assemblies // Load the types from any custom plugin assemblies
LoadCustomPluginTypes(); LoadCustomPluginTypes();
} }
} }
} }
} }
/// <summary> /// <summary>

View File

@@ -28,7 +28,6 @@ namespace PepperDash.Essentials.Core.Touchpanels
_Touchpanel.ButtonStateChange += new Crestron.SimplSharpPro.DeviceSupport.ButtonEventHandler(_Touchpanel_ButtonStateChange); _Touchpanel.ButtonStateChange += new Crestron.SimplSharpPro.DeviceSupport.ButtonEventHandler(_Touchpanel_ButtonStateChange);
AddPostActivationAction(() => AddPostActivationAction(() =>
{ {
// Link up the button feedbacks to the specified BoolFeedbacks // Link up the button feedbacks to the specified BoolFeedbacks
@@ -40,7 +39,7 @@ namespace PepperDash.Essentials.Core.Touchpanels
{ {
var bKey = button.Key.ToLower(); var bKey = button.Key.ToLower();
var feedback = device.GetFeedbackProperty(feedbackConfig.BoolFeedbackName); var feedback = device.GetFeedbackProperty(feedbackConfig.FeedbackName);
var bFeedback = feedback as BoolFeedback; var bFeedback = feedback as BoolFeedback;
var iFeedback = feedback as IntFeedback; var iFeedback = feedback as IntFeedback;
@@ -72,7 +71,7 @@ namespace PepperDash.Essentials.Core.Touchpanels
} }
else else
{ {
Debug.Console(1, this, "Unable to get BoolFeedback with name: {0} from device: {1}", feedbackConfig.BoolFeedbackName, device.Key); Debug.Console(1, this, "Unable to get BoolFeedback with name: {0} from device: {1}", feedbackConfig.FeedbackName, device.Key);
} }
} }
else else
@@ -140,6 +139,6 @@ namespace PepperDash.Essentials.Core.Touchpanels
public class KeypadButtonFeedback public class KeypadButtonFeedback
{ {
public string DeviceKey { get; set; } public string DeviceKey { get; set; }
public string BoolFeedbackName { get; set; } public string FeedbackName { get; set; }
} }
} }

View File

@@ -7,7 +7,7 @@
<ProjectGuid>{9199CE8A-0C9F-4952-8672-3EED798B284F}</ProjectGuid> <ProjectGuid>{9199CE8A-0C9F-4952-8672-3EED798B284F}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PepperDash.Essentials.DM</RootNamespace> <RootNamespace>PepperDash_Essentials_DM</RootNamespace>
<AssemblyName>PepperDash_Essentials_DM</AssemblyName> <AssemblyName>PepperDash_Essentials_DM</AssemblyName>
<ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92300};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{0B4745B0-194B-4BB6-8E21-E9057CA92300};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PlatformFamilyName>WindowsCE</PlatformFamilyName> <PlatformFamilyName>WindowsCE</PlatformFamilyName>

View File

@@ -1,7 +1,7 @@
using System.Reflection; using System.Reflection;
using Crestron.SimplSharp.Reflection; using Crestron.SimplSharp.Reflection;
[assembly: System.Reflection.AssemblyTitle("Essentials_DM")] [assembly: System.Reflection.AssemblyTitle("PepperDash_Essentials_DM")]
[assembly: System.Reflection.AssemblyCompany("PepperDash Technology Corp")] [assembly: System.Reflection.AssemblyCompany("PepperDash Technology Corp")]
[assembly: System.Reflection.AssemblyProduct("PepperDashEssentials")] [assembly: System.Reflection.AssemblyProduct("PepperDashEssentials")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © PepperDash Technology Corp 2020")] [assembly: System.Reflection.AssemblyCopyright("Copyright © PepperDash Technology Corp 2020")]