public DimeRecord ReadRecord() { if (this.m_closed) { throw new InvalidOperationException(XmlaSR.DimeReader_IsClosed); } if (this.m_currentRecord != null) { if (this.m_currentRecord.EndOfMessage) { return(null); } this.m_currentRecord.Close(); } this.m_currentRecord = new DimeRecord(this.m_stream); if (this.m_Options == null) { this.m_Options = this.m_currentRecord.Options; } if (this.m_currentRecord.TypeFormat == TypeFormatEnum.None && this.m_currentRecord.EndOfMessage) { this.m_currentRecord.Close(); return(null); } return(this.m_currentRecord); }
private static void ReadPadding(Stream stream, int bytesRead) { int num = DimeRecord.PaddedCount(bytesRead) - bytesRead; for (int i = 0; i < num; i++) { stream.ReadByte(); } }
private static void WritePadding(Stream stream, int bytesWritten) { int num = DimeRecord.PaddedCount(bytesWritten) - bytesWritten; for (int i = 0; i < num; i++) { stream.WriteByte(0); } }
public override void Write(byte[] buffer, int offset, int size) { if (this.disposed) { throw new ObjectDisposedException(null); } if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset"); } if (size < 0) { throw new ArgumentOutOfRangeException("size"); } if (size + offset > buffer.Length) { throw new ArgumentException(XmlaSR.InvalidArgument, "buffer"); } try { if (size > 0) { if (this.dimeWriter == null) { this.dimeWriter = new DimeWriter(this.bufferedStream); this.dimeWriter.DefaultChunkSize = this.dimeChunkSize; this.dimeWriter.Options = base.GetTransportCapabilities(); this.dimeRecordForWrite = this.dimeWriter.CreateRecord(null, DataTypes.GetDataTypeFromEnum(this.GetRequestDataType()), TypeFormatEnum.MediaType, -1); if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace = new StackTrace(); stackTrace.GetFrame(1).GetMethod(); } } this.dimeRecordForWrite.WriteBody(buffer, offset, size); } } catch (XmlaStreamException) { throw; } catch (IOException innerException) { throw new XmlaStreamException(innerException); } catch (SocketException innerException2) { throw new XmlaStreamException(innerException2); } }
internal void WriteBody(byte[] buffer, int offset, int count) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (count < 0 || offset < 0) { throw new ArgumentOutOfRangeException(XmlaSR.DimeRecord_OffsetAndCountShouldBePositive); } if (this.m_closed) { throw new InvalidOperationException(XmlaSR.DimeRecord_StreamIsClosed); } if (this.m_ioMode != IOModeEnum.WriteOnly) { throw new InvalidOperationException(XmlaSR.DimeRecord_WriteNotAllowed); } if (this.m_chunked) { if (this.m_bytesReadWritten + count >= this.ChunkSize) { this.WriteChunkedPayload(false, false, buffer, offset, count); return; } if (this.m_bodyStreamBuffer == null) { this.m_bodyStreamBuffer = new MemoryStream((count < 512) ? 512 : count); } this.m_bodyStreamBuffer.Write(buffer, offset, count); this.m_bytesReadWritten += count; return; } else { if (this.m_bytesReadWritten + count > this.m_contentLength) { throw new Exception(XmlaSR.DimeRecord_ContentLengthExceeded); } if (!this.m_headerWritten) { this.WriteHeader(false, false, (long)this.m_contentLength); this.m_headerWritten = true; } this.m_stream.Write(buffer, offset, count); this.m_bytesReadWritten += count; if (this.m_bytesReadWritten == this.m_contentLength) { DimeRecord.WritePadding(this.m_stream, this.m_bytesReadWritten); } return; } }
public void Close() { if (this.m_closed) { return; } if (this.m_currentRecord != null) { this.m_currentRecord.Close(true); this.m_currentRecord = null; } this.m_closed = true; }
public DimeRecord CreateRecord(Uri id, string type, TypeFormatEnum typeFormat, int contentLength) { if (type == null) { throw new ArgumentNullException("type"); } if (this.m_closed) { throw new InvalidOperationException(XmlaSR.DimeWriter_WriterIsClosed); } if (this.m_currentRecord != null) { this.m_currentRecord.Close(false); } this.m_currentRecord = new DimeRecord(this.m_stream, id, type, typeFormat, this.m_firstRecord, contentLength, this.m_defaultChunkSize); this.m_currentRecord.Options = this.m_Options; this.m_firstRecord = false; return(this.m_currentRecord); }
internal int ReadBody(byte[] buffer, int offset, int count) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0 || count < 0) { throw new ArgumentOutOfRangeException("offset"); } if (this.m_closed) { throw new Exception(XmlaSR.DimeRecord_StreamIsClosed); } if (this.m_ioMode != IOModeEnum.ReadOnly) { throw new InvalidOperationException(XmlaSR.DimeRecord_ReadNotAllowed); } int num = 0; int num2 = this.m_contentLength - this.m_bytesReadWritten; if (this.m_chunked && num2 == 0) { do { this.ReadHeader(); }while (this.m_contentLength == 0 && this.m_chunked); num2 = this.m_contentLength; this.m_bytesReadWritten = 0; } if (num2 > 0) { num = this.m_stream.Read(buffer, offset, (num2 < count) ? num2 : count); this.m_bytesReadWritten += num; if (this.m_bytesReadWritten == this.m_contentLength) { DimeRecord.ReadPadding(this.m_stream, this.m_bytesReadWritten); } } return(num); }
private void WriteChunkedPayload(bool endOfRecord, bool endOfMessage, byte[] bytes, int offset, int count) { byte[] array = null; int num = 0; if (this.m_bodyStreamBuffer != null && this.m_bodyStreamBuffer.Length > 0L) { array = this.m_bodyStreamBuffer.GetBuffer(); this.m_bodyStreamBuffer = null; num = this.m_bytesReadWritten; this.m_bytesReadWritten = 0; } this.WriteHeader(endOfRecord, endOfMessage, (long)(count + num)); if (array != null) { this.m_stream.Write(array, 0, num); } if (bytes != null) { this.m_stream.Write(bytes, offset, count); } DimeRecord.WritePadding(this.m_stream, count + num); }
public override DataType GetResponseDataType() { DataType result; try { if (this.endOfStream) { result = DataType.Undetermined; } else { if (this.dimeReader == null) { this.dimeReader = new DimeReader(this.bufferedStream); this.dimeRecordForRead = this.dimeReader.ReadRecord(); if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace = new StackTrace(); stackTrace.GetFrame(1).GetMethod(); } this.DetermineNegotiatedOptions(); } if (this.dimeRecordForRead == null) { if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace2 = new StackTrace(); stackTrace2.GetFrame(1).GetMethod(); } this.dimeReader.Close(); this.dimeReader = null; this.endOfStream = true; result = DataType.Undetermined; } else { DataType dataTypeFromString = DataTypes.GetDataTypeFromString(this.dimeRecordForRead.Type); if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace3 = new StackTrace(); stackTrace3.GetFrame(1).GetMethod(); } if (dataTypeFromString == DataType.Unknown) { throw new AdomdUnknownResponseException(XmlaSR.Dime_DataTypeNotSupported(this.dimeRecordForRead.Type), ""); } result = dataTypeFromString; } } } catch (XmlaStreamException) { throw; } catch (IOException innerException) { throw new XmlaStreamException(innerException); } catch (SocketException innerException2) { throw new XmlaStreamException(innerException2); } return(result); }
public override int Read(byte[] buffer, int offset, int size) { if (this.disposed) { throw new ObjectDisposedException(null); } if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset"); } if (size < 0) { throw new ArgumentOutOfRangeException("size"); } if (size + offset > buffer.Length) { throw new ArgumentException(XmlaSR.InvalidArgument, "buffer"); } int result; try { if (size == 0 || this.endOfStream) { result = 0; } else { if (this.dimeReader == null) { this.dimeReader = new DimeReader(this.bufferedStream); this.dimeRecordForRead = this.dimeReader.ReadRecord(); if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace = new StackTrace(); stackTrace.GetFrame(1).GetMethod(); } } if (this.dimeRecordForRead == null) { if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace2 = new StackTrace(); stackTrace2.GetFrame(1).GetMethod(); } this.dimeReader.Close(); this.dimeReader = null; this.endOfStream = true; result = 0; } else { int num = this.dimeRecordForRead.ReadBody(buffer, offset, size); if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace3 = new StackTrace(); stackTrace3.GetFrame(1).GetMethod(); } if (num == 0) { this.dimeRecordForRead.Close(); this.dimeReader.Close(); this.dimeRecordForRead = null; this.dimeReader = null; this.endOfStream = true; } result = num; } } } catch (XmlaStreamException) { throw; } catch (IOException innerException) { throw new XmlaStreamException(innerException); } catch (SocketException innerException2) { throw new XmlaStreamException(innerException2); } return(result); }
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; }
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; }