Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

106 rader
3.1 KiB

  1. using System;
  2. using System.Net;
  3. namespace MQTTnet.Server
  4. {
  5. public class MqttServerOptionsBuilder
  6. {
  7. private readonly MqttServerOptions _options = new MqttServerOptions();
  8. public MqttServerOptionsBuilder WithConnectionBacklog(int value)
  9. {
  10. _options.ConnectionBacklog = value;
  11. return this;
  12. }
  13. public MqttServerOptionsBuilder WithDefaultCommunicationTimeout(TimeSpan value)
  14. {
  15. _options.DefaultCommunicationTimeout = value;
  16. return this;
  17. }
  18. public MqttServerOptionsBuilder WithDefaultEndpoint()
  19. {
  20. _options.DefaultEndpointOptions.IsEnabled = true;
  21. return this;
  22. }
  23. public MqttServerOptionsBuilder WithDefaultEndpointPort(int? value)
  24. {
  25. _options.DefaultEndpointOptions.Port = value;
  26. return this;
  27. }
  28. public MqttServerOptionsBuilder WithDefaultEndpointBoundIPAddress(IPAddress value)
  29. {
  30. _options.DefaultEndpointOptions.BoundIPAddress = value ?? IPAddress.Any;
  31. return this;
  32. }
  33. public MqttServerOptionsBuilder WithoutDefaultEndpoint()
  34. {
  35. _options.DefaultEndpointOptions.IsEnabled = false;
  36. return this;
  37. }
  38. public MqttServerOptionsBuilder WithEncryptedEndpoint()
  39. {
  40. _options.TlsEndpointOptions.IsEnabled = true;
  41. return this;
  42. }
  43. public MqttServerOptionsBuilder WithEncryptedEndpointPort(int? value)
  44. {
  45. _options.TlsEndpointOptions.Port = value;
  46. return this;
  47. }
  48. public MqttServerOptionsBuilder WithEncryptedEndpointBoundIPAddress(IPAddress value)
  49. {
  50. _options.TlsEndpointOptions.BoundIPAddress = value;
  51. return this;
  52. }
  53. public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value)
  54. {
  55. _options.TlsEndpointOptions.Certificate = value;
  56. return this;
  57. }
  58. public MqttServerOptionsBuilder WithoutEncryptedEndpoint()
  59. {
  60. _options.TlsEndpointOptions.IsEnabled = false;
  61. return this;
  62. }
  63. public MqttServerOptionsBuilder WithStorage(IMqttServerStorage value)
  64. {
  65. _options.Storage = value;
  66. return this;
  67. }
  68. public MqttServerOptionsBuilder WithConnectionValidator(Action<MqttConnectionValidatorContext> value)
  69. {
  70. _options.ConnectionValidator = value;
  71. return this;
  72. }
  73. public MqttServerOptionsBuilder WithApplicationMessageInterceptor(Action<MqttApplicationMessageInterceptorContext> value)
  74. {
  75. _options.ApplicationMessageInterceptor = value;
  76. return this;
  77. }
  78. public MqttServerOptionsBuilder WithSubscriptionInterceptor(Action<MqttSubscriptionInterceptorContext> value)
  79. {
  80. _options.SubscriptionInterceptor = value;
  81. return this;
  82. }
  83. public IMqttServerOptions Build()
  84. {
  85. return _options;
  86. }
  87. }
  88. }