Inheritance: IXRefContainer
示例#1
0
 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));
         }
     }
 }
示例#2
0
        private string CreateCore(string name, XRefMap map)
        {
            var entry = CreateEntry(name);

            using (var sw = new StreamWriter(entry.Open()))
            {
                YamlUtility.Serialize(sw, map);
            }
            return(name);
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
 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);
     }
 }
示例#6
0
 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));
 }
示例#7
0
        /// <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.");
        }
示例#8
0
 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.");
 }
示例#9
0
            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));
            }
示例#10
0
        /// <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);
        }
示例#11
0
 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);
 }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
        /// <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);
        }
示例#15
0
 public void UpdateMajor(XRefMap map) => Update(MajorFileName, map);
示例#16
0
 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;
 }
示例#17
0
 public BasicXRefMapReader(XRefMap map)
 {
     Map = map ?? throw new ArgumentNullException(nameof(map));
 }
示例#18
0
 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);
     }
 }
示例#19
0
 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);
 }
示例#20
0
 /// <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;
 }
示例#21
0
 public void UpdateMajor(XRefMap map) => Update(MajorFileName, map);
示例#22
0
 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.");
 }
示例#23
0
 public BasicXRefMapReader(XRefMap map)
 {
     Map = map;
 }
示例#24
0
 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);
 }
示例#25
0
 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();
示例#26
0
 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;
     }
 }
示例#27
0
 public BasicXRefMapReader(XRefMap map)
 {
     Map = map;
 }
示例#28
0
 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();
示例#29
0
 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);
         }
     }
 }