Ejemplo n.º 1
0
        private void WriteHeader(bool endOfRecord, bool endOfMessage, long contentLength)
        {
            byte[] array  = new byte[12];
            byte[] array2 = null;
            byte[] array3 = null;
            DimeRecord.HeaderFlagsEnum headerFlagsEnum = (DimeRecord.HeaderFlagsEnum) 0;
            if (this.m_chunked && !endOfRecord)
            {
                headerFlagsEnum = DimeRecord.HeaderFlagsEnum.ChunkedRecord;
            }
            if (this.m_beginOfMessage)
            {
                headerFlagsEnum      |= DimeRecord.HeaderFlagsEnum.BeginOfMessage;
                this.m_beginOfMessage = false;
            }
            if (endOfMessage)
            {
                headerFlagsEnum |= DimeRecord.HeaderFlagsEnum.EndOfMessage;
            }
            TypeFormatEnum typeFormatEnum;
            Uri            uri;
            string         text;

            if (!this.m_chunked || this.m_firstChunk)
            {
                typeFormatEnum = this.m_typeFormat;
                uri            = this.m_id;
                text           = this.m_type;
            }
            else
            {
                typeFormatEnum = TypeFormatEnum.Unchanged;
                uri            = null;
                text           = null;
            }
            array[0] = (byte)(headerFlagsEnum | (DimeRecord.HeaderFlagsEnum) 8);
            array[1] = (byte)((byte)typeFormatEnum << 4);
            if (!this.m_chunked || this.m_firstChunk)
            {
                array[2] = 0;
                array[3] = 4;
            }
            int length;

            if (uri != null && (length = uri.AbsoluteUri.Length) > 0)
            {
                int byteCount = Encoding.ASCII.GetByteCount(uri.AbsoluteUri);
                if (byteCount > 65535)
                {
                    throw new Exception(XmlaSR.DimeRecord_EncodedTypeLengthExceeds8191);
                }
                array3 = new byte[DimeRecord.PaddedCount(byteCount)];
                Encoding.ASCII.GetBytes(this.m_id.AbsoluteUri, 0, length, array3, 0);
                array[4] = (byte)(byteCount >> 8);
                array[5] = (byte)byteCount;
            }
            if (text != null && text.Length > 0)
            {
                int byteCount = Encoding.ASCII.GetByteCount(text);
                if (byteCount > 65535)
                {
                    throw new Exception(XmlaSR.DimeRecord_EncodedTypeLengthExceeds8191);
                }
                array2 = new byte[DimeRecord.PaddedCount(byteCount)];
                Encoding.ASCII.GetBytes(text, 0, text.Length, array2, 0);
                array[6] = (byte)(byteCount >> 8);
                array[7] = (byte)byteCount;
            }
            if (contentLength > 0L)
            {
                array[8]  = (byte)(contentLength >> 24 & 255L);
                array[9]  = (byte)(contentLength >> 16 & 255L);
                array[10] = (byte)(contentLength >> 8 & 255L);
                array[11] = (byte)(contentLength & 255L);
            }
            this.m_stream.Write(array, 0, 12);
            if (array3 != null && array3.Length > 0)
            {
                this.m_stream.Write(array3, 0, array3.Length);
            }
            if (!this.m_chunked || this.m_firstChunk)
            {
                this.m_stream.Write(this.m_Options.GetBytes(), 0, 4);
            }
            if (array2 != null && array2.Length > 0)
            {
                this.m_stream.Write(array2, 0, array2.Length);
            }
            this.m_firstChunk = false;
        }
Ejemplo n.º 2
0
        private void ReadHeader()
        {
            byte[] array = new byte[12];
            DimeRecord.ForceRead(this.m_stream, array, 12);
            this.m_version = (byte)((array[0] & 248) >> 3);
            if (this.m_version != 1)
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_VersionNotSupported((int)this.m_version), "");
            }
            DimeRecord.HeaderFlagsEnum headerFlagsEnum = (DimeRecord.HeaderFlagsEnum)(array[0] & 7);
            this.m_chunked        = ((byte)(headerFlagsEnum & DimeRecord.HeaderFlagsEnum.ChunkedRecord) != 0);
            this.m_beginOfMessage = ((byte)(headerFlagsEnum & DimeRecord.HeaderFlagsEnum.BeginOfMessage) != 0);
            this.m_endOfMessage   = ((byte)(headerFlagsEnum & DimeRecord.HeaderFlagsEnum.EndOfMessage) != 0);
            if (this.m_chunked && this.m_endOfMessage)
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_InvalidHeaderFlags(this.m_beginOfMessage ? 1 : 0, 1, 1), "");
            }
            if ((!this.m_chunked && !this.m_endOfMessage) || (!this.m_firstChunk && this.m_beginOfMessage))
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_OnlySingleRecordMessagesAreSupported, "");
            }
            this.m_typeFormat = (TypeFormatEnum)((array[1] & 240) >> 4);
            this.m_reserved   = (byte)(array[1] & 15);
            int num  = ((int)array[2] << 8) + (int)array[3];
            int num2 = ((int)array[4] << 8) + (int)array[5];
            int num3 = ((int)array[6] << 8) + (int)array[7];

            this.m_contentLength = ((int)array[8] << 24) + ((int)array[9] << 16) + ((int)array[10] << 8) + (int)array[11];
            if (this.m_firstChunk)
            {
                if (this.m_typeFormat != TypeFormatEnum.MediaType)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_TypeFormatShouldBeMedia(this.m_typeFormat.ToString()), "");
                }
                if (num3 <= 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_DataTypeShouldBeSpecifiedOnTheFirstChunk, "");
                }
            }
            else
            {
                if (this.m_typeFormat != TypeFormatEnum.Unchanged)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_TypeFormatShouldBeUnchanged(this.m_typeFormat.ToString()), "");
                }
                if (num3 != 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_DataTypeIsOnlyForTheFirstChunk, "");
                }
                if (num2 != 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_IDIsOnlyForFirstChunk, "");
                }
                if (num != 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.UnknownServerResponseFormat, "Unexpected non-zero options length");
                }
            }
            if (this.m_reserved != 0)
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_ReservedFlagShouldBeZero(this.m_reserved), "");
            }
            if (num > 0)
            {
                array = new byte[DimeRecord.RoundUp(num)];
                DimeRecord.ForceRead(this.m_stream, array, array.Length);
                this.m_Options.FromBytes(array);
            }
            if (num2 > 0)
            {
                array = new byte[DimeRecord.RoundUp(num2)];
                DimeRecord.ForceRead(this.m_stream, array, array.Length);
            }
            if (num3 > 0)
            {
                array = new byte[DimeRecord.RoundUp(num3)];
                DimeRecord.ForceRead(this.m_stream, array, array.Length);
                this.m_type = Encoding.ASCII.GetString(array, 0, num3);
                if (!DataTypes.IsSupportedDataType(this.m_type))
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_DataTypeNotSupported(this.m_type), "");
                }
            }
            this.m_firstChunk = false;
        }