WIP: AI Validator

This commit is contained in:
2025-12-15 20:05:26 +01:00
parent 096ff5573e
commit f10dfe629e
16 changed files with 1686 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ public class PluginManager
private readonly List<Type> _processorTypes = new();
private readonly List<Type> _importerTypes = new();
private readonly List<Type> _exporterTypes = new();
private readonly List<Type> _validatorTypes = new();
private readonly List<IPlugin> _plugins = new();
public PluginManager(ILogger<PluginManager> logger, IServiceProvider serviceProvider)
@@ -42,10 +43,11 @@ public class PluginManager
}
}
_logger.LogInformation("Loaded {ProcessorCount} processors, {ImporterCount} importers, and {ExporterCount} exporters from {AssemblyCount} assemblies",
_logger.LogInformation("Loaded {ProcessorCount} processors, {ImporterCount} importers, {ExporterCount} exporters, and {ValidatorCount} validators from {AssemblyCount} assemblies",
_processorTypes.Count,
_importerTypes.Count,
_exporterTypes.Count,
_validatorTypes.Count,
dllFiles.Length);
}
@@ -77,6 +79,12 @@ public class PluginManager
_exporterTypes.Add(type);
_logger.LogDebug("Registered exporter: {Type}", type.Name);
}
if (typeof(IDataValidator).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract)
{
_validatorTypes.Add(type);
_logger.LogDebug("Registered validator: {Type}", type.Name);
}
}
}
catch (Exception ex)
@@ -157,5 +165,29 @@ public class PluginManager
return null;
}
public int GetPluginsCount() => _processorTypes.Count + _importerTypes.Count + _exporterTypes.Count;
public IDataValidator? GetValidator(string validatorType)
{
foreach (var type in _validatorTypes)
{
try
{
var scope = _serviceProvider.CreateScope();
var instance = (IDataValidator)ActivatorUtilities.CreateInstance(scope.ServiceProvider, type);
if (instance.CanValidate(validatorType))
{
return instance;
}
scope.Dispose();
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to create validator instance of type {Type}", type.Name);
}
}
return null;
}
public int GetPluginsCount() => _processorTypes.Count + _importerTypes.Count + _exporterTypes.Count + _validatorTypes.Count;
}