Plugin version dependency logic tested and working correctly.

This commit is contained in:
Neil Dorin
2020-01-31 14:33:14 -07:00
parent 59590e5463
commit f7aaf7a576
3 changed files with 141 additions and 18 deletions

View File

@@ -97,9 +97,13 @@ namespace PepperDash.Essentials
directoryPrefix = Crestron.SimplSharp.CrestronIO.Directory.GetApplicationRootDirectory();
if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Server) // Handles 3-series running Windows OS
var version = Crestron.SimplSharp.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Global.SetAssemblyVersion(string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build));
if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Server) // Handles 3-series running Windows CE OS
{
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials v{0} on 3-series Appliance", Global.GetAssemblyVersion());
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials v{0} on 3-series Appliance", Global.AssemblyVersion);
// Check if User/ProgramX exists
if (Directory.Exists(directoryPrefix + dirSeparator + "User"
@@ -127,7 +131,7 @@ namespace PepperDash.Essentials
}
else // Handles Linux OS (Virtual Control)
{
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials v{0} on Virtual Control Server", Global.GetAssemblyVersion());
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials v{0} on Virtual Control Server", Global.AssemblyVersion);
// Set path to User/
filePathPrefix = directoryPrefix + dirSeparator + "User" + dirSeparator;
@@ -246,11 +250,16 @@ namespace PepperDash.Essentials
var loadPlugin = methods.FirstOrDefault(m => m.Name.Equals("LoadPlugin"));
if (loadPlugin != null)
{
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static);
var minimumVersion = properties.FirstOrDefault(p => p.Name.Equals("MinimumEssentialsFrameworkVersion"));
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)
{
var minimumVersionString = minimumVersion.GetValue(null, null) as string;
Debug.Console(2, "MinimumEssentialsFrameworkVersion found");
var minimumVersionString = minimumVersion.GetValue(null) as string;
if (!string.IsNullOrEmpty(minimumVersionString))
{
@@ -259,15 +268,24 @@ namespace PepperDash.Essentials
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 not defined. Loading plugin, but your mileage may vary.");
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 type {0}", assy.Key, type.FullName);
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding plugin: {0}", assy.Key);
loadPlugin.Invoke(null, null);
}
}

View File

@@ -51,15 +51,31 @@ namespace PepperDash.Essentials.Core
FilePathPrefix = prefix;
}
static string _AssemblyVersion;
/// <summary>
/// Gets the Assembly Version of Essentials
/// </summary>
/// <returns>The Assembly Version at Runtime</returns>
public static string GetAssemblyVersion()
public static string AssemblyVersion
{
var version = Crestron.SimplSharp.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
get
{
return _AssemblyVersion;
}
private set
{
_AssemblyVersion = value;
}
}
return string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build);
/// <summary>
/// Sets the Assembly version to the version of the Essentials Library
/// </summary>
/// <param name="assemblyVersion"></param>
public static void SetAssemblyVersion(string assemblyVersion)
{
AssemblyVersion = assemblyVersion;
}
/// <summary>
@@ -69,11 +85,16 @@ namespace PepperDash.Essentials.Core
/// <returns>Returns true if the running version meets or exceeds the minimum specified version</returns>
public static bool IsRunningMinimumVersionOrHigher(string minimumVersion)
{
var runtimeVersion = Crestron.SimplSharp.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Debug.Console(2, "Comparing running version '{0}' to minimum version '{1}'", AssemblyVersion, minimumVersion);
Debug.Console(2, "Comparing running version '{0}' to minimum version '{1}'", GetAssemblyVersion(), minimumVersion);
var runtimeVersion = Regex.Match(AssemblyVersion, @"^(\d*).(\d*).(\d*)$");
if (runtimeVersion.Major == 0)
var runtimeVersionMajor = Int16.Parse(runtimeVersion.Groups[1].Value);
var runtimeVersionMinor = Int16.Parse(runtimeVersion.Groups[2].Value);
var runtimeVersionBuild = Int16.Parse(runtimeVersion.Groups[3].Value);
// Check for beta build version
if (runtimeVersionMajor == 0)
{
Debug.Console(2, "Running Beta Build. Bypassing Dependency Check.");
return true;
@@ -85,20 +106,21 @@ namespace PepperDash.Essentials.Core
{
Debug.Console(2, "minimumVersion String does not match format xx.yy.zz");
return false;
}
var minVersionMajor = Int16.Parse(minVersion.Groups[1].Value);
var minVersionMinor = Int16.Parse(minVersion.Groups[2].Value);
var minVersionBuild = Int16.Parse(minVersion.Groups[3].Value);
if (minVersionMajor < runtimeVersion.Major)
if (minVersionMajor > runtimeVersionMajor)
return false;
if (minVersionMinor < runtimeVersion.Minor)
if (minVersionMinor > runtimeVersionMinor)
return false;
if (minVersionBuild < runtimeVersion.Build)
if (minVersionBuild > runtimeVersionBuild)
return false;
return true;

View File

@@ -0,0 +1,83 @@
{
"$schema": "http://json-schema.org/draft-03/schema#",
"title": "DmChassisController Properties Config Schema",
"description": "",
"$ref": "EssentialsConfigSchema.json#definitions/Device",
"properties": {
"properties": {
"$ref": "#/propertiesConfig"
}
},
"propertiesConfig": {
"type": "object",
"additionalProperties": true,
"properties": {
"control": {
"required":true,
"type": "object",
"$ref": "../../ControlPropertiesConfigSchema.json#/ControlPropertiesConfig"
},
"volumeControls": {
"title": "Volume Controls",
"type": "object",
"additionalProperties": {
"type": "object",
"$ref": "#/dmAudioCardPropertiesConfig"
}
},
"inputSlots": {
"required":true,
"title": "Input Slots",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"outputSlots": {
"required":true,
"title": "Output Slots",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"inputNames": {
"title": "Input Names",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"outputNames": {
"title": "Output Names",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"noRouteText": {
"title": "No Route Text",
"type": "string"
},
"inputSlotSupportsHdcp2": {
"type": "object",
"additionalProperties": {
"type": "boolean"
}
}
}
},
"dmAudioCardPropertiesConfig": {
"type": "object",
"properties": {
"OutLevel": {
"title": "Output Level",
"type": "integer"
},
"isVolumeControlPoint": {
"title": "Volume Control Point?",
"type": "boolean"
}
}
}
}