public MetashareSession Start() { Metainfo metainfo; byte[] bytes = Bytes.Random(20000); using (FileSandbox temp = new FileSandbox(new EmptyFileLocator())) { MetainfoBuilder builder = new MetainfoBuilder(temp.Directory); string path = temp.CreateFile("debian-8.5.0-amd64-CD-1.iso"); File.WriteAllBytes(path, bytes); builder.AddFile(path); metainfo = builder.ToMetainfo(out bytes); } FileSandbox sandbox = new FileSandbox(new EmptyFileLocator()); string destination = Path.Combine(sandbox.Directory, metainfo.Hash.ToString()); File.WriteAllBytes(destination + ".metainfo", bytes); CoordinatorService glue = new CoordinatorBuilder() .WithHash(metainfo.Hash) .WithMemory(new MemoryBuilder().Build()) .WithPlugin(new MetadataPlugin(new MetadataHooks())) .Build(); MetafileService metafile = new MetafileBuilder() .WithHash(metainfo.Hash) .WithDestination(destination + ".metainfo") .WithFiles(files) .WithPipeline(pipeline) .Build(); MetashareService service = new MetashareBuilder() .WithHash(metainfo.Hash) .WithPipeline(pipeline) .WithGlue(glue) .WithMetafile(metafile) .Build(); TaskCompletionSource <bool> onVerified = new TaskCompletionSource <bool>(); metafile.Hooks.OnMetafileVerified += _ => onVerified.SetResult(true); metafile.Start(); metafile.Verify(); onVerified.Task.Wait(5000); return(new MetashareSession(service)); }
private void StartMetaStore(string destination) { MetafileHooks hooks = new MetafileHooks { OnMetafileVerified = OnMetafileVerified }; MetaStore = new MetafileBuilder() .WithHash(Hash) .WithPipeline(Pipeline) .WithFiles(Files) .WithDestination(Path.Combine(destination, $"{Hash}.metainfo")) .Build(hooks); MetaStore.Start(); }
public MetafileSession Start(bool completed = false) { Metainfo metainfo = null; byte[] data = null; using (IFileSandbox temp = new FileSandbox(new EmptyFileLocator())) { MetainfoBuilder builder = new MetainfoBuilder(temp.Directory); string path = temp.CreateFile("debian-8.5.0-amd64-CD-1.iso"); File.WriteAllBytes(path, Bytes.Random(20000)); builder.AddFile(path); metainfo = builder.ToMetainfo(out data); } IFileSandbox sandbox = new FileSandbox(new EmptyFileLocator()); string destination = Path.Combine(sandbox.Directory, metainfo.Hash.ToString()); if (completed) { File.WriteAllBytes(destination, data); } MetafileService service = new MetafileBuilder() .WithHash(metainfo.Hash) .WithDestination(destination) .WithFiles(files) .WithPipeline(pipeline) .Build(); TaskCompletionSource <bool> onVerified = new TaskCompletionSource <bool>(); service.Hooks.OnMetafileVerified += _ => onVerified.SetResult(true); return(new MetafileSession(sandbox, metainfo, destination, data, service, onVerified.Task)); }