protected override void OnClose()
 {
     this.bufferedMessageData.Close();
     this.bufferedMessageData = null;
     this.offset = 0;
     base.OnClose();
 }
 protected override void OnClose()
 {
     this.bufferedMessageData.Close();
     this.bufferedMessageData = null; 
     this.offset = 0;
     base.OnClose();
 }
Esempio n. 3
0
 InternalByteStreamMessage(ByteStreamBufferedMessageData messageData, MessageHeaders headers, MessageProperties properties, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent)
 {
     this.headers    = new MessageHeaders(headers);
     this.properties = new MessageProperties(properties);
     this.bodyWriter = new BufferedBodyWriter(messageData);
     this.reader     = new XmlBufferedByteStreamReader(messageData, quotas);
     this.moveBodyReaderToContent = moveBodyReaderToContent;
 }
        public XmlBufferedByteStreamReader(ByteStreamBufferedMessageData bufferedMessageData, XmlDictionaryReaderQuotas quotas) : base (quotas)
        {
            Fx.Assert(bufferedMessageData != null, "bufferedMessageData is null");
            this.bufferedMessageData = bufferedMessageData;
            this.bufferedMessageData.Open(); 

            this.offset = bufferedMessageData.Buffer.Offset;
            this.quotas = quotas;
            this.position = ReaderPosition.None;
        }
        public XmlBufferedByteStreamReader(ByteStreamBufferedMessageData bufferedMessageData, XmlDictionaryReaderQuotas quotas) : base(quotas)
        {
            Fx.Assert(bufferedMessageData != null, "bufferedMessageData is null");
            this.bufferedMessageData = bufferedMessageData;
            this.bufferedMessageData.Open();

            this.offset   = bufferedMessageData.Buffer.Offset;
            this.quotas   = quotas;
            this.position = ReaderPosition.None;
        }
Esempio n. 6
0
        public static Message CreateMessage(ArraySegment <byte> buffer, BufferManager bufferManager)
        {
            if (buffer.Array == null)
            {
                throw FxTrace.Exception.ArgumentNull("buffer.Array", SR.ArgumentPropertyShouldNotBeNullError("buffer.Array"));
            }

            ByteStreamBufferedMessageData data = new ByteStreamBufferedMessageData(buffer, bufferManager);

            return(CreateMessage(data, XmlDictionaryReaderQuotas.Max, true)); // moveBodyReaderToContent is true, for consistency with the other implementations of Message (including the Message base class itself)
        }
Esempio n. 7
0
                public ByteStreamMessageBuffer(ByteStreamBufferedMessageData messageData, MessageHeaders headers, MessageProperties properties, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent)
                    : base()
                {
                    this.messageData = messageData;
                    this.headers     = new MessageHeaders(headers);
                    this.properties  = new MessageProperties(properties);
                    this.quotas      = new XmlDictionaryReaderQuotas();
                    quotas.CopyTo(this.quotas);
                    this.moveBodyReaderToContent = moveBodyReaderToContent;

                    this.messageData.Open();
                }
Esempio n. 8
0
            public InternalByteStreamMessage(ByteStreamBufferedMessageData bufferedMessageData, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent)
            {
                // Assign both writer and reader here so that we can CreateBufferedCopy without the need to
                // abstract between a streamed or buffered message. We're protected here by the state on Message
                // preventing both a read/write.

                quotas = ByteStreamMessageUtility.EnsureQuotas(quotas);

                this.bodyWriter = new BufferedBodyWriter(bufferedMessageData);
                this.headers    = new MessageHeaders(MessageVersion.None);
                this.properties = new MessageProperties();
                this.reader     = new XmlBufferedByteStreamReader(bufferedMessageData, quotas);
                this.moveBodyReaderToContent = moveBodyReaderToContent;
            }
Esempio n. 9
0
 // OnCreateBufferedCopy / OnWriteBodyContents can only be called once - protected by state on Message (either copied or written once)
 protected override BodyWriter OnCreateBufferedCopy(int maxBufferSize)
 {
     using (BufferManagerOutputStream bufferedStream = new BufferManagerOutputStream(SR.MaxReceivedMessageSizeExceeded("{0}"), maxBufferSize))
     {
         using (XmlDictionaryWriter writer = new XmlByteStreamWriter(bufferedStream, true))
         {
             OnWriteBodyContents(writer);
             writer.Flush();
             int    size;
             byte[] bytesArray = bufferedStream.ToArray(out size);
             ByteStreamBufferedMessageData bufferedMessageData = new ByteStreamBufferedMessageData(new ArraySegment <byte>(bytesArray, 0, size));
             return(new BufferedBodyWriter(bufferedMessageData));
         }
     }
 }
Esempio n. 10
0
 public override void Close()
 {
     lock (ThisLock)
     {
         if (!closed)
         {
             closed       = true;
             this.headers = null;
             if (properties != null)
             {
                 properties.Dispose();
                 properties = null;
             }
             this.messageData.Close();
             this.messageData = null;
             this.quotas      = null;
         }
     }
 }
Esempio n. 11
0
        public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
        {
            if (buffer.Array == null)
            {
                throw FxTrace.Exception.ArgumentNull("buffer.Array");
            }

            if (bufferManager == null)
            {
                throw FxTrace.Exception.ArgumentNull("bufferManager");
            }

            if (TD.ByteStreamMessageDecodingStartIsEnabled())
            {
                TD.ByteStreamMessageDecodingStart();
            }

            ByteStreamBufferedMessageData messageData = new ByteStreamBufferedMessageData(buffer, bufferManager);

            Message message = ByteStreamMessage.CreateMessage(messageData, this.bufferedReadReaderQuotas, this.moveBodyReaderToContent);

            message.Properties.Encoder = this;

            if (SMTD.MessageReadByEncoderIsEnabled())
            {
                SMTD.MessageReadByEncoder(
                    EventTraceActivityHelper.TryExtractActivity(message, true),
                    buffer.Count,
                    this);
            }

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
            }

            return(message);
        }
        public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
        {
            if (buffer.Array == null)
            {
                throw FxTrace.Exception.ArgumentNull("buffer.Array");
            }

            if (bufferManager == null)
            {
                throw FxTrace.Exception.ArgumentNull("bufferManager");
            }

            if (TD.ByteStreamMessageDecodingStartIsEnabled())
            {
                TD.ByteStreamMessageDecodingStart();
            }

            ByteStreamBufferedMessageData messageData = new ByteStreamBufferedMessageData(buffer, bufferManager);

            Message message = ByteStreamMessage.CreateMessage(messageData, this.bufferedReadReaderQuotas, this.moveBodyReaderToContent);
            message.Properties.Encoder = this;

            if (SMTD.MessageReadByEncoderIsEnabled())
            {
                SMTD.MessageReadByEncoder(
                    EventTraceActivityHelper.TryExtractActivity(message, true),
                    buffer.Count,
                    this);
            }

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
            }

            return message;
        }
        public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
        {
            if (message == null)
            {
                throw FxTrace.Exception.ArgumentNull("message");
            }
            if (bufferManager == null)
            {
                throw FxTrace.Exception.ArgumentNull("bufferManager");
            }
            if (maxMessageSize < 0)
            {
                throw FxTrace.Exception.ArgumentOutOfRange("maxMessageSize", maxMessageSize, SR.ArgumentOutOfMinRange(0));
            }
            if (messageOffset < 0)
            {
                throw FxTrace.Exception.ArgumentOutOfRange("messageOffset", messageOffset, SR.ArgumentOutOfMinRange(0));
            }

            EventTraceActivity eventTraceActivity = null;
            if (TD.ByteStreamMessageEncodingStartIsEnabled())
            {
                eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                TD.ByteStreamMessageEncodingStart(eventTraceActivity);
            }

            ThrowIfMismatchedMessageVersion(message);
            message.Properties.Encoder = this;

            ArraySegment<byte> messageBuffer;
            int size;

            using (BufferManagerOutputStream stream = new BufferManagerOutputStream(maxSentMessageSizeExceededResourceString, 0, maxMessageSize, bufferManager))
            {
                stream.Skip(messageOffset);
                using (XmlWriter writer = new XmlByteStreamWriter(stream, true))
                {
                    message.WriteMessage(writer);
                    writer.Flush();
                    byte[] bytes = stream.ToArray(out size);
                    messageBuffer = new ArraySegment<byte>(bytes, messageOffset, size - messageOffset);
                }
            }

            if (SMTD.MessageWrittenByEncoderIsEnabled())
            {
                SMTD.MessageWrittenByEncoder(
                    eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message),
                    messageBuffer.Count,
                    this);
            }

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                // DevDiv#486728
                // Don't pass in a buffer manager to avoid returning 'messageBuffer" to the bufferManager twice.
                ByteStreamBufferedMessageData messageData = new ByteStreamBufferedMessageData(messageBuffer, null);
                using (XmlReader reader = new XmlBufferedByteStreamReader(messageData, this.quotas))
                {
                    MessageLogger.LogMessage(ref message, reader, MessageLoggingSource.TransportSend);
                }
            }

            return messageBuffer;
        }
 public ByteStreamBufferedMessageDataStream(ByteStreamBufferedMessageData byteStreamBufferedMessageData)
     : base(byteStreamBufferedMessageData.Buffer.Array, byteStreamBufferedMessageData.Buffer.Offset, byteStreamBufferedMessageData.Buffer.Count, false)
 {
     this.byteStreamBufferedMessageData = byteStreamBufferedMessageData;
     this.byteStreamBufferedMessageData.Open(); //increment the refCount
 }
Esempio n. 15
0
 internal static Message CreateMessage(ByteStreamBufferedMessageData bufferedMessageData, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent)
 {
     return(new InternalByteStreamMessage(bufferedMessageData, quotas, moveBodyReaderToContent));
 }
Esempio n. 16
0
 public BufferedBodyWriter(ByteStreamBufferedMessageData bufferedMessageData)
     : base(true)
 {
     this.bufferedMessageData = bufferedMessageData;
 }
Esempio n. 17
0
        public override ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
        {
            if (message == null)
            {
                throw FxTrace.Exception.ArgumentNull("message");
            }
            if (bufferManager == null)
            {
                throw FxTrace.Exception.ArgumentNull("bufferManager");
            }
            if (maxMessageSize < 0)
            {
                throw FxTrace.Exception.ArgumentOutOfRange("maxMessageSize", maxMessageSize, SR.ArgumentOutOfMinRange(0));
            }
            if (messageOffset < 0)
            {
                throw FxTrace.Exception.ArgumentOutOfRange("messageOffset", messageOffset, SR.ArgumentOutOfMinRange(0));
            }

            EventTraceActivity eventTraceActivity = null;

            if (TD.ByteStreamMessageEncodingStartIsEnabled())
            {
                eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                TD.ByteStreamMessageEncodingStart(eventTraceActivity);
            }

            ThrowIfMismatchedMessageVersion(message);
            message.Properties.Encoder = this;

            ArraySegment <byte> messageBuffer;
            int size;

            using (BufferManagerOutputStream stream = new BufferManagerOutputStream(maxSentMessageSizeExceededResourceString, 0, maxMessageSize, bufferManager))
            {
                stream.Skip(messageOffset);
                using (XmlWriter writer = new XmlByteStreamWriter(stream, true))
                {
                    message.WriteMessage(writer);
                    writer.Flush();
                    byte[] bytes = stream.ToArray(out size);
                    messageBuffer = new ArraySegment <byte>(bytes, messageOffset, size - messageOffset);
                }
            }

            if (SMTD.MessageWrittenByEncoderIsEnabled())
            {
                SMTD.MessageWrittenByEncoder(
                    eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message),
                    messageBuffer.Count,
                    this);
            }

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                // DevDiv#486728
                // Don't pass in a buffer manager to avoid returning 'messageBuffer" to the bufferManager twice.
                ByteStreamBufferedMessageData messageData = new ByteStreamBufferedMessageData(messageBuffer, null);
                using (XmlReader reader = new XmlBufferedByteStreamReader(messageData, this.quotas))
                {
                    MessageLogger.LogMessage(ref message, reader, MessageLoggingSource.TransportSend);
                }
            }

            return(messageBuffer);
        }
 public ByteStreamBufferedMessageDataStream(ByteStreamBufferedMessageData byteStreamBufferedMessageData)
     : base(byteStreamBufferedMessageData.Buffer.Array, byteStreamBufferedMessageData.Buffer.Offset, byteStreamBufferedMessageData.Buffer.Count, false)
 {
     this.byteStreamBufferedMessageData = byteStreamBufferedMessageData;
     this.byteStreamBufferedMessageData.Open(); //increment the refCount
 }