public async Task <byte[]> JoinIfComplete(IInboundMessage message) { var(messageId, chunkId, chunksCount) = ExtractHeadersValues(message); var count = await _store.CountChunks(messageId); if (count >= chunksCount - 1) { var chunks = await _store.GetChunks(messageId); if (chunks.ContainsKey(chunkId)) { return(null); } chunks.Add(chunkId, message.RawContent); var completeMessage = Join(chunks); await _store.Cleanup(messageId); return(completeMessage); } else { await _store.Store(messageId, chunkId, chunksCount, message.RawContent); return(null); } }
public byte[] JoinIfComplete(MessageChunk chunk) { var count = _store.CountChunks(chunk.OriginalMessageId); if (count >= chunk.ChunksCount - 1) { var chunks = _store.GetChunks(chunk.OriginalMessageId); if (chunks.ContainsKey(chunk.ChunkId)) { return(null); } chunks.Add(chunk.ChunkId, chunk.Content); var completeMessage = Join(chunks); _store.Cleanup(chunk.OriginalMessageId); return(completeMessage); } else { _store.Store(chunk); return(null); } }