mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-19 23:46:49 +00:00
feat: Rename LoadConfig2 to LoadConfig and implement plugin version checks against configuration
This commit is contained in:
parent
5f4a35d425
commit
7d60c41dbc
3 changed files with 59 additions and 2 deletions
|
|
@ -35,7 +35,7 @@ namespace PepperDash.Essentials.Core.Config;
|
|||
/// <summary>
|
||||
/// LoadConfig2 method
|
||||
/// </summary>
|
||||
public static bool LoadConfig2()
|
||||
public static bool LoadConfig()
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, "Loading unmerged system/template portal configuration file.");
|
||||
try
|
||||
|
|
|
|||
|
|
@ -6,7 +6,13 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace PepperDash.Essentials.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public interface ILoadConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
void GoWithLoad();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<AssemblyMetadataAttribute>()
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies filesystem is set up. IR, SGD, and programX folders
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue