RobotService.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Team.FFFeederService;
  7. using Team.FFFeederService.Interfaces;
  8. using TeamAAS_VP.Core.Robots;
  9. using TeamAAS_VP.Interfaces;
  10. using TeamAAS_VP.Models;
  11. using TouchSocket.Core;
  12. using TouchSocket.Sockets;
  13. namespace TeamAAS_VP.Core
  14. {
  15. public class RobotService : IRobotService
  16. {
  17. private readonly Dictionary<Guid, IRobot> _robotCollection;
  18. public RobotService()
  19. {
  20. _robotCollection = new Dictionary<Guid, IRobot>();
  21. }
  22. public bool CreateRobot(Guid id, RobotInfo robotInfo)
  23. {
  24. IRobot robot;
  25. if (robotInfo.RobotBrand == Enums.RobotBrand.EPSON)
  26. {
  27. robot = new EpsonRobot(robotInfo);
  28. }
  29. else if (robotInfo.RobotBrand == Enums.RobotBrand.FANUC)
  30. {
  31. robot = new FanucRobot(robotInfo);
  32. }
  33. else if (robotInfo.RobotBrand == Enums.RobotBrand.Schneider)
  34. {
  35. robot = new SchneiderRobot(robotInfo);
  36. }
  37. else if (robotInfo.RobotBrand == Enums.RobotBrand.XYZ_Platform || robotInfo.RobotBrand == Enums.RobotBrand.XYZU_Platform)
  38. {
  39. robot = new XYZ_Platform(robotInfo);
  40. }
  41. else
  42. {
  43. robot = new EpsonRobot(robotInfo);
  44. }
  45. if (_robotCollection.ContainsKey(id))
  46. {
  47. var currenRobot = _robotCollection[id];
  48. currenRobot.Dispose();
  49. }
  50. robot.Id = id;
  51. _robotCollection[id] = robot;
  52. return true;
  53. }
  54. public Task<bool> CreateRobotAsync(Guid id, RobotInfo robotInfo)
  55. {
  56. IRobot robot;
  57. if (robotInfo.RobotBrand == Enums.RobotBrand.EPSON)
  58. {
  59. robot = new EpsonRobot(robotInfo);
  60. }
  61. else if (robotInfo.RobotBrand == Enums.RobotBrand.FANUC)
  62. {
  63. robot = new FanucRobot(robotInfo);
  64. }
  65. else if (robotInfo.RobotBrand == Enums.RobotBrand.Schneider)
  66. {
  67. robot = new SchneiderRobot(robotInfo);
  68. }
  69. else
  70. {
  71. robot = new EpsonRobot(robotInfo);
  72. }
  73. if (_robotCollection.ContainsKey(id))
  74. {
  75. var currenRobot = _robotCollection[id];
  76. currenRobot.Dispose();
  77. }
  78. robot.Id = id;
  79. _robotCollection[id] = robot;
  80. return Task.FromResult(true);
  81. }
  82. public IRobot GetRobot(Guid id)
  83. {
  84. if (_robotCollection.ContainsKey(id))
  85. {
  86. return _robotCollection[id];
  87. }
  88. else
  89. {
  90. return null;
  91. }
  92. }
  93. public Task<IRobot> GetRobotAsync(Guid id)
  94. {
  95. if (_robotCollection.ContainsKey(id))
  96. {
  97. return Task.FromResult(_robotCollection[id]);
  98. }
  99. else
  100. {
  101. return null;
  102. }
  103. }
  104. public void UnRegisterRobot(Guid id)
  105. {
  106. if (_robotCollection.ContainsKey(id))
  107. {
  108. var robot = _robotCollection[id];
  109. robot.Dispose();
  110. }
  111. }
  112. public Task UnRegisterRobotAsync(Guid id)
  113. {
  114. if (_robotCollection.ContainsKey(id))
  115. {
  116. var robot = _robotCollection[id];
  117. robot.Dispose();
  118. }
  119. return Task.CompletedTask;
  120. }
  121. }
  122. }