/// <inheritdoc /> protected override IEnumerable <MessageRecord> ReadMessagesFromStream(Stream stream, MessageQuery query) { if (compress) { stream = new GZipStream(stream, CompressionMode.Decompress, false); } var commandSerializer = new MessageBinarySerializer(stream, Serializer); for (MessageRecord message; (message = commandSerializer.Read()) != null;) { if (query.Match(message)) { yield return(message); } } }
/// <inheritdoc /> public Task AddAsync(MessageRecord messageRecord, CancellationToken cancellationToken) { if (disposed) { throw new ObjectDisposedException(null); } lock (SyncRoot) { // We cannot continue zip streams, so we have to create new file // every time with new stream. string name = GetAvailableFileNameByDate(currentFileStream, DateTime.Now, compress); if (currentFileStream == null || System.IO.Path.GetFileName(currentFileStream.Name) != name) { Close(); currentFileStream = new FileStream(System.IO.Path.Combine(Path, name), FileMode.Append); if (compress) { currentGZipStream = new GZipStream(currentFileStream, CompressionMode.Compress); } currentBinarySerializer = new MessageBinarySerializer(CurrentStream, Serializer); } currentBinarySerializer.Write(messageRecord); } if (!BufferStream) { lock (SyncRoot) { currentGZipStream?.Flush(); currentFileStream.Flush(); } } return(completedTask); }