Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

52 Zeilen
1.6 KiB

  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. namespace MQTTnet.Extensions.ManagedClient
  6. {
  7. public class ManagedMqttApplicationMessageBuilder
  8. {
  9. private Guid _id = Guid.NewGuid();
  10. private MqttApplicationMessage _applicationMessage;
  11. public ManagedMqttApplicationMessageBuilder WithId(Guid id)
  12. {
  13. _id = id;
  14. return this;
  15. }
  16. public ManagedMqttApplicationMessageBuilder WithApplicationMessage(MqttApplicationMessage applicationMessage)
  17. {
  18. _applicationMessage = applicationMessage;
  19. return this;
  20. }
  21. public ManagedMqttApplicationMessageBuilder WithApplicationMessage(Action<MqttApplicationMessageBuilder> builder)
  22. {
  23. if (builder == null) throw new ArgumentNullException(nameof(builder));
  24. var internalBuilder = new MqttApplicationMessageBuilder();
  25. builder(internalBuilder);
  26. _applicationMessage = internalBuilder.Build();
  27. return this;
  28. }
  29. public ManagedMqttApplicationMessage Build()
  30. {
  31. if (_applicationMessage == null)
  32. {
  33. throw new InvalidOperationException("The ApplicationMessage cannot be null.");
  34. }
  35. return new ManagedMqttApplicationMessage
  36. {
  37. Id = _id,
  38. ApplicationMessage = _applicationMessage
  39. };
  40. }
  41. }
  42. }