Exemple #1
0
        public Task <MqttClientPublishResult> PublishAsync(MqttApplicationMessage applicationMessage, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            MqttTopicValidator.ThrowIfInvalid(applicationMessage);

            ThrowIfDisposed();
            ThrowIfNotConnected();

            var publishPacket = _adapter.PacketFormatterAdapter.DataConverter.CreatePublishPacket(applicationMessage);

            switch (applicationMessage.QualityOfServiceLevel)
            {
            case MqttQualityOfServiceLevel.AtMostOnce:
            {
                return(PublishAtMostOnce(publishPacket, cancellationToken));
            }

            case MqttQualityOfServiceLevel.AtLeastOnce:
            {
                return(PublishAtLeastOnceAsync(publishPacket, cancellationToken));
            }

            case MqttQualityOfServiceLevel.ExactlyOnce:
            {
                return(PublishExactlyOnceAsync(publishPacket, cancellationToken));
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
 public void Invalid_Topic_Empty()
 {
     MqttTopicValidator.ThrowIfInvalid(string.Empty);
 }
 public void Invalid_Topic_Plus()
 {
     MqttTopicValidator.ThrowIfInvalid("/a/+/c");
 }
 public void Invalid_Topic_Hash()
 {
     MqttTopicValidator.ThrowIfInvalid("/a/#/c");
 }
 public void Valid_Topic()
 {
     MqttTopicValidator.ThrowIfInvalid("/a/b/c");
 }