You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

50 lines
1.4 KiB

  1. using System;
  2. using MQTTnet.Core.Client;
  3. namespace MQTTnet.Core.ManagedClient
  4. {
  5. public class ManagedMqttClientOptionsBuilder
  6. {
  7. private readonly ManagedMqttClientOptions _options = new ManagedMqttClientOptions();
  8. public ManagedMqttClientOptionsBuilder WithAutoReconnectDelay(TimeSpan value)
  9. {
  10. _options.AutoReconnectDelay = value;
  11. return this;
  12. }
  13. public ManagedMqttClientOptionsBuilder WithStorage(IManagedMqttClientStorage value)
  14. {
  15. _options.Storage = value;
  16. return this;
  17. }
  18. public ManagedMqttClientOptionsBuilder WithClientOptions(IMqttClientOptions value)
  19. {
  20. _options.ClientOptions = value ?? throw new ArgumentNullException(nameof(value));
  21. return this;
  22. }
  23. public ManagedMqttClientOptionsBuilder WithClientOptions(Action<MqttClientOptionsBuilder> options)
  24. {
  25. if (options == null) throw new ArgumentNullException(nameof(options));
  26. var builder = new MqttClientOptionsBuilder();
  27. options(builder);
  28. _options.ClientOptions = builder.Build();
  29. return this;
  30. }
  31. public ManagedMqttClientOptions Build()
  32. {
  33. if (_options.ClientOptions == null)
  34. {
  35. throw new InvalidOperationException("The ClientOptions cannot be null.");
  36. }
  37. return _options;
  38. }
  39. }
  40. }