Ejemplo n.º 1
0
        public static BrokeredMessage BrokerGetMessage(AmqpMessage amqpMessage, bool shouldOptimizeForPassthrough)
        {
            BrokeredMessage brokeredMessage;

            if (!shouldOptimizeForPassthrough)
            {
                amqpMessage.Deserialize(SectionFlag.All);
                brokeredMessage = new BrokeredMessage(amqpMessage.GetNonBodySectionsStream(), true, amqpMessage.GetBodySectionStream(), true, BrokeredMessageFormat.Amqp);
            }
            else
            {
                amqpMessage.Deserialize(SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties);
                brokeredMessage = new BrokeredMessage(null, false, amqpMessage.ToStream(), true, BrokeredMessageFormat.PassthroughAmqp);
            }
            if (amqpMessage.RawByteBuffers != null)
            {
                brokeredMessage.AttachDisposables(amqpMessage.RawByteBuffers.GetClones());
            }
            MessageConverter.UpdateBrokeredMessageHeaderAndProperties(amqpMessage, brokeredMessage);
            return(brokeredMessage);
        }
Ejemplo n.º 2
0
        private static void UpdateBrokeredMessageHeaderAndProperties(AmqpMessage source, BrokeredMessage target, SerializationTarget serializationTarget)
        {
            DateTime            dateTime;
            long                num;
            DateTime            dateTime1;
            ArraySegment <byte> nums;
            ArraySegment <byte> nums1;
            string              str;
            string              str1;
            long                num1;
            int    num2;
            long   num3;
            string str2;
            Guid   guid;
            string groupId;

            MessageConverter.UpdateBrokeredMessageHeaderAndProperties(source, target);
            SectionFlag sections = source.Sections;

            if ((int)(sections & SectionFlag.Header) != 0 && source.Header.DeliveryCount.HasValue)
            {
                target.DeliveryCount = (int)source.Header.DeliveryCount.Value;
            }
            if ((int)(sections & SectionFlag.MessageAnnotations) != 0)
            {
                if (source.MessageAnnotations.Map.TryGetValue <DateTime>("x-opt-enqueued-time", out dateTime))
                {
                    target.EnqueuedTimeUtc = dateTime;
                }
                if (source.MessageAnnotations.Map.TryGetValue <long>("x-opt-sequence-number", out num))
                {
                    target.SequenceNumber = num;
                }
                if (source.MessageAnnotations.Map.TryGetValue <DateTime>("x-opt-locked-until", out dateTime1))
                {
                    target.LockedUntilUtc = dateTime1;
                }
            }
            if ((int)(sections & SectionFlag.DeliveryAnnotations) != 0)
            {
                if (source.DeliveryAnnotations.Map.TryGetValue <ArraySegment <byte> >("x-opt-prefiltered-headers", out nums))
                {
                    target.PrefilteredHeaders = new MemoryStream(nums.Array, nums.Offset, nums.Count);
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <ArraySegment <byte> >("x-opt-prefiltered-headers", out nums1))
                {
                    target.PrefilteredProperties = new MemoryStream(nums1.Array, nums1.Offset, nums1.Count);
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <string>("x-opt-transfer-destination", out str))
                {
                    target.TransferDestination = str;
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <string>("x-opt-transfer-source", out str1))
                {
                    target.TransferSource = str1;
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <long>("x-opt-transfer-sn", out num1))
                {
                    target.TransferSequenceNumber = num1;
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <int>("x-opt-transfer-hop-count", out num2))
                {
                    target.TransferHopCount = num2;
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <long>("x-opt-transfer-resource", out num3))
                {
                    target.TransferDestinationResourceId = num3;
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <string>("x-opt-transfer-session", out str2))
                {
                    target.SessionId = str2;
                    BrokeredMessage brokeredMessage = target;
                    if (source.Properties == null)
                    {
                        groupId = null;
                    }
                    else
                    {
                        groupId = source.Properties.GroupId;
                    }
                    brokeredMessage.TransferSessionId = groupId;
                }
                if (source.DeliveryAnnotations.Map.TryGetValue <Guid>("x-opt-lock-token", out guid))
                {
                    target.LockToken = guid;
                }
            }
        }