92 lines
2.6 KiB
C#
92 lines
2.6 KiB
C#
using Inspectron.Settings;
|
|
using Ninject;
|
|
using Ninject.Extensions.ChildKernel;
|
|
using Serilog;
|
|
using VisionBuilder.UI.Common.Plugins;
|
|
|
|
namespace VisionBuilder.UI.Common;
|
|
|
|
public static class Extensions
|
|
{
|
|
public static void RegisterSettings(this IKernel self)
|
|
{
|
|
// get all types from kernel that implement ISettings
|
|
var settingsTypes = self.GetAll(typeof(ISettings)).Select(x=>(ISettings)x).ToList();
|
|
// register each type as ISettings
|
|
foreach (var settingsInstance in settingsTypes)
|
|
{
|
|
settingsInstance.RegisterSettings(self.Get<InspectronSettings>());
|
|
}
|
|
}
|
|
|
|
public static void RegisterModule<T>(this IKernel self) where T : IVisionBuilderModule
|
|
{
|
|
self.Bind<T, IVisionBuilderModule>().To<T>().InSingletonScope();
|
|
}
|
|
|
|
|
|
|
|
public static void InitializeModules(this IKernel self)
|
|
{
|
|
|
|
var serviceTypes = self.GetAll(typeof(IVisionBuilderModule)).Select(x => (IVisionBuilderModule)x).ToList();
|
|
foreach (var service in serviceTypes)
|
|
{
|
|
try
|
|
{
|
|
if (service != null)
|
|
{
|
|
Log.Information($"Initializing module {service.GetType().Name}");
|
|
service.InitializeModule();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"Error initializing module {service.GetType().Name}: {e}", e);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public static IKernel LoadGlobalPlugins(this IKernel self)
|
|
{
|
|
var plugins = PluginLoader.Instance.Plugins;
|
|
foreach (var plugin in plugins)
|
|
{
|
|
try
|
|
{
|
|
Log.Information($"Initializing global plugin {plugin.GetType().Name}");
|
|
plugin.RegisterGlobalModules(self);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"Error initializing global plugin {plugin.GetType().Name}: {e}", e);
|
|
}
|
|
}
|
|
return self;
|
|
}
|
|
|
|
public static IKernel LoadCameraPlugins(this IChildKernel self, string cameraName)
|
|
{
|
|
var plugins = PluginLoader.Instance.Plugins;
|
|
foreach (var plugin in plugins)
|
|
{
|
|
try
|
|
{
|
|
Log.Information($"Initializing camera plugin {plugin.GetType().Name} for camera {cameraName}");
|
|
plugin.RegisterCameraModules(self,cameraName);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"Error initializing camera plugin {plugin.GetType().Name} for camera {cameraName}: {e}", e);
|
|
}
|
|
}
|
|
return self;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |