public RepositorySession Start() { Metainfo metainfo; RepositoryData data = new RepositoryData(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, data.ToBytes()); builder.AddFile(path); metainfo = builder.ToMetainfo(); } FileSandbox sandbox = new FileSandbox(new EmptyFileLocator()); string destination = Path.Combine(sandbox.Directory, metainfo.Hash.ToString()); RepositoryService service = new RepositoryBuilder() .WithHash(metainfo.Hash) .WithDestination(destination) .WithFiles(files) .WithPipeline(pipeline) .WithMemory(new RepositoryMemoryImplementation()) .Build(); return(new RepositorySession(metainfo, service, sandbox, data)); }
public OmnibusSession Start() { Metainfo metainfo; byte[] data = 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, data); builder.AddFile(path); metainfo = builder.ToMetainfo(); } OmnibusService service = new OmnibusBuilder() .WithHash(metainfo.Hash) .WithPipeline(new PipelineSimulator()) .Build(); return(new OmnibusSession(metainfo, service)); }
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)); }
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)); }
public MetagetSession Start(bool completed = false) { 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()); MetagetData data = new MetagetData(bytes); if (completed) { File.WriteAllBytes(destination + ".metainfo", data.ToBytes()); } MetagetService metaget = new MetagetBuilder() .WithHash(metainfo.Hash) .WithPipeline(new PipelineSimulator()) .WithGlue(A.Fake <MetagetGlue>()) .WithMetafile(A.Fake <MetagetMetafile>()) .Build(); return(new MetagetSession(sandbox, metainfo.Hash, data, metaget)); }