private DataSet DeserializeMetadata(byte[] buffer) { CompressionModes compressionModes = (CompressionModes)(m_operationalModes & OperationalModes.CompressionModeMask); bool useCommonSerializationFormat = (m_operationalModes & OperationalModes.UseCommonSerializationFormat) > 0; bool compressMetadata = (m_operationalModes & OperationalModes.CompressMetadata) > 0; Ticks startTime = DateTime.UtcNow.Ticks; DataSet deserializedMetadata; GZipStream inflater = null; if (compressMetadata && compressionModes.HasFlag(CompressionModes.GZip)) { try { // Insert compressed data into compressed buffer using (MemoryStream compressedData = new MemoryStream(buffer)) { inflater = new GZipStream(compressedData, CompressionMode.Decompress, true); buffer = inflater.ReadStream(); } } finally { if ((object)inflater != null) inflater.Close(); } } if (useCommonSerializationFormat) { // Copy decompressed data into encoded buffer using (MemoryStream encodedData = new MemoryStream(buffer)) using (XmlTextReader xmlReader = new XmlTextReader(encodedData)) { // Read encoded data into data set as XML deserializedMetadata = new DataSet(); deserializedMetadata.ReadXml(xmlReader, XmlReadMode.ReadSchema); } } else { deserializedMetadata = Serialization.Deserialize<DataSet>(buffer, SerializationFormat.Binary); } long rowCount = deserializedMetadata.Tables.Cast<DataTable>().Select(dataTable => (long)dataTable.Rows.Count).Sum(); if (rowCount > 0) { Time elapsedTime = (DateTime.UtcNow.Ticks - startTime).ToSeconds(); OnStatusMessage("Received a total of {0:N0} records spanning {1:N0} tables of meta-data that was {2}deserialized in {3}...", rowCount, deserializedMetadata.Tables.Count, compressMetadata ? "uncompressed and " : "", elapsedTime.ToString(2)); } return deserializedMetadata; }
private DataSet DeserializeMetadata(byte[] buffer) { GatewayCompressionMode gatewayCompressionMode = (GatewayCompressionMode)(m_operationalModes & OperationalModes.CompressionModeMask); bool useCommonSerializationFormat = (m_operationalModes & OperationalModes.UseCommonSerializationFormat) > 0; bool compressMetadata = (m_operationalModes & OperationalModes.CompressMetadata) > 0; DataSet deserializedMetadata; MemoryStream compressedData = null; GZipStream inflater = null; MemoryStream encodedData = null; XmlTextReader unicodeReader = null; if (compressMetadata && gatewayCompressionMode == GatewayCompressionMode.GZip) { try { // Insert compressed data into compressed buffer compressedData = new MemoryStream(buffer); inflater = new GZipStream(compressedData, CompressionMode.Decompress); buffer = inflater.ReadStream(); } finally { if ((object)inflater != null) inflater.Close(); if ((object)compressedData != null) compressedData.Close(); } } if (useCommonSerializationFormat) { try { // Copy decompressed data into encoded buffer encodedData = new MemoryStream(buffer); // Read encoded data into data set as XML unicodeReader = new XmlTextReader(encodedData); deserializedMetadata = new DataSet(); deserializedMetadata.ReadXml(unicodeReader, XmlReadMode.ReadSchema); } finally { if ((object)unicodeReader != null) unicodeReader.Close(); if ((object)encodedData != null) encodedData.Close(); } } else { deserializedMetadata = Serialization.Deserialize<DataSet>(buffer, TVA.SerializationFormat.Binary); } return deserializedMetadata; }
private SignalIndexCache DeserializeSignalIndexCache(byte[] buffer) { CompressionModes compressionModes = (CompressionModes)(m_operationalModes & OperationalModes.CompressionModeMask); bool useCommonSerializationFormat = (m_operationalModes & OperationalModes.UseCommonSerializationFormat) > 0; bool compressSignalIndexCache = (m_operationalModes & OperationalModes.CompressSignalIndexCache) > 0; SignalIndexCache deserializedCache; GZipStream inflater = null; if (compressSignalIndexCache && compressionModes.HasFlag(CompressionModes.GZip)) { try { using (MemoryStream compressedData = new MemoryStream(buffer)) { inflater = new GZipStream(compressedData, CompressionMode.Decompress, true); buffer = inflater.ReadStream(); } } finally { if ((object)inflater != null) inflater.Close(); } } if (useCommonSerializationFormat) { deserializedCache = new SignalIndexCache(); deserializedCache.Encoding = m_encoding; deserializedCache.ParseBinaryImage(buffer, 0, buffer.Length); } else { deserializedCache = Serialization.Deserialize<SignalIndexCache>(buffer, SerializationFormat.Binary); } return deserializedCache; }
private SignalIndexCache DeserializeSignalIndexCache(byte[] buffer) { GatewayCompressionMode gatewayCompressionMode = (GatewayCompressionMode)(m_operationalModes & OperationalModes.CompressionModeMask); bool useCommonSerializationFormat = (m_operationalModes & OperationalModes.UseCommonSerializationFormat) > 0; bool compressSignalIndexCache = (m_operationalModes & OperationalModes.CompressSignalIndexCache) > 0; SignalIndexCache deserializedCache; MemoryStream compressedData = null; GZipStream inflater = null; if (compressSignalIndexCache && gatewayCompressionMode == GatewayCompressionMode.GZip) { try { compressedData = new MemoryStream(buffer); inflater = new GZipStream(compressedData, CompressionMode.Decompress); buffer = inflater.ReadStream(); } finally { if ((object)inflater != null) inflater.Close(); if ((object)compressedData != null) compressedData.Close(); } } if (useCommonSerializationFormat) { deserializedCache = new SignalIndexCache(); deserializedCache.Encoding = m_encoding; deserializedCache.ParseBinaryImage(buffer, 0, buffer.Length); } else { deserializedCache = Serialization.Deserialize<SignalIndexCache>(buffer, TVA.SerializationFormat.Binary); } return deserializedCache; }