public async Task TestDownload() { const string ZipFile = "test.zip"; var builder = new XRefArchiveBuilder(); Assert.True(await builder.DownloadAsync(new Uri("http://dotnet.github.io/docfx/xrefmap.yml"), ZipFile)); using (var xar = XRefArchive.Open(ZipFile, XRefArchiveMode.Read)) { var map = xar.GetMajor(); Assert.True(map.HrefUpdated); Assert.True(map.Sorted); Assert.NotNull(map.References); Assert.Null(map.Redirections); } File.Delete(ZipFile); }
private async Task PackReferenceAsync() { var files = GetAllFiles(); if (files.Count == 0) { return; } var dir = Path.GetDirectoryName(_packageFile); if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) { Directory.CreateDirectory(dir); } bool updateMode = File.Exists(_packageFile); using (var writer = XRefArchive.Open(_packageFile, updateMode ? XRefArchiveMode.Update : XRefArchiveMode.Create)) { if (!updateMode) { writer.CreateMajor(new XRefMap { HrefUpdated = true, Redirections = new List <XRefMapRedirection>() }); } if (files.Count == 1) { await PackOneReferenceAsync(files[0], writer); return; } // left is smaller files, right is bigger files. var left = 0; var right = files.Count - 1; var leftTask = PackOneReferenceAsync(files[left], writer); var rightTask = PackOneReferenceAsync(files[right], writer); while (left <= right) { var completed = await Task.WhenAny(new[] { leftTask, rightTask }.Where(t => t != null)); await completed; // throw if any error. if (completed == leftTask) { left++; if (left < right) { leftTask = PackOneReferenceAsync(files[left], writer); } else { leftTask = null; } } else { right--; if (left < right) { rightTask = PackOneReferenceAsync(files[right], writer); } else { rightTask = null; } } } } }