//#region IDisposable Members public void Dispose() { if (this.sectionDataReader != null) { sectionDataReader.Dispose(); this.sectionDataReader = null; } if (this.sectionData != null) { this.sectionData.Close(); this.sectionData.Dispose(); this.sectionData = null; } }
private static string GetVersionFromServerReponse(TcpClient client) { EndianAwareBinaryReader reader = new EndianAwareBinaryReader(client.GetStream(), false); try { byte type = reader.ReadByte(); if (type != 1) { throw new NAMEException($"{SupportedDependencies.RabbitMq}: Server responded with wrong type ({type})."); } //Skip channel reader.ReadUInt16(); //Read Length uint length = reader.ReadUInt32(); //Read the rest of the message into memory. The length of Connection.Start will never be bigger than int.max byte[] buffer = reader.ReadBytes((int)length); reader.Dispose(); reader = new EndianAwareBinaryReader(new MemoryStream(buffer), false); //Read class (should be Connection (10)) ushort rClass = reader.ReadUInt16(); if (rClass != 10) { throw new NAMEException($"{SupportedDependencies.RabbitMq}: Server responded with wrong class ({rClass})."); } //Read method (should be Start (10)) ushort rMethod = reader.ReadUInt16(); if (rMethod != 10) { throw new NAMEException($"{SupportedDependencies.RabbitMq}: Server responded with wrong method ({rMethod})."); } //Read AMQP major version (should be 0) byte major = reader.ReadByte(); if (major != 0) { throw new NAMEException($"{SupportedDependencies.RabbitMq}: Server responded with wrong AMQP major version ({major})."); } //Read AMQP minor version (should be 9) byte minor = reader.ReadByte(); if (major != 0) { throw new NAMEException($"{SupportedDependencies.RabbitMq}: Server responded with wrong AMQP minor version ({minor})."); } IDictionary <string, object> serverProperties = AmqpTypesReader.ReadTable(reader); if (!serverProperties.ContainsKey("version")) { throw new NAMEException($"{SupportedDependencies.RabbitMq}: Server did not send a server-properties table!"); } if (!(serverProperties["version"] is byte[])) { throw new NAMEException($"{SupportedDependencies.RabbitMq}: Server returned a version which is not a string!"); } var versionStr = Encoding.UTF8.GetString((byte[])serverProperties["version"]); return(versionStr); } finally { if (reader != null) { reader.Dispose(); } } }