public string CreateMinor(XRefMap map, IEnumerable <string> names) { if (map == null) { throw new ArgumentNullException(nameof(map)); } if (_mode == XRefArchiveMode.Read) { throw new InvalidOperationException("Cannot create entry for readonly archive."); } if (names != null) { foreach (var name in names) { var entryName = NormalizeName(name); if (entryName != null && HasEntryCore(entryName)) { return(CreateCore(entryName, map)); } } } while (true) { var entryName = Guid.NewGuid().ToString() + ".yml"; if (HasEntryCore(entryName)) { return(CreateCore(entryName, map)); } } }
private string CreateCore(string name, XRefMap map) { var entry = CreateEntry(name); using (var sw = new StreamWriter(entry.Open())) { YamlUtility.Serialize(sw, map); } return(name); }
private static IEnumerable <string> GetNames(Uri uri, XRefMap map) { var name = uri.Segments.LastOrDefault(); yield return(name); if (map.References?.Count > 0) { yield return(map.References[0].Uid); } }
private void UpdateCore(string name, XRefMap map) { var entry = _archive.GetEntry(name); entry.Delete(); entry = _archive.CreateEntry(name); using (var sw = new StreamWriter(entry.Open())) { YamlUtility.Serialize(sw, map); } }
public BasicXRefMapReader(XRefMap map) { Map = map ?? throw new ArgumentNullException(nameof(map)); if (map.HrefUpdated != true && map.BaseUrl != null) { if (!Uri.TryCreate(map.BaseUrl, UriKind.Absolute, out Uri baseUri)) { throw new InvalidDataException($"Xref map file has an invalid base url: {map.BaseUrl}."); } map.UpdateHref(baseUri); } }
public string CreateMajor(XRefMap map) { if (map == null) { throw new ArgumentNullException(nameof(map)); } if (_mode == XRefArchiveMode.Read) { throw new InvalidOperationException("Cannot create entry for readonly archive."); } if (HasEntryCore(MajorFileName)) { throw new InvalidOperationException("Major entry existed."); } return(CreateCore(MajorFileName, map)); }
/// <summary> /// Export xref map file. /// </summary> private static void ExportXRefMap(DocumentBuildParameters parameters, DocumentBuildContext context) { Logger.LogVerbose("Exporting xref map..."); var xrefMap = new XRefMap(); xrefMap.References = (from xref in context.XRefSpecMap.Values.AsParallel().WithDegreeOfParallelism(parameters.MaxParallelism) select new XRefSpec(xref) { Href = ((RelativePath)context.FileMap[xref.Href]).RemoveWorkingFolder().ToString() + "#" + XRefDetails.GetHtmlId(xref.Uid), }).ToList(); xrefMap.Sort(); YamlUtility.Serialize( Path.Combine(parameters.OutputBaseDir, XRefMapFileName), xrefMap); Logger.LogInfo("XRef map exported."); }
public static void UpdateHref(XRefMap map, Uri uri) { if (!string.IsNullOrEmpty(map.BaseUrl)) { if (!Uri.TryCreate(map.BaseUrl, UriKind.Absolute, out Uri baseUri)) { throw new InvalidDataException($"Xref map file (from {uri.AbsoluteUri}) has an invalid base url: {map.BaseUrl}."); } map.UpdateHref(baseUri); return; } if (uri.Scheme == "http" || uri.Scheme == "https") { map.UpdateHref(uri); return; } throw new InvalidDataException($"Xref map file (from {uri.AbsoluteUri}) missing base url."); }
public async Task <IXRefContainerReader> CreateAsync() { AddToDownloadList(_uris); var dict = new Dictionary <string, IXRefContainer>(); while (_processing.Count > 0) { var task = await Task.WhenAny(_processing.Keys); var uri = _processing[task]; _processing.Remove(task); try { var container = await task; if (!container.IsEmbeddedRedirections) { AddToDownloadList( from r in container.GetRedirections() where r != null select GetUri(uri, r.Href) into u where u != null select u); } dict[uri.IsAbsoluteUri ? uri.AbsoluteUri : uri.OriginalString] = container; } catch (Exception ex) { Logger.LogWarning($"Unable to download xref map file from {uri}, details: {ex.Message}"); } } var fakeEntry = Guid.NewGuid().ToString(); dict[fakeEntry] = new XRefMap { HrefUpdated = true, Redirections = (from pair in dict select new XRefMapRedirection { Href = pair.Key, }).ToList() }; return(new XRefMapReader(fakeEntry, dict)); }
/// <summary> /// Export xref map file. /// </summary> private static string ExportXRefMap(DocumentBuildParameters parameters, DocumentBuildContext context) { Logger.LogVerbose("Exporting xref map..."); var xrefMap = new XRefMap(); xrefMap.References = (from xref in context.XRefSpecMap.Values.AsParallel().WithDegreeOfParallelism(parameters.MaxParallelism) select new XRefSpec(xref) { Href = context.UpdateHref(xref.Href, RelativePath.WorkingFolder) }).ToList(); xrefMap.Sort(); string xrefMapFileNameWithVersion = GetXrefMapFileNameWithGroup(parameters); YamlUtility.Serialize( Path.GetFullPath(Environment.ExpandEnvironmentVariables(Path.Combine(parameters.OutputBaseDir, xrefMapFileNameWithVersion))), xrefMap, YamlMime.XRefMap); Logger.LogInfo("XRef map exported."); return(xrefMapFileNameWithVersion); }
public async Task<IXRefContainerReader> CreateAsync() { AddToDownloadList(_uris); var dict = new Dictionary<string, IXRefContainer>(); while (_processing.Count > 0) { var task = await Task.WhenAny(_processing.Keys); var uri = _processing[task]; _processing.Remove(task); try { var container = await task; if (!container.IsEmbeddedRedirections) { AddToDownloadList( from r in container.GetRedirections() where r != null select GetUri(uri, r.Href) into u where u != null select u); } dict[uri.IsAbsoluteUri ? uri.AbsoluteUri : uri.OriginalString] = container; } catch (Exception ex) { Logger.LogWarning($"Unable to download xref map file from {uri}, details: {ex.Message}"); } } var fakeEntry = Guid.NewGuid().ToString(); dict[fakeEntry] = new XRefMap { HrefUpdated = true, Redirections = (from pair in dict select new XRefMapRedirection { Href = pair.Key, }).ToList() }; return new XRefMapReader(fakeEntry, dict); }
public void Update(string name, XRefMap map) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (map == null) { throw new ArgumentNullException(nameof(map)); } if (_mode == XRefArchiveMode.Read) { throw new InvalidOperationException("Cannot create entry for readonly archive."); } var entryName = GetEntry(name); if (entryName == null) { throw new InvalidOperationException($"Entry {name} not found."); } UpdateCore(name, map); }
private static async Task <XRefMap> DownloadBySchemeAsync(Uri uri) { XRefMap result = null; if (uri.IsFile) { result = DownloadFromLocal(uri); } else if (uri.Scheme == "http" || uri.Scheme == "https" || uri.Scheme == "ftp") { result = await DownloadFromWebAsync(uri); } else { throw new ArgumentException($"Unsupported scheme {uri.Scheme}, expected: http, https, ftp, file.", nameof(uri)); } if (result == null) { throw new InvalidDataException($"Invalid yaml file from {uri}."); } return(result); }
/// <summary> /// Export xref map file. /// </summary> private static string ExportXRefMap(DocumentBuildParameters parameters, DocumentBuildContext context) { Logger.LogVerbose("Exporting xref map..."); var xrefMap = new XRefMap(); xrefMap.References = (from xref in context.XRefSpecMap.Values.AsParallel().WithDegreeOfParallelism(parameters.MaxParallelism) select new XRefSpec(xref) { Href = ((RelativePath)context.GetFilePath(UriUtility.GetNonFragment(xref.Href))).RemoveWorkingFolder() + UriUtility.GetFragment(xref.Href) }).ToList(); xrefMap.Sort(); string xrefMapFileNameWithVersion = string.IsNullOrEmpty(parameters.VersionName) ? XRefMapFileName : parameters.VersionName + "." + XRefMapFileName; YamlUtility.Serialize( xrefMapFileNameWithVersion, xrefMap, YamlMime.XRefMap); Logger.LogInfo("XRef map exported."); return(xrefMapFileNameWithVersion); }
public void UpdateMajor(XRefMap map) => Update(MajorFileName, map);
private string CreateCore(string name, XRefMap map) { var entry = CreateEntry(name); using (var sw = new StreamWriter(entry.Open())) { YamlUtility.Serialize(sw, map, YamlMime.XRefMap); } return name; }
public BasicXRefMapReader(XRefMap map) { Map = map ?? throw new ArgumentNullException(nameof(map)); }
private void UpdateCore(string name, XRefMap map) { var entry = _archive.GetEntry(name); entry.Delete(); entry = _archive.CreateEntry(name); using (var sw = new StreamWriter(entry.Open())) { YamlUtility.Serialize(sw, map, YamlMime.XRefMap); } }
public string CreateMajor(XRefMap map) { if (map == null) { throw new ArgumentNullException(nameof(map)); } if (_mode == XRefArchiveMode.Read) { throw new InvalidOperationException("Cannot create entry for readonly archive."); } if (HasEntryCore(MajorFileName)) { throw new InvalidOperationException("Major entry existed."); } return CreateCore(MajorFileName, map); }
/// <summary> /// Export xref map file. /// </summary> private static string ExportXRefMap(DocumentBuildParameters parameters, DocumentBuildContext context) { Logger.LogVerbose("Exporting xref map..."); var xrefMap = new XRefMap(); xrefMap.References = (from xref in context.XRefSpecMap.Values.AsParallel().WithDegreeOfParallelism(parameters.MaxParallelism) select new XRefSpec(xref) { Href = ((RelativePath)context.FileMap[UriUtility.GetNonFragment(xref.Href)]).RemoveWorkingFolder() + UriUtility.GetFragment(xref.Href) }).ToList(); xrefMap.Sort(); string xrefMapFileNameWithVersion = string.IsNullOrEmpty(parameters.VersionName) ? XRefMapFileName : parameters.VersionName + "." + XRefMapFileName; YamlUtility.Serialize( Path.Combine(parameters.OutputBaseDir, xrefMapFileNameWithVersion), xrefMap, YamlMime.XRefMap); Logger.LogInfo("XRef map exported."); return xrefMapFileNameWithVersion; }
public static void UpdateHref(XRefMap map, Uri uri) { if (!string.IsNullOrEmpty(map.BaseUrl)) { Uri baseUri; if (!Uri.TryCreate(map.BaseUrl, UriKind.Absolute, out baseUri)) { throw new InvalidDataException($"Xref map file (from {uri.AbsoluteUri}) has an invalid base url: {map.BaseUrl}."); } map.UpdateHref(baseUri); return; } if (uri.Scheme == "http" || uri.Scheme == "https") { map.UpdateHref(uri); return; } throw new InvalidDataException($"Xref map file (from {uri.AbsoluteUri}) missing base url."); }
public BasicXRefMapReader(XRefMap map) { Map = map; }
private async Task <List <XRefMapRedirection> > RewriteRedirections(Uri uri, XRefArchive xa, XRefMap map) => (from list in await Task.WhenAll( from r in map.Redirections where !string.IsNullOrEmpty(r.Href) || !string.IsNullOrEmpty(r.UidPrefix) group r by r.Href into g let href = GetHrefUri(uri, g.Key) where href != null select RewriteRedirectionsCore(g.ToList(), href, xa)) from r in list orderby r.UidPrefix.Length descending, r.UidPrefix select r).ToList();
private static IEnumerable<string> GetNames(Uri uri, XRefMap map) { var name = uri.Segments.LastOrDefault(); yield return name; if (map.References?.Count > 0) { yield return map.References[0].Uid; } }
private async Task<List<XRefMapRedirection>> RewriteRedirections(Uri uri, XRefArchive xa, XRefMap map) => (from list in await Task.WhenAll( from r in map.Redirections where !string.IsNullOrEmpty(r.Href) group r by r.Href into g let href = GetHrefUri(uri, g.Key) where href != null select RewriteRedirectionsCore(g.ToList(), href, xa)) from r in list orderby (r.UidPrefix ?? string.Empty).Length descending, (r.UidPrefix ?? string.Empty) select r).ToList();
public string CreateMinor(XRefMap map, IEnumerable<string> names) { if (map == null) { throw new ArgumentNullException(nameof(map)); } if (_mode == XRefArchiveMode.Read) { throw new InvalidOperationException("Cannot create entry for readonly archive."); } if (names != null) { foreach (var name in names) { var entryName = NormalizeName(name); if (entryName != null && !HasEntryCore(entryName)) { return CreateCore(entryName, map); } } } while (true) { var entryName = Guid.NewGuid().ToString() + ".yml"; if (!HasEntryCore(entryName)) { return CreateCore(entryName, map); } } }