コード例 #1
0
        public XRefSpec GetXrefSpec(string uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            if (string.IsNullOrWhiteSpace(uid))
            {
                return(null);
            }

            if (XRefSpecMap.TryGetValue(uid, out XRefSpec xref))
            {
                return(xref);
            }

            if (ExternalXRefSpec.TryGetValue(uid, out xref))
            {
                return(xref);
            }

            if (UnknownUids.ContainsKey(uid))
            {
                return(null);
            }

            if (_reader != null)
            {
                xref = _reader.Result.Find(uid);
                if (xref != null)
                {
                    return(ExternalXRefSpec.AddOrUpdate(uid, xref, (_, old) => old + xref));
                }
            }

            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages, MaxParallelism))
                {
                    xref = GetExternalReference(externalReferences, uid);
                }
                if (xref != null)
                {
                    return(ExternalXRefSpec.AddOrUpdate(uid, xref, (_, old) => old + xref));
                }
            }

            var uidList = ResolveByXRefServiceAsync(new List <string> {
                uid
            }, ExternalXRefSpec).Result;

            if (uidList.Count == 0)
            {
                return(ExternalXRefSpec[uid]);
            }

            UnknownUids.TryAdd(uid, null);
            return(null);
        }
コード例 #2
0
        public void ResolveExternalXRefSpec()
        {
            // remove internal xref.
            var uidList =
                (from uid in XRef
                 where !XRefSpecMap.ContainsKey(uid)
                 select uid)
                .Concat(
                    from spec in ExternalXRefSpec.Values
                    where spec.Href == null
                    select spec.Uid)
                .ToList();

            if (uidList.Count > 0)
            {
                uidList = ResolveByXRefMaps(uidList, ExternalXRefSpec);
            }
            if (uidList.Count > 0)
            {
                uidList = ResolveByExternalReferencePackages(uidList, ExternalXRefSpec);
            }

            foreach (var uid in uidList)
            {
                UnknownUids.TryAdd(uid, null);
            }
        }
コード例 #3
0
        public async Task ResolveExternalXRefSpecForNoneSpecsAsync()
        {
            // remove internal xref.
            var uidList =
                (from uid in XRef
                 where !ExternalXRefSpec.ContainsKey(uid) && !XRefSpecMap.ContainsKey(uid)
                 select uid)
                .Concat(
                    from spec in ExternalXRefSpec.Values
                    where spec.Href == null && !spec.IsSpec && !XRefSpecMap.ContainsKey(spec.Uid)
                    select spec.Uid)
                .ToList();

            if (uidList.Count == 0)
            {
                return;
            }
            uidList = ResolveByXRefMaps(uidList, ExternalXRefSpec);
            if (uidList.Count > 0)
            {
                uidList = ResolveByExternalReferencePackages(uidList, ExternalXRefSpec);
            }
            if (uidList.Count > 0)
            {
                uidList = await ResolveByXRefServiceAsync(uidList, ExternalXRefSpec);
            }

            Logger.LogVerbose($"{uidList.Count} uids are unresolved.");

            foreach (var uid in uidList)
            {
                UnknownUids.TryAdd(uid, null);
            }
        }
コード例 #4
0
        public void RegisterInternalXrefSpecBookmark(string uid, string bookmark)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }
            if (uid.Length == 0)
            {
                throw new ArgumentException("Uid cannot be empty", nameof(uid));
            }
            if (bookmark == null)
            {
                throw new ArgumentNullException(nameof(bookmark));
            }
            if (bookmark.Length == 0)
            {
                return;
            }

            if (XRefSpecMap.TryGetValue(uid, out XRefSpec xref))
            {
                xref.Href = UriUtility.GetNonFragment(xref.Href) + "#" + bookmark;
            }
            else
            {
                throw new DocfxException($"Xref spec with uid {uid} not found. Can't register bookmark {bookmark} to it.");
            }
        }
コード例 #5
0
        public void RegisterInternalXrefSpecBookmark(string uid, string bookmark)
        {
            if (string.IsNullOrEmpty(uid))
            {
                throw new ArgumentNullException(nameof(uid));
            }
            if (bookmark == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }
            if (bookmark == string.Empty)
            {
                return;
            }

            XRefSpec xref;

            if (XRefSpecMap.TryGetValue(uid, out xref))
            {
                xref.Href = UriUtility.GetNonFragment(xref.Href) + "#" + bookmark;
            }
            else
            {
                throw new DocfxException($"Xref spec with uid {uid} not found. Can't register bookmark {bookmark} to it.");
            }
        }
コード例 #6
0
        public void SetExternalXRefSpec()
        {
            var result = new Dictionary <string, XRefSpec>();

            // remove internal xref.
            var xref = XRef.Where(s => !XRefSpecMap.ContainsKey(s)).ToList();

            if (xref.Count == 0)
            {
                return;
            }

            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages, MaxParallelism))
                {
                    foreach (var uid in xref)
                    {
                        var spec = GetExternalReference(externalReferences, uid);
                        if (spec != null)
                        {
                            result[uid] = spec;
                        }
                    }
                }

                Logger.LogInfo($"{result.Count} external references found in {ExternalReferencePackages.Length} packages.");
            }

            ExternalXRefSpec = result;
        }
コード例 #7
0
        public XRefSpec GetXrefSpec(string uid)
        {
            if (string.IsNullOrEmpty(uid))
            {
                throw new ArgumentNullException(nameof(uid));
            }

            XRefSpec xref;

            if (XRefSpecMap.TryGetValue(uid, out xref))
            {
                return(xref);
            }

            if (ExternalXRefSpec.TryGetValue(uid, out xref))
            {
                return(xref);
            }

            if (UnknownUids.ContainsKey(uid))
            {
                return(null);
            }

            if (XRefMaps != null && XRefMaps.Count > 0)
            {
                xref = (from map in XRefMaps select new BasicXRefMapReader(map).Find(uid)).FirstOrDefault();
                if (xref != null)
                {
                    return(ExternalXRefSpec.AddOrUpdate(uid, xref, (_, old) => old + xref));
                }
            }

            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages, MaxParallelism))
                {
                    xref = GetExternalReference(externalReferences, uid);
                }
                if (xref != null)
                {
                    return(ExternalXRefSpec.AddOrUpdate(uid, xref, (_, old) => old + xref));
                }
            }

            UnknownUids.TryAdd(uid, null);
            return(null);
        }
コード例 #8
0
ファイル: DocumentBuildContext.cs プロジェクト: srottem/docfx
        public XRefSpec GetXrefSpec(string uid)
        {
            if (string.IsNullOrEmpty(uid))
            {
                throw new ArgumentNullException(nameof(uid));
            }

            if (XRefSpecMap.TryGetValue(uid, out XRefSpec xref))
            {
                return(xref);
            }

            if (ExternalXRefSpec.TryGetValue(uid, out xref))
            {
                return(xref);
            }

            if (UnknownUids.ContainsKey(uid))
            {
                return(null);
            }

            if (_reader != null)
            {
                xref = _reader.Result.Find(uid);
                if (xref != null)
                {
                    return(ExternalXRefSpec.AddOrUpdate(uid, xref, (_, old) => old + xref));
                }
            }

            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages, MaxParallelism))
                {
                    xref = GetExternalReference(externalReferences, uid);
                }
                if (xref != null)
                {
                    return(ExternalXRefSpec.AddOrUpdate(uid, xref, (_, old) => old + xref));
                }
            }

            UnknownUids.TryAdd(uid, null);
            return(null);
        }
コード例 #9
0
        public XRefSpec GetXrefSpec(string uid)
        {
            if (string.IsNullOrEmpty(uid))
            {
                throw new ArgumentNullException(nameof(uid));
            }

            XRefSpec xref;

            if (XRefSpecMap.TryGetValue(uid, out xref))
            {
                return(xref);
            }

            if (ExternalXRefSpec.TryGetValue(uid, out xref))
            {
                return(xref);
            }

            return(null);
        }
コード例 #10
0
 // TODO: use this method instead of directly accessing UidMap
 public void RegisterInternalXrefSpec(XRefSpec xrefSpec)
 {
     if (xrefSpec == null)
     {
         throw new ArgumentNullException(nameof(xrefSpec));
     }
     if (string.IsNullOrEmpty(xrefSpec.Href))
     {
         throw new ArgumentException("Href for xref spec must contain value");
     }
     if (!PathUtility.IsRelativePath(xrefSpec.Href))
     {
         throw new ArgumentException("Only relative href path is supported");
     }
     XRefSpecMap.AddOrUpdate(
         xrefSpec.Uid,
         xrefSpec,
         (_, old) =>
     {
         Logger.LogWarning($"Uid({xrefSpec.Uid}) has already been defined in {((RelativePath)old.Href).RemoveWorkingFolder()}.",
                           code: WarningCodes.Build.DuplicateUids);
         return(FilePathComparer.OSPlatformSensitiveStringComparer.Compare(old.Href, xrefSpec.Href) > 0 ? xrefSpec : old);
     });
 }