Esempio n. 1
0
        public long ReadHeader(XmlReader reader, BrokeredMessage brokeredMessage, SerializationTarget serializationTarget)
        {
            byte[] numArray;
            long   num;
            List <ArraySegment <byte> > arraySegments = new List <ArraySegment <byte> >();
            long length = (long)0;

            if (serializationTarget == SerializationTarget.Communication)
            {
                reader.ReadStartElement();
            }
            do
            {
                numArray = AmqpMessageEncoder.ReadBytes(reader, 512);
                length   = length + (long)((int)numArray.Length);
                arraySegments.Add(new ArraySegment <byte>(numArray, 0, (int)numArray.Length));
            }while ((int)numArray.Length >= 512);
            if (serializationTarget == SerializationTarget.Communication)
            {
                reader.ReadEndElement();
            }
            using (BufferListStream bufferListStream = new BufferListStream(arraySegments.ToArray()))
            {
                using (AmqpMessage amqpMessage = AmqpMessage.CreateAmqpStreamMessageHeader(bufferListStream))
                {
                    amqpMessage.Deserialize(SectionFlag.NonBody);
                    brokeredMessage.MessageId = "nil";
                    AmqpMessageEncoder.UpdateBrokeredMessageHeaderAndProperties(amqpMessage, brokeredMessage, serializationTarget);
                    brokeredMessage.RawHeaderStream = amqpMessage.GetNonBodySectionsStream();
                    num = length;
                }
            }
            return(num);
        }
Esempio n. 2
0
 public override void Deserialize(SectionFlag desiredSections)
 {
     if (!this.deserialized)
     {
         BufferListStream  stream = (BufferListStream)this.bufferStream.Clone();
         AmqpMessageReader reader = new AmqpMessageReader(stream);
         reader.ReadMessage(this, desiredSections);
         stream.Dispose();
         this.deserialized = true;
     }
 }
Esempio n. 3
0
 public BufferListStream(IList <ArraySegment <byte> > bufferList)
 {
     this.bufferList = bufferList;
     for (int i = 0; i < this.bufferList.Count; i++)
     {
         BufferListStream    count = this;
         long                num   = count.length;
         ArraySegment <byte> item  = this.bufferList[i];
         count.length = num + (long)item.Count;
     }
 }
Esempio n. 4
0
            void Initialize()
            {
                this.OnInitialize();

                int encodeSize = this.GetSectionSize(this.header) +
                                 this.GetSectionSize(this.deliveryAnnotations) +
                                 this.GetSectionSize(this.messageAnnotations) +
                                 this.GetSectionSize(this.properties) +
                                 this.GetSectionSize(this.applicationProperties) +
                                 this.GetBodySize() +
                                 this.GetSectionSize(this.footer);

                List <ArraySegment <byte> > segmentList = new List <ArraySegment <byte> >(4);

                if (encodeSize == 0)
                {
                    this.AddCustomSegments(segmentList);
                }
                else
                {
                    ByteBuffer buffer        = ByteBuffer.Wrap(new byte[encodeSize]);
                    int        segmentOffset = 0;

                    this.EncodeSection(buffer, this.header);
                    this.EncodeSection(buffer, this.deliveryAnnotations);
                    this.EncodeSection(buffer, this.messageAnnotations);
                    this.EncodeSection(buffer, this.properties);
                    this.EncodeSection(buffer, this.applicationProperties);
                    if (buffer.Length > 0)
                    {
                        segmentList.Add(buffer.Array);
                    }

                    segmentOffset = buffer.Length;
                    this.EncodeBody(buffer);
                    int count = buffer.Length - segmentOffset;
                    if (count > 0)
                    {
                        segmentList.Add(new ArraySegment <byte>(buffer.Buffer, segmentOffset, count));
                    }

                    this.AddCustomSegments(segmentList);

                    if (this.footer != null)
                    {
                        segmentOffset = buffer.Length;
                        this.EncodeSection(buffer, this.footer);
                        segmentList.Add(new ArraySegment <byte>(buffer.Buffer, segmentOffset, buffer.Length - segmentOffset));
                    }
                }

                this.bufferStream = new BufferListStream(segmentList.ToArray());
            }
Esempio n. 5
0
        public static AmqpMessage BrokerGetMessage(BrokeredMessage brokeredMessage)
        {
            AmqpMessage messageId = null;
            bool        flag      = true;

            if (brokeredMessage.MessageFormat == BrokeredMessageFormat.PassthroughAmqp)
            {
                flag      = false;
                messageId = AmqpMessage.CreateAmqpStreamMessage((BufferListStream)brokeredMessage.BodyStream, true);
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Amqp)
            {
                messageId = AmqpMessage.CreateAmqpStreamMessage(brokeredMessage.RawHeaderStream, brokeredMessage.BodyStream, true);
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.AmqpEventData)
            {
                flag = false;
                BufferListStream bufferListStream = BufferListStream.Create(brokeredMessage.BodyStream, 512, true);
                messageId = AmqpMessage.CreateOutputMessage(bufferListStream, true);
                MessageAnnotations messageAnnotations = messageId.MessageAnnotations;
                messageAnnotations.Map["x-opt-sequence-number"] = brokeredMessage.SequenceNumber;
                Annotations map        = messageAnnotations.Map;
                AmqpSymbol  amqpSymbol = "x-opt-offset";
                long        offset     = brokeredMessage.Offset;
                map[amqpSymbol] = offset.ToString(NumberFormatInfo.InvariantInfo);
                messageAnnotations.Map["x-opt-enqueued-time"] = brokeredMessage.EnqueuedTimeUtc;
                if (!string.IsNullOrEmpty(brokeredMessage.Publisher))
                {
                    messageAnnotations.Map["x-opt-publisher"]     = brokeredMessage.Publisher;
                    messageAnnotations.Map["x-opt-partition-key"] = brokeredMessage.Publisher;
                }
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Sbmp)
            {
                brokeredMessage.SetPropertiesAsModifiedByBroker();
                messageId = MessageConverter.CreateAmqpMessageFromSbmpMessage(brokeredMessage);
                messageId.Properties.MessageId      = brokeredMessage.MessageId;
                messageId.Properties.CorrelationId  = brokeredMessage.CorrelationId;
                messageId.Properties.ContentType    = brokeredMessage.ContentType;
                messageId.Properties.Subject        = brokeredMessage.Label;
                messageId.Properties.To             = brokeredMessage.To;
                messageId.Properties.ReplyTo        = brokeredMessage.ReplyTo;
                messageId.Properties.GroupId        = brokeredMessage.SessionId;
                messageId.Properties.ReplyToGroupId = brokeredMessage.ReplyToSessionId;
            }
            if (flag)
            {
                MessageConverter.UpdateAmqpMessageHeadersAndProperties(messageId, brokeredMessage, true);
            }
            return(messageId);
        }
Esempio n. 6
0
        private void Advance(int count, int segmentCount)
        {
            if (count > segmentCount)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            BufferListStream bufferListStream = this;

            bufferListStream.position = bufferListStream.position + (long)count;
            BufferListStream bufferListStream1 = this;

            bufferListStream1.readOffset = bufferListStream1.readOffset + count;
            if (this.readOffset == segmentCount)
            {
                BufferListStream bufferListStream2 = this;
                bufferListStream2.readArray = bufferListStream2.readArray + 1;
                this.readOffset             = 0;
            }
        }
Esempio n. 7
0
        public static BufferListStream Create(Stream stream, int segmentSize, bool forceCopyStream)
        {
            BufferListStream bufferListStream;
            int num;

            if (stream == null)
            {
                throw FxTrace.Exception.ArgumentNull("stream");
            }
            if (!(stream is BufferListStream) || forceCopyStream)
            {
                stream.Position  = (long)0;
                bufferListStream = new BufferListStream(BufferListStream.ReadStream(stream, segmentSize, out num));
            }
            else
            {
                bufferListStream = (BufferListStream)((BufferListStream)stream).Clone();
            }
            return(bufferListStream);
        }
Esempio n. 8
0
            protected override void OnInitialize()
            {
                // mask off immutable sections except footer
                this.properties            = null;
                this.applicationProperties = null;
                this.footer = null;

                BufferListStream stream = this.messageStream as BufferListStream;

                if (stream != null && !this.ownStream)
                {
                    stream = (BufferListStream)stream.Clone();
                }
                else
                {
                    int length = 0;
                    ArraySegment <byte>[] buffers = AmqpMessage.ReadStream(this.messageStream, 512, out length);
                    stream = new BufferListStream(buffers);
                }

                AmqpMessageReader reader       = new AmqpMessageReader(stream);
                AmqpMessage       emptyMessage = AmqpMessage.Create();

                reader.ReadMessage(emptyMessage, SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations);
                this.UpdateHeader(emptyMessage.header);
                this.UpdateDeliveryAnnotations(emptyMessage.deliveryAnnotations);
                this.UpdateMessageAnnotations(emptyMessage.messageAnnotations);

                // read out the remaining buffers
                bool unused = false;

                this.buffers = stream.ReadBuffers(int.MaxValue, true, out unused);

                stream.Dispose();
                if (this.ownStream)
                {
                    this.messageStream.Dispose();
                }
            }
Esempio n. 9
0
        public long WriteHeader(XmlWriter writer, BrokeredMessage brokeredMessage, SerializationTarget serializationTarget)
        {
            long num;

            using (BufferListStream bufferListStream = BufferListStream.Create(brokeredMessage.RawHeaderStream, 512))
            {
                using (AmqpMessage amqpMessage = AmqpMessage.CreateAmqpStreamMessageHeader(bufferListStream))
                {
                    AmqpMessageEncoder.UpdateAmqpMessageHeadersAndProperties(brokeredMessage, amqpMessage, serializationTarget);
                    if (serializationTarget == SerializationTarget.Communication)
                    {
                        writer.WriteStartElement("MessageHeaders");
                    }
                    long num1 = amqpMessage.Write(writer);
                    if (serializationTarget == SerializationTarget.Communication)
                    {
                        writer.WriteEndElement();
                    }
                    num = num1;
                }
            }
            return(num);
        }
Esempio n. 10
0
 public static BufferListStream Create(Stream stream, int segmentSize)
 {
     return(BufferListStream.Create(stream, segmentSize, false));
 }
Esempio n. 11
0
 public AmqpMessageReader(BufferListStream stream)
 {
     this.stream = stream;
 }
Esempio n. 12
0
 public AmqpInputStreamMessage(BufferListStream bufferStream)
 {
     this.bufferStream = bufferStream;
 }