namespace EternalArrowBackup.TargetBinaryStorage.InMemoryBinaryStorage { using System; using System.Collections.Generic; using System.Threading.Tasks; using EternalArrowBackup.TargetBinaryStorage.Contracts; public class BinaryStorage : ITargetBinaryStorage { private Dictionary Blobs { get; } = new Dictionary(); private Dictionary Blocks { get; } = new Dictionary(); public Task GetBlobIfExists(string blobId) { if (!this.Blobs.ContainsKey(blobId)) { return Task.FromResult(default(IBlobInfo)); } return Task.FromResult(this.Blobs[blobId]); } public Task WriteBlob(string blobId, long originalSize, string[] blockKeys) { return Task.Run(() => { this.Blobs[blobId] = new BlobInfo(DateTime.UtcNow, originalSize, blockKeys); }); } public Task WriteBlock(byte[] block, string blobId, int partNumber, string blockKey) { return Task.Run(() => { this.Blocks[new BlockId(blobId, blockKey)] = new BlockInfo(blobId, partNumber, blockKey, block); }); } public Task RetrieveBlock(string blobId, string blockKey) { return Task.Run(() => this.Blocks[new BlockId(blobId, blockKey)].BlockData); } } }