namespace EternalArrowBackup.SourceStorage.InMemorySourceStorage { using System; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; using EternalArrowBackup.SourceStorage.Contracts; public class SourceStorage : ISourceStorage { public SourceStorage(ImmutableDictionary> storageData) { this.StorageData = storageData; } private ImmutableDictionary> StorageData { get; } public Task GetAllDirectories(ITargetBlock actionBlock, CancellationToken ct) { return Task.Run(() => { foreach (var kvp in this.StorageData) { if (ct.IsCancellationRequested) { break; } actionBlock.Post(new SourceDirectory(kvp.Key, kvp.Value)); } actionBlock.Complete(); }); } public Task GetDirectory(string normalizedRelativePath) { return Task.Run(() => (ISourceDirectory)new SourceDirectory(normalizedRelativePath, this.StorageData[normalizedRelativePath])); } } }