예제 #1
0
        public static SubAckPacket InResponseTo(SubscribePacket subscribePacket, QualityOfService maxQoS)
        {
            var subAckPacket = new SubAckPacket
            {
                PacketId = subscribePacket.PacketId
            };
            IReadOnlyList<SubscriptionRequest> subscriptionRequests = subscribePacket.Requests;
            var returnCodes = new QualityOfService[subscriptionRequests.Count];
            for (int i = 0; i < subscriptionRequests.Count; i++)
            {
                QualityOfService requestedQos = subscriptionRequests[i].QualityOfService;
                returnCodes[i] = requestedQos <= maxQoS ? requestedQos : maxQoS;
            }

            subAckPacket.ReturnCodes = returnCodes;

            return subAckPacket;
        }
예제 #2
0
        public static SubAckPacket InResponseTo(SubscribePacket subscribePacket, QualityOfService maxQoS)
        {
            var subAckPacket = new SubAckPacket
            {
                PacketId = subscribePacket.PacketId
            };
            var subscriptionRequests = subscribePacket.Requests;
            var returnCodes          = new QualityOfService[subscriptionRequests.Count];

            for (int i = 0; i < subscriptionRequests.Count; i++)
            {
                QualityOfService requestedQos = subscriptionRequests[i].QualityOfService;
                returnCodes[i] = requestedQos <= maxQoS ? requestedQos : maxQoS;
            }

            subAckPacket.ReturnCodes = returnCodes;

            return(subAckPacket);
        }
예제 #3
0
        public static SubAckPacket AddSubscriptions(ISessionState session, SubscribePacket packet, QualityOfService maxSupportedQos)
        {
            List<Subscription> subscriptions = session.Subscriptions;
            var returnCodes = new List<QualityOfService>(subscriptions.Count);
            foreach (SubscriptionRequest request in packet.Requests)
            {
                Subscription existingSubscription = null;
                for (int i = subscriptions.Count - 1; i >= 0; i--)
                {
                    Subscription subscription = subscriptions[i];
                    if (subscription.TopicFilter.Equals(request.TopicFilter, StringComparison.Ordinal))
                    {
                        subscriptions.RemoveAt(i);
                        existingSubscription = subscription;
                        break;
                    }
                }

                QualityOfService finalQos = request.QualityOfService < maxSupportedQos ? request.QualityOfService : maxSupportedQos;

                subscriptions.Add(existingSubscription == null
                    ? new Subscription(request.TopicFilter, request.QualityOfService)
                    : existingSubscription.CreateUpdated(finalQos));

                returnCodes.Add(finalQos);
            }
            var ack = new SubAckPacket
            {
                PacketId = packet.PacketId,
                ReturnCodes = returnCodes
            };
            return ack;
        }
예제 #4
0
        public static SubAckPacket AddSubscriptions(ISessionState session, SubscribePacket packet, QualityOfService maxSupportedQos)
        {
            IReadOnlyList<ISubscription> subscriptions = session.Subscriptions;
            var returnCodes = new List<QualityOfService>(subscriptions.Count);
            foreach (SubscriptionRequest request in packet.Requests)
            {
                QualityOfService finalQos = request.QualityOfService < maxSupportedQos ? request.QualityOfService : maxSupportedQos;

                session.AddOrUpdateSubscription(request.TopicFilter, finalQos);

                returnCodes.Add(finalQos);
            }
            var ack = new SubAckPacket
            {
                PacketId = packet.PacketId,
                ReturnCodes = returnCodes
            };
            return ack;
        }