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);
        }
Exemple #2
0
        private List <string> ResolveByExternalReferencePackages(List <string> uidList, ConcurrentDictionary <string, XRefSpec> externalXRefSpec)
        {
            if (ExternalReferencePackages.Length == 0)
            {
                return(uidList);
            }

            var oldSpecCount = externalXRefSpec.Count;
            var list         = new List <string>();

            using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages, MaxParallelism))
            {
                foreach (var uid in uidList)
                {
                    var spec = GetExternalReference(externalReferences, uid);
                    if (spec != null)
                    {
                        externalXRefSpec.AddOrUpdate(uid, spec, (_, old) => old + spec);
                    }
                    else
                    {
                        list.Add(uid);
                    }
                }
            }

            Logger.LogInfo($"{externalXRefSpec.Count - oldSpecCount} external references found in {ExternalReferencePackages.Length} packages.");
            return(list);
        }
        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;
        }
        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))
                {
                    foreach (var uid in xref)
                    {
                        var spec = GetExternalReference(externalReferences, uid);
                        if (spec != null)
                        {
                            result[uid] = spec;
                        }
                    }
                }
            }

            ExternalXRefSpec = result;
        }
Exemple #5
0
 private static XRefSpec GetExternalReference(ExternalReferencePackageCollection externalReferences, string uid)
 {
     if (!externalReferences.TryGetReference(uid, out ReferenceViewModel vm))
     {
         return(null);
     }
     return(YamlUtility.ConvertTo <XRefSpec>(vm));
 }
Exemple #6
0
        public void SetExternalXRefSpec()
        {
            var result = new Dictionary <string, XRefSpec>();

            // remove internal xref.
            var xref = XRef.Where(s => !UidMap.ContainsKey(s.Key)).ToDictionary(s => s.Key, s => s.Value);

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

            var missingUids = new List <KeyValuePair <string, HashSet <string> > >();

            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages))
                {
                    foreach (var uid in xref.Keys)
                    {
                        var spec = GetExternalReference(externalReferences, uid);
                        if (spec != null)
                        {
                            result[uid] = spec;
                        }
                        else
                        {
                            if (missingUids.Count < 100)
                            {
                                missingUids.Add(new KeyValuePair <string, HashSet <string> >(uid, xref[uid]));
                            }
                        }
                    }
                }
            }
            else
            {
                missingUids.AddRange(xref.Take(100));
            }
            if (missingUids.Count > 0)
            {
                var uidLines = string.Join(Environment.NewLine + "\t", missingUids.Select(s => "@" + s.Key + " in files \"" + string.Join(",", s.Value.Select(p => p.ToDisplayPath())) + "\""));
                if (missingUids.Count < 100)
                {
                    Logger.LogWarning($"Missing following definitions of cross-reference:{Environment.NewLine}\t{uidLines}");
                }
                else
                {
                    Logger.LogWarning($"Too many missing definitions of cross-reference, following is top 100:{Environment.NewLine}\t{uidLines}");
                }
            }
            ExternalXRefSpec = result;
        }
        private Dictionary <string, XRefSpec> GetExternalXRefSpec()
        {
            var result = new Dictionary <string, XRefSpec>();

            // remove internal xref.
            XRef.ExceptWith(UidMap.Keys);

            if (XRef.Count == 0)
            {
                return(result);
            }

            var missingUids = new List <string>();

            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages))
                {
                    foreach (var uid in XRef)
                    {
                        var spec = GetExternalReference(externalReferences, uid);
                        if (spec != null)
                        {
                            result[uid] = spec;
                        }
                        else
                        {
                            if (missingUids.Count < 100)
                            {
                                missingUids.Add(uid);
                            }
                        }
                    }
                }
            }
            else
            {
                missingUids.AddRange(XRef.Take(100));
            }
            if (missingUids.Count > 0)
            {
                var uidLines = string.Join(Environment.NewLine + "\t", missingUids);
                if (missingUids.Count < 100)
                {
                    Logger.LogWarning($"Missing following definitions of xref:{Environment.NewLine}{uidLines}.");
                }
                else
                {
                    Logger.LogWarning($"Too many missing definitions of xref, following is top 100:{Environment.NewLine}{uidLines}.");
                }
            }
            return(result);
        }
        public void SetExternalXRefSpec()
        {
            var result = new Dictionary<string, XRefSpec>();

            // remove internal xref.
            var xref = XRef.Where(s => !UidMap.ContainsKey(s.Key)).ToDictionary(s => s.Key, s => s.Value);

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

            var missingUids = new List<KeyValuePair<string, HashSet<string>>>();
            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages))
                {
                    foreach (var uid in xref.Keys)
                    {
                        var spec = GetExternalReference(externalReferences, uid);
                        if (spec != null)
                        {
                            result[uid] = spec;
                        }
                        else
                        {
                            if (missingUids.Count < 100)
                            {
                                missingUids.Add(new KeyValuePair<string, HashSet<string>>(uid, xref[uid]));
                            }
                        }
                    }
                }
            }
            else
            {
                missingUids.AddRange(xref.Take(100));
            }
            if (missingUids.Count > 0)
            {
                var uidLines = string.Join(Environment.NewLine + "\t", missingUids.Select(s => "@" + s.Key + " in files \"" + string.Join(",", s.Value.Select(p => p.ToDisplayPath())) + "\""));
                if (missingUids.Count < 100)
                {
                    Logger.LogWarning($"Missing following definitions of cross-reference:{Environment.NewLine}\t{uidLines}");
                }
                else
                {
                    Logger.LogWarning($"Too many missing definitions of cross-reference, following is top 100:{Environment.NewLine}\t{uidLines}");
                }
            }
            ExternalXRefSpec = result;
        }
Exemple #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);
            }

            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);
        }
Exemple #10
0
        private static XRefSpec GetExternalReference(ExternalReferencePackageCollection externalReferences, string uid)
        {
            ReferenceViewModel vm;

            if (!externalReferences.TryGetReference(uid, out vm))
            {
                return(null);
            }
            using (var sw = new StringWriter())
            {
                YamlUtility.Serialize(sw, vm);
                using (var sr = new StringReader(sw.ToString()))
                {
                    return(YamlUtility.Deserialize <XRefSpec>(sr));
                }
            }
        }
Exemple #11
0
        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);
        }
Exemple #12
0
 private static XRefSpec GetExternalReference(ExternalReferencePackageCollection externalReferences, string uid)
 {
     ReferenceViewModel vm;
     if (!externalReferences.TryGetReference(uid, out vm))
     {
         return null;
     }
     return YamlUtility.ConvertTo<XRefSpec>(vm);
 }
Exemple #13
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;
        }
Exemple #14
0
        private List<string> ResolveByExternalReferencePackages(List<string> uidList, ConcurrentDictionary<string, XRefSpec> externalXRefSpec)
        {
            if (ExternalReferencePackages.Length == 0)
            {
                return uidList;
            }

            var oldSpecCount = externalXRefSpec.Count;
            var list = new List<string>();
            using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages, MaxParallelism))
            {
                foreach (var uid in uidList)
                {
                    var spec = GetExternalReference(externalReferences, uid);
                    if (spec != null)
                    {
                        externalXRefSpec.AddOrUpdate(uid, spec, (_, old) => old + spec);
                    }
                    else
                    {
                        list.Add(uid);
                    }
                }
            }

            Logger.LogInfo($"{externalXRefSpec.Count - oldSpecCount} external references found in {ExternalReferencePackages.Length} packages.");
            return list;
        }
        private Dictionary<string, XRefSpec> GetExternalXRefSpec()
        {
            var result = new Dictionary<string, XRefSpec>();

            // remove internal xref.
            XRef.ExceptWith(UidMap.Keys);

            if (XRef.Count == 0)
            {
                return result;
            }

            var missingUids = new List<string>();
            if (ExternalReferencePackages.Length > 0)
            {
                using (var externalReferences = new ExternalReferencePackageCollection(ExternalReferencePackages))
                {
                    foreach (var uid in XRef)
                    {
                        var spec = GetExternalReference(externalReferences, uid);
                        if (spec != null)
                        {
                            result[uid] = spec;
                        }
                        else
                        {
                            if (missingUids.Count < 100)
                            {
                                missingUids.Add(uid);
                            }
                        }
                    }
                }
            }
            else
            {
                missingUids.AddRange(XRef.Take(100));
            }
            if (missingUids.Count > 0)
            {
                var uidLines = string.Join(Environment.NewLine + "\t", missingUids);
                if (missingUids.Count < 100)
                {
                    Logger.LogWarning($"Missing following definitions of xref:{Environment.NewLine}{uidLines}.");
                }
                else
                {
                    Logger.LogWarning($"Too many missing definitions of xref, following is top 100:{Environment.NewLine}{uidLines}.");
                }
            }
            return result;
        }
 private static XRefSpec GetExternalReference(ExternalReferencePackageCollection externalReferences, string uid)
 {
     ReferenceViewModel vm;
     if (!externalReferences.TryGetReference(uid, out vm))
     {
         return null;
     }
     using (var sw = new StringWriter())
     {
         YamlUtility.Serialize(sw, vm);
         using (var sr = new StringReader(sw.ToString()))
         {
             return YamlUtility.Deserialize<XRefSpec>(sr);
         }
     }
 }