Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class CommunicationFactory
  2. {
  3. public static ICommunication CreateCommunication(Protocol protocol, Communication configuration, ILogger logger)
  4. {
  5. ICommunication com = null;
  6. switch (protocol)
  7. {
  8. case Protocol.Tcp:
  9. var tcpConfig = (TcpConfiguration)configuration;
  10. com = new TcpCommunication(new TcpCommunicationConfiguration(tcpConfig.HostName, tcpConfig.Port, tcpConfig.BufferSize), logger);
  11. break;
  12. case Protocol.Udp:
  13. var udpConfig = (UdpConfiguration)configuration;
  14. com = new UdpCommunication(new UdpCommunicationConfiguration(udpConfig.HostName, udpConfig.Port, udpConfig.BufferSize), logger);
  15. break;
  16. case Protocol.Http:
  17. var httpConfig = (HttpConfiguration)configuration;
  18. com = new HttpCommunication(new HttpCommunicationConfiguration(httpConfig.BaseAddress, httpConfig.Verb, httpConfig.Login, httpConfig.Password, httpConfig.Headers), logger);
  19. break;
  20. }
  21. if (com == null)
  22. throw new Exception($"Unknown protocol {protocol.ToString()}");
  23.  
  24. return com;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement