WIP, abandoned: One-way backup tool with versioning and client-side encryption. Your precious data will never get lost!
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
namespace EternalArrowBackup.SourceStorage.InMemorySourceStorage
|
|
|
|
|
{
|
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Threading.Tasks.Dataflow;
|
|
|
|
|
using EternalArrowBackup.SourceStorage.Contracts;
|
|
|
|
|
|
|
|
|
|
internal class SourceDirectory : ISourceDirectory
|
|
|
|
|
{
|
|
|
|
|
public SourceDirectory(string path, ImmutableDictionary<string, byte[]> storageData)
|
|
|
|
|
{
|
|
|
|
|
this.NormalizedRelativePath = path;
|
|
|
|
|
this.StorageData = storageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NormalizedRelativePath { get; }
|
|
|
|
|
|
|
|
|
|
private ImmutableDictionary<string, byte[]> StorageData { get; }
|
|
|
|
|
|
|
|
|
|
public Task GetAllFiles(ActionBlock<ISourceFile> actionBlock, CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var kvp in this.StorageData)
|
|
|
|
|
{
|
|
|
|
|
if (ct.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actionBlock.Post(new SourceFile(kvp.Key, kvp.Value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actionBlock.Complete();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ISourceFile> GetFile(string filename)
|
|
|
|
|
{
|
|
|
|
|
return Task.Run(() => (ISourceFile)new SourceFile(filename, this.StorageData[filename]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|