Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

48 řádky
1.4 KiB

  1. using System;
  2. namespace MQTTnet.Extensions.ManagedClient
  3. {
  4. public class ManagedMqttApplicationMessageBuilder
  5. {
  6. private Guid _id = Guid.NewGuid();
  7. private MqttApplicationMessage _applicationMessage;
  8. public ManagedMqttApplicationMessageBuilder WithId(Guid id)
  9. {
  10. _id = id;
  11. return this;
  12. }
  13. public ManagedMqttApplicationMessageBuilder WithApplicationMessage(MqttApplicationMessage applicationMessage)
  14. {
  15. _applicationMessage = applicationMessage;
  16. return this;
  17. }
  18. public ManagedMqttApplicationMessageBuilder WithApplicationMessage(Action<MqttApplicationMessageBuilder> builder)
  19. {
  20. if (builder == null) throw new ArgumentNullException(nameof(builder));
  21. var internalBuilder = new MqttApplicationMessageBuilder();
  22. builder(internalBuilder);
  23. _applicationMessage = internalBuilder.Build();
  24. return this;
  25. }
  26. public ManagedMqttApplicationMessage Build()
  27. {
  28. if (_applicationMessage == null)
  29. {
  30. throw new InvalidOperationException("The ApplicationMessage cannot be null.");
  31. }
  32. return new ManagedMqttApplicationMessage
  33. {
  34. Id = _id,
  35. ApplicationMessage = _applicationMessage
  36. };
  37. }
  38. }
  39. }