| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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<Guid, IRobot> _robotCollection;
- public RobotService()
- {
- _robotCollection = new Dictionary<Guid, IRobot>();
- }
- 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<bool> 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<IRobot> 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;
- }
- }
- }
|