using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Team.FFFeederService; using Team.FFFeederService.Interfaces; using TeamAAS_VP.Core.Robots; using TeamAAS_VP.Interfaces; using TeamAAS_VP.Models; using TouchSocket.Core; using TouchSocket.Sockets; namespace TeamAAS_VP.Core { public class RobotService : IRobotService { private readonly Dictionary _robotCollection; public RobotService() { _robotCollection = new Dictionary(); } public bool CreateRobot(Guid id, RobotInfo robotInfo) { IRobot robot; if (robotInfo.RobotBrand == Enums.RobotBrand.EPSON) { robot = new EpsonRobot(robotInfo); } else if (robotInfo.RobotBrand == Enums.RobotBrand.FANUC) { robot = new FanucRobot(robotInfo); } else if (robotInfo.RobotBrand == Enums.RobotBrand.Schneider) { robot = new SchneiderRobot(robotInfo); } else if (robotInfo.RobotBrand == Enums.RobotBrand.XYZ_Platform || robotInfo.RobotBrand == Enums.RobotBrand.XYZU_Platform) { robot = new XYZ_Platform(robotInfo); } else { robot = new EpsonRobot(robotInfo); } if (_robotCollection.ContainsKey(id)) { var currenRobot = _robotCollection[id]; currenRobot.Dispose(); } robot.Id = id; _robotCollection[id] = robot; return true; } public Task CreateRobotAsync(Guid id, RobotInfo robotInfo) { IRobot robot; if (robotInfo.RobotBrand == Enums.RobotBrand.EPSON) { robot = new EpsonRobot(robotInfo); } else if (robotInfo.RobotBrand == Enums.RobotBrand.FANUC) { robot = new FanucRobot(robotInfo); } else if (robotInfo.RobotBrand == Enums.RobotBrand.Schneider) { robot = new SchneiderRobot(robotInfo); } else { robot = new EpsonRobot(robotInfo); } if (_robotCollection.ContainsKey(id)) { var currenRobot = _robotCollection[id]; currenRobot.Dispose(); } robot.Id = id; _robotCollection[id] = robot; return Task.FromResult(true); } public IRobot GetRobot(Guid id) { if (_robotCollection.ContainsKey(id)) { return _robotCollection[id]; } else { return null; } } public Task GetRobotAsync(Guid id) { if (_robotCollection.ContainsKey(id)) { return Task.FromResult(_robotCollection[id]); } else { return null; } } public void UnRegisterRobot(Guid id) { if (_robotCollection.ContainsKey(id)) { var robot = _robotCollection[id]; robot.Dispose(); } } public Task UnRegisterRobotAsync(Guid id) { if (_robotCollection.ContainsKey(id)) { var robot = _robotCollection[id]; robot.Dispose(); } return Task.CompletedTask; } } }