Esempio n. 1
0
        /// <inheritdoc cref="IMqttClient.UnsubscribeAsync" />
        public Task <MqttClientUnsubscribeResult> UnsubscribeAsync(
            MqttClientUnsubscribeOptions options,
            CancellationToken cancellationToken)
        {
            Check.NotNull(options, nameof(options));

            _broker.Unsubscribe(ClientId, options.TopicFilters);

            var result = new MqttClientUnsubscribeResult();

            options.TopicFilters.ForEach(filter => result.Items.Add(MapUnsubscribeResultItem(filter)));
            return(Task.FromResult(result));
        }
Esempio n. 2
0
        public MqttClientUnsubscribeResult CreateClientUnsubscribeResult(MqttUnsubscribePacket unsubscribePacket, MqttUnsubAckPacket unsubAckPacket)
        {
            if (unsubscribePacket == null)
            {
                throw new ArgumentNullException(nameof(unsubscribePacket));
            }
            if (unsubAckPacket == null)
            {
                throw new ArgumentNullException(nameof(unsubAckPacket));
            }

            var result = new MqttClientUnsubscribeResult();

            result.Items.AddRange(unsubscribePacket.TopicFilters.Select((t, i) =>
                                                                        new MqttClientUnsubscribeResultItem(t, MqttClientUnsubscribeResultCode.Success)));

            return(result);
        }
Esempio n. 3
0
        public MqttClientUnsubscribeResult CreateClientUnsubscribeResult(MqttUnsubscribePacket unsubscribePacket, MqttUnsubAckPacket unsubAckPacket)
        {
            if (unsubscribePacket == null)
            {
                throw new ArgumentNullException(nameof(unsubscribePacket));
            }
            if (unsubAckPacket == null)
            {
                throw new ArgumentNullException(nameof(unsubAckPacket));
            }

            if (unsubAckPacket.ReasonCodes.Count != unsubscribePacket.TopicFilters.Count)
            {
                throw new MqttProtocolViolationException("The return codes are not matching the topic filters [MQTT-3.9.3-1].");
            }

            var result = new MqttClientUnsubscribeResult();

            result.Items.AddRange(unsubscribePacket.TopicFilters.Select((t, i) =>
                                                                        new MqttClientUnsubscribeResultItem(t, (MqttClientUnsubscribeResultCode)unsubAckPacket.ReasonCodes[i])));

            return(result);
        }