Stream that wraps the data with TDS protocol
Inheritance: Stream
Exemplo n.º 1
0
 /// <summary>
 /// Protocol-aware deflation routine
 /// </summary>
 /// <param name="stream">Destination to deflate the message</param>
 public void Deflate(TDSStream stream)
 {
     // Iterate through each message
     foreach (TDSMessage current in this)
     {
         // Deflate the message
         current.Deflate(stream);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Inflate the message from protocol-aware stream on the server
        /// </summary>
        /// <param name="stream">Source to inflate the message</param>
        public bool InflateClientRequest(TDSStream stream)
        {
            // Chck if data stream is fully inflated
            if (!_InflateDataStream(stream))
            {
                return(false);
            }

            // Inflate all tokens in the stream
            _InflateClientTokens();

            // If we reached this point it means that both data and tokens are inflated
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Inflate the message from protocol-aware stream on the client side
        /// </summary>
        /// <param name="clientState">State of the client parser</param>
        /// <param name="stream">Source to inflate the message</param>
        public bool InflateServerResponse(TDSClientState clientState, TDSStream stream)
        {
            // Chck if data stream is fully inflated
            if (!_InflateDataStream(stream))
            {
                return(false);
            }

            // Inflate all tokens in the stream
            _InflateServerTokens(clientState);

            // If we reached this point it means that both data and tokens are inflated
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Protocol-aware deflation routine
        /// </summary>
        /// <param name="stream">Destination to deflate the message</param>
        public void Deflate(TDSStream stream)
        {
            // Start a message on the stream
            stream.StartMessage(MessageType);

            // Iterate through each token and deflate it
            foreach (TDSPacketToken token in this)
            {
                // Deflate token into the data stream
                token.Deflate(stream);
            }

            // Complete the message
            stream.EndMessage();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initialization constructor
        /// </summary>
        public AutoTDSStream(TDSStream innerTDSStream, bool closeInnerStream)
        {
            // Check if inner stream is valid
            if (innerTDSStream == null)
            {
                // We can't proceed without underlying stream
                throw new ArgumentNullException("innerTDSStream", "Underlying TDS stream is required");
            }

            // Save transport stream
            InnerTDSStream = innerTDSStream;

            // Save whether inner stream is to be closed as well
            _closeInnerStream = closeInnerStream;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Inflates the stream of data in this message
        /// </summary>
        /// <returns></returns>
        private bool _InflateDataStream(TDSStream stream)
        {
            // Indicates that end-of-message marker was reached
            bool isEndOfMessageReached = false;

            // Continue inflating packets as long as there's data in the stream or we've not reached the end of the message
            while (!isEndOfMessageReached)
            {
                // Chunk of data still available in the current packet
                int packetDataLeft = 0;

                // Check if we have a packet header
                if (stream.IncomingPacketHeader != null)
                {
                    // Calculate the chunk of remaining data
                    packetDataLeft = stream.IncomingPacketHeader.Length - stream.IncomingPacketPosition;
                }

                // Check if we have data to work with
                if (packetDataLeft == 0)
                {
                    // Position stream on the next packet header and read it
                    if (!stream.ReadNextHeader())
                    {
                        // We couldn't inflate the next packet header
                        break;
                    }

                    // Record packet status
                    PacketStatuses.Add(stream.IncomingPacketHeader.Status);

                    // Use the packet header to establish message type
                    MessageType = stream.IncomingPacketHeader.Type;

                    // Recalculate the chunk of remaining data
                    packetDataLeft = stream.IncomingPacketHeader.Length - stream.IncomingPacketPosition;
                }

                // Allocate a buffer to read the data into the buffer
                byte[] packetDataBuffer = new byte[packetDataLeft];

                // Read the data into the buffer
                int packetDataRead = stream.Read(packetDataBuffer, 0, packetDataLeft);

                // Check if we have a data stream
                if (_dataStream == null)
                {
                    // Allocate a new data stream
                    _dataStream = new MemoryStream();
                }

                // Write the data into the message stream
                _dataStream.Write(packetDataBuffer, 0, packetDataRead);

                // Check if the whole packet was read
                if (packetDataRead < packetDataLeft)
                {
                    // We don't have enough data to inflate the whole message
                    break;
                }

                // Check if inflation succeded
                isEndOfMessageReached = (stream.IncomingPacketHeader.Status & TDSPacketStatus.EndOfMessage) != 0;
            }

            // Tell caller whether we reached the end of message
            return(isEndOfMessageReached);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initialization constructor
 /// </summary>
 public AutoTDSStream(TDSStream innerTDSStream) :
     this(innerTDSStream, true)
 {
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initialization constructor
        /// </summary>
        public AutoTDSStream(TDSStream innerTDSStream, bool closeInnerStream)
        {
            // Check if inner stream is valid
            if (innerTDSStream == null)
            {
                // We can't proceed without underlying stream
                throw new ArgumentNullException("innerTDSStream", "Underlying TDS stream is required");
            }

            // Save transport stream
            InnerTDSStream = innerTDSStream;

            // Save whether inner stream is to be closed as well
            _closeInnerStream = closeInnerStream;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initialization constructor
 /// </summary>
 public AutoTDSStream(TDSStream innerTDSStream) :
     this(innerTDSStream, true)
 {
 }