示例#1
0
            async Task <PackageAssembly> TryResolveInDependencyAsync(
                AssemblyNameReference name,
                PackageDependency dep,
                ConcurrentDictionary <string, bool> searchedPackages,
                ConcurrentQueue <PackageAssembly> found)
            {
                if (found.Count > 0)
                {
                    return(null);
                }

                var lowerPackageId = dep.PackageId.ToLowerInvariant();

                if (!searchedPackages.TryAdd(lowerPackageId, true))
                {
                    return(null);
                }

                try {
                    var package = await PackageData.GetAsync(dep.PackageId, dep.VersionSpec, httpClient, CancellationToken.None).ConfigureAwait(false);

                    if (found.Count > 0)
                    {
                        return(null);
                    }
                    var fw = package.FindClosestTargetFramework(packageTargetFramework.Moniker);
                    if (fw != null)
                    {
                        var r = await TryResolveInFrameworkAsync(name, fw, searchedPackages, found).ConfigureAwait(false);

                        if (r != null)
                        {
                            found.Enqueue(r);
                        }
                        return(r);
                    }
                }
                catch (Exception ex) {
                    Debug.WriteLine(ex);
                }
                return(null);
            }
示例#2
0
        void ReadNuspec(Entry entry)
        {
            using (var stream = entry.Open()) {
                var xdoc = XDocument.Load(stream);
                var ns   = xdoc.Root.Name.Namespace;
                var meta = xdoc.Root.Elements().FirstOrDefault(x => x.Name.LocalName == "metadata");
                if (meta == null)
                {
                    throw new Exception("Failed to find metadata in " + xdoc);
                }
                string GetS(string name, string def = "")
                {
                    try { return(meta.Element(ns + name).Value.Trim()); }
                    catch { return(def); }
                }

                string GetUrl(string name)
                {
                    var u = GetS(name);

                    if (!u.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                    {
                        return("");
                    }
                    if (u.ToLowerInvariant().Contains("_url_here_or_delete"))
                    {
                        return("");
                    }
                    return(u);
                }

                NuspecXml  = xdoc.ToString(SaveOptions.OmitDuplicateNamespaces);
                Id         = GetS("id", IndexId);
                Authors    = GetS("authors");
                Owners     = GetS("owners");
                ProjectUrl = GetUrl("projectUrl");
                LicenseUrl = GetUrl("licenseUrl");
                if (LicenseUrl == ProjectUrl)
                {
                    LicenseUrl = "";
                }
                IconUrl     = GetUrl("iconUrl");
                Description = GetS("description");
                var repo = meta.Element(ns + "repository");
                if (repo != null)
                {
                    RepositoryType   = repo.Attribute("type")?.Value ?? "";
                    RepositoryUrl    = repo.Attribute("url")?.Value ?? "";
                    RepositoryCommit = repo.Attribute("commit")?.Value ?? "";
                }
                var deps = meta.Element(ns + "dependencies");
                if (deps != null)
                {
                    // System.Console.WriteLine(deps);
                    foreach (var de in deps.Elements())
                    {
                        if (de.Name.LocalName == "group")
                        {
                            var tfa = de.Attribute("targetFramework");
                            if (tfa != null)
                            {
                                var tfName = tfa.Value;
                                var tf     = FindExactTargetFramework(TargetFrameworkNameToMoniker(tfName));
                                if (tf != null)
                                {
                                    foreach (var ge in de.Elements(ns + "dependency"))
                                    {
                                        var dep = new PackageDependency(ge);
                                        tf.AddDependency(dep);
                                    }
                                }
                            }
                        }
                        else if (de.Name.LocalName == "dependency")
                        {
                            var dep = new PackageDependency(de);
                            foreach (var tf in TargetFrameworks)
                            {
                                tf.AddDependency(dep);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
            async Task <PackageAssembly> TryResolveInDependencyAsync(AssemblyNameReference name, PackageDependency dep, ConcurrentDictionary <string, bool> searchedPackages, CancellationTokenSource cts)
            {
                var lowerPackageId = dep.PackageId.ToLowerInvariant();

                if (searchedPackages.ContainsKey(lowerPackageId))
                {
                    return(null);
                }
                searchedPackages.TryAdd(lowerPackageId, true);

                try {
                    var package = await PackageData.GetAsync(dep.PackageId, dep.VersionSpec, cts.Token).ConfigureAwait(false);

                    if (cts.Token.IsCancellationRequested)
                    {
                        return(null);
                    }
                    var fw = package.FindClosestTargetFramework(packageTargetFramework.Moniker);
                    if (fw != null)
                    {
                        return(await TryResolveInFrameworkAsync(name, fw, searchedPackages, cts).ConfigureAwait(false));
                    }
                }
                catch {}
                return(null);
            }