[성현모] DeviceManager, Factory 리팩토링, DIO, Scanner 추가
This commit is contained in:
46
eCIAv2.Library/Devices/DeviceManager.cs
Normal file
46
eCIAv2.Library/Devices/DeviceManager.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using eCIAv2.Library.Config;
|
||||
using eCIAv2.Library.Devices.DIIO;
|
||||
using eCIAv2.Library.Devices.Scanner;
|
||||
using eCIAv2.Library.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices
|
||||
{
|
||||
public class DeviceManager
|
||||
{
|
||||
private readonly Dictionary<string, IDevice> _devices = new();
|
||||
|
||||
public DeviceManager(DeviceFactory factory, ConfigService config)
|
||||
{
|
||||
foreach (var dicConfig in config.GetConfig().Configs)
|
||||
{
|
||||
//scanner
|
||||
foreach(var device in dicConfig.Value.Device.Scanners)
|
||||
{
|
||||
var scanner = factory.Create<IScanner>();
|
||||
scanner.DeviceName = device.Name;
|
||||
|
||||
_devices.Add(device.Name, scanner);
|
||||
}
|
||||
|
||||
//dio
|
||||
foreach (var device in dicConfig.Value.Device.DIOs)
|
||||
{
|
||||
var dio = factory.Create<IDIO>();
|
||||
dio.DeviceName = device.Name;
|
||||
|
||||
_devices.Add(device.Name, dio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T GetDevice<T>(string name) where T : IDevice
|
||||
{
|
||||
return (T)_devices[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user