ReadPortProducer.cs 879 B

123456789101112131415161718192021222324
  1. namespace SHJX.Service.Control.PortProduction.PortProducerImpl
  2. {
  3. public class ReadPortProducer : IPortProducer
  4. {
  5. private static readonly ConcurrentDictionary<ArgType, IPortArg> PortArgs = new();
  6. public ReadPortProducer(OptCommand command) : base(command) { }
  7. protected override IPortArg GetPortArg(ArgType type)
  8. {
  9. if (PortArgs.TryGetValue(type, out var port))
  10. {
  11. return port;
  12. }
  13. IPortArg portArg = type switch
  14. {
  15. ArgType.Read => new ReadPortArg(),
  16. ArgType.HeatRead => new HeatReadPortArg(),
  17. ArgType.Humiture=>new HumiturePortArg(),
  18. _ => throw new ArgumentException("未找到对应的枚举!")
  19. };
  20. PortArgs.TryAdd(type, portArg);
  21. return portArg;
  22. }
  23. }
  24. }