Merged in feature/heath-shades (pull request #12)

esc-1103: Plugins - (heath shades)
This commit is contained in:
Heath Volmer
2019-05-22 15:33:24 +00:00
5 changed files with 97 additions and 22 deletions

View File

@@ -679,13 +679,14 @@ namespace PepperDash.Essentials
if(string.IsNullOrEmpty(message)) if(string.IsNullOrEmpty(message))
return; return;
if (!message.Contains("/system/heartbeat")) if (!message.Contains("/system/heartbeat"))
Debug.Console(1, this, "Message RX: {0}", message); {
else Debug.Console(1, this, "Message RX: {0}", message);
{ }
LastAckMessage = DateTime.Now; else
//Debug.Console(1, this, "RX message contains /system/heartbeat"); {
} LastAckMessage = DateTime.Now;
}
try try
{ {
@@ -702,6 +703,11 @@ namespace PepperDash.Essentials
{ {
HandleHeartBeat(messageObj["content"]); HandleHeartBeat(messageObj["content"]);
} }
else if (type == "raw")
{
var wrapper = messageObj["content"].ToObject<DeviceActionWrapper>();
DeviceJsonApi.DoDeviceAction(wrapper);
}
else if (type == "close") else if (type == "close")
{ {
Debug.Console(1, this, "Received close message from server."); Debug.Console(1, this, "Received close message from server.");

View File

@@ -417,7 +417,7 @@ namespace PepperDash.Essentials
if (rmVc != null) if (rmVc != null)
{ {
var vc = rmVc.CurrentVolumeControls as IBasicVolumeWithFeedback; var vc = rmVc.CurrentVolumeControls as IBasicVolumeWithFeedback;
if (rmVc != null) if (vc != null)
{ {
volumes.Master = new Volume("master", vc.VolumeLevelFeedback.UShortValue, vc.MuteFeedback.BoolValue, "Volume", true, ""); volumes.Master = new Volume("master", vc.VolumeLevelFeedback.UShortValue, vc.MuteFeedback.BoolValue, "Volume", true, "");
} }

View File

@@ -1,10 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.CrestronThread; using Crestron.SimplSharpPro.CrestronThread;
using Crestron.SimplSharpPro.Diagnostics; using Crestron.SimplSharpPro.Diagnostics;
using Crestron.SimplSharp.Reflection;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
@@ -21,6 +23,8 @@ namespace PepperDash.Essentials
{ {
HttpLogoServer LogoServer; HttpLogoServer LogoServer;
List<object> FactoryObjects = new List<object>();
public ControlSystem() public ControlSystem()
: base() : base()
{ {
@@ -137,15 +141,14 @@ namespace PepperDash.Essentials
{ {
try try
{ {
CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync",
ConsoleAccessLevelEnum.AccessOperator);
//PortalSync = new PepperDashPortalSyncClient();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials load from configuration"); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials load from configuration");
var filesReady = SetupFilesystem(); var filesReady = SetupFilesystem();
if (filesReady) if (filesReady)
{ {
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Checking for plugins");
LoadPlugins();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Folder structure verified. Loading config..."); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Folder structure verified. Loading config...");
if (!ConfigReader.LoadConfig2()) if (!ConfigReader.LoadConfig2())
return; return;
@@ -181,6 +184,51 @@ namespace PepperDash.Essentials
} }
/// <summary>
/// Initial simple implementation. Reads user/programN/plugins folder and
/// use
/// </summary>
void LoadPlugins()
{
var dir = Global.FilePathPrefix + "plugins";
if (Directory.Exists(dir))
{
// TODO Clear out or create localPlugins folder (maybe in program slot folder)
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Plugins directory found, checking for factory plugins");
var di = new DirectoryInfo(dir);
var files = di.GetFiles("*.dll");
foreach (FileInfo fi in files)
{
// TODO COPY plugin to loadedPlugins folder
// TODO LOAD that loadedPlugins dll file
var assy = Assembly.LoadFrom(fi.FullName);
var ver = assy.GetName().Version;
var verStr = string.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loaded plugin file '{0}', version {1}", fi.FullName, verStr);
// iteratate this assembly's classes, looking for "LoadPlugin()" methods
var types = assy.GetTypes();
foreach (var type in types)
{
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
var loadPlugin = methods.FirstOrDefault(m => m.Name.Equals("LoadPlugin"));
if (loadPlugin != null)
{
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding type {0}", fi.FullName, type.FullName);
loadPlugin.Invoke(null, null);
}
}
// plugin dll will be loaded. Any classes in plugin should have a static constructor
// that registers that class with the Core.DeviceFactory
}
}
}
/// <summary> /// <summary>
/// Verifies filesystem is set up. IR, SGD, and programX folders /// Verifies filesystem is set up. IR, SGD, and programX folders
/// </summary> /// </summary>
@@ -203,14 +251,21 @@ namespace PepperDash.Essentials
return configExists; return configExists;
} }
public void EnablePortalSync(string s) ///// <summary>
{ /////
if (s.ToLower() == "enable") ///// </summary>
{ ///// <param name="s"></param>
CrestronConsole.ConsoleCommandResponse("Portal Sync features enabled"); //public void EnablePortalSync(string s)
} //{
} // if (s.ToLower() == "enable")
// {
// CrestronConsole.ConsoleCommandResponse("Portal Sync features enabled");
// }
//}
/// <summary>
///
/// </summary>
public void TearDown() public void TearDown()
{ {
Debug.Console(0, "Tearing down existing system"); Debug.Console(0, "Tearing down existing system");
@@ -274,7 +329,7 @@ namespace PepperDash.Essentials
try try
{ {
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Creating device '{0}'", devConf.Key); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Creating device '{0}', type '{1}'", devConf.Key, devConf.Type);
// Skip this to prevent unnecessary warnings // Skip this to prevent unnecessary warnings
if (devConf.Key == "processor") if (devConf.Key == "processor")
{ {
@@ -303,6 +358,20 @@ namespace PepperDash.Essentials
newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf); newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf);
if (newDev == null) if (newDev == null)
newDev = PepperDash.Essentials.BridgeFactory.GetDevice(devConf); newDev = PepperDash.Essentials.BridgeFactory.GetDevice(devConf);
//if (newDev == null) // might want to consider the ability to override an essentials "type"
//{
// // iterate plugin factories
// foreach (var f in FactoryObjects)
// {
// var cresFactory = f as IGetCrestronDevice;
// if (cresFactory != null)
// {
// newDev = cresFactory.GetDevice(devConf, this);
// }
// }
//}
if (newDev != null) if (newDev != null)
DeviceManager.AddDevice(newDev); DeviceManager.AddDevice(newDev);
else else

View File

@@ -4,5 +4,5 @@
[assembly: AssemblyCompany("PepperDash Technology Corp")] [assembly: AssemblyCompany("PepperDash Technology Corp")]
[assembly: AssemblyProduct("PepperDashEssentials")] [assembly: AssemblyProduct("PepperDashEssentials")]
[assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2018")] [assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2018")]
[assembly: AssemblyVersion("1.3.2.*")] [assembly: AssemblyVersion("1.4.0.*")]