diff --git a/src/PepperDash.Essentials.Core/Config/Essentials/ConfigReader.cs b/src/PepperDash.Essentials.Core/Config/Essentials/ConfigReader.cs index 362ab9f0..e402341e 100644 --- a/src/PepperDash.Essentials.Core/Config/Essentials/ConfigReader.cs +++ b/src/PepperDash.Essentials.Core/Config/Essentials/ConfigReader.cs @@ -35,7 +35,7 @@ namespace PepperDash.Essentials.Core.Config; /// /// LoadConfig2 method /// - public static bool LoadConfig2() + public static bool LoadConfig() { Debug.LogMessage(LogEventLevel.Information, "Loading unmerged system/template portal configuration file."); try diff --git a/src/PepperDash.Essentials.Core/Config/ILoadConfig.cs b/src/PepperDash.Essentials.Core/Config/ILoadConfig.cs index a02baa8c..8c093176 100644 --- a/src/PepperDash.Essentials.Core/Config/ILoadConfig.cs +++ b/src/PepperDash.Essentials.Core/Config/ILoadConfig.cs @@ -6,7 +6,13 @@ using System.Threading.Tasks; namespace PepperDash.Essentials.Core; +/// +/// Defines the contract for loading configuration. This is called after all plugins have been loaded, but before any devices are initialized. This allows for any necessary configuration merging or processing to be done before devices are created and initialized. +/// public interface ILoadConfig { + /// + /// Executes the loading of the configuration. This is called after all plugins have been loaded, but before any devices are initialized. This allows for any necessary configuration merging or processing to be done before devices are created and initialized. + /// void GoWithLoad(); } diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 0706efcd..a769d2c6 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -314,12 +314,14 @@ public class ControlSystem : CrestronControlSystem, ILoadConfig, IInitialization PluginLoader.LoadPlugins(); Debug.LogMessage(LogEventLevel.Information, "Folder structure verified. Loading config..."); - if (!ConfigReader.LoadConfig2() || ConfigReader.ConfigObject == null) + if (!ConfigReader.LoadConfig() || ConfigReader.ConfigObject == null) { Debug.LogMessage(LogEventLevel.Warning, "Unable to load config file. Please ensure a valid config file is present and restart the program."); // return; } + CheckPluginVersionsAgainstConfig(); + Load(); Debug.LogMessage(LogEventLevel.Information, "Essentials load complete"); } @@ -352,6 +354,55 @@ public class ControlSystem : CrestronControlSystem, ILoadConfig, IInitialization } + private void CheckPluginVersionsAgainstConfig() + { + var versions = ConfigReader.ConfigObject.Versions; + + if (versions != null) + { + var pluginVersions = PluginLoader.EssentialsPluginAssemblies + .Select(a => + { + var packageId = a.GetCustomAttributes() + .FirstOrDefault(attr => attr.Key == "NuGetPackageId")?.Value + ?? a.Name; + return (packageId, version: a.Version.ToString()); + }) + .ToDictionary(x => x.packageId, x => x.version); + + if (versions.Essentials != null) + { + if (pluginVersions.TryGetValue("PepperDashEssentials", out var pluginVersion)) + { + if (pluginVersion != versions.Essentials) + { + Debug.LogMessage(LogEventLevel.Warning, + "Essentials version mismatch. Config version: {configVersion:l}, Loaded plugin version: {pluginVersion:l}", + versions.Essentials, pluginVersion); + } + } + } + + + foreach (var version in versions.Packages) + { + if (pluginVersions.TryGetValue(version.PackageId, out var pluginVersion)) + { + if (pluginVersion != version.Version) + { + Debug.LogMessage(LogEventLevel.Warning, + "Plugin version mismatch for {pluginKey:l}. Config version: {configVersion:l}, Loaded plugin version: {pluginVersion:l}", + version.PackageId, version.Version, pluginVersion); + } + } + else + { + Debug.LogMessage(LogEventLevel.Warning, + "Plugin {pluginKey:l} specified in config versions but not found in loaded plugins.", version.PackageId); + } + } + } + } /// /// Verifies filesystem is set up. IR, SGD, and programX folders