io commander
This commit is contained in:
36
VisionBuilder.UI.IOCommander/ModuleExtensions.cs
Normal file
36
VisionBuilder.UI.IOCommander/ModuleExtensions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Ninject.Extensions.ChildKernel;
|
||||
using System.ComponentModel;
|
||||
using Ninject;
|
||||
using VisionBuilder.UI.Common;
|
||||
using VisionBuilder.UI.IOCommander.Interfaces;
|
||||
using VisionBuilder.UI.IOCommander.Modules;
|
||||
using VisionBuilder.UI.IOCommander.Settings;
|
||||
|
||||
namespace VisionBuilder.UI.IOCommander;
|
||||
|
||||
public static class ModuleExtensions
|
||||
{
|
||||
public static IKernel UseIOCommander(this IKernel self, string[] cameraNames)
|
||||
{
|
||||
// for settings to work properly
|
||||
TypeDescriptor.AddAttributes(typeof(List<IOCommanderPinAction>), new TypeConverterAttribute(typeof(IOCommanderPinActionListConverter)));
|
||||
|
||||
TypeDescriptor.AddAttributes(typeof(List<IOCommanderCommand>), new TypeConverterAttribute(typeof(IOCommanderCommandListConverter)));
|
||||
|
||||
List<IOCommanderCameraSettings> cameras = cameraNames.Select(name => new IOCommanderCameraSettings(name)).ToList();
|
||||
self.Bind<IOCommanderSettings, ISettings>().ToConstant(new IOCommanderSettings(cameras.ToArray()));
|
||||
self.Bind<IOCommanderModule,IVisionBuilderModule>().To<IOCommanderModule>().InSingletonScope();
|
||||
self.Bind<IOCommanderProgramModule, IVisionBuilderModule>().To<IOCommanderProgramModule>().InSingletonScope();
|
||||
self.Bind<IIOCommanderDebugViewService>().To<NoDebugView>().InSingletonScope();
|
||||
return self;
|
||||
}
|
||||
|
||||
public static IChildKernel UseCameraIOCommander(this IChildKernel self, string cameraName)
|
||||
{
|
||||
var ioCommanderSettings = self.Get<IOCommanderSettings>();
|
||||
var cameraSettings=ioCommanderSettings.Cameras.First(x => x.CameraName == cameraName);
|
||||
self.Bind<IOCommanderCameraSettings, ISettings>().ToConstant(cameraSettings);
|
||||
self.Bind<IOCommanderCameraModule, IVisionBuilderModule>().To<IOCommanderCameraModule>().InSingletonScope();
|
||||
return self;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user