Beispiel #1
0
        public IEnumerable <string> ExpandRuntime(string runtime)
        {
            // Could this be faster? Sure! But we can refactor once it works and has tests
            yield return(runtime);

            // Try to expand the runtime based on the graph
            var deduper    = new HashSet <string>();
            var expansions = new List <string>();

            deduper.Add(runtime);
            expansions.Add(runtime);
            for (var i = 0; i < expansions.Count; i++)
            {
                // expansions.Count will keep growing as we add items, but thats OK, we want to expand until we stop getting new items
                RuntimeDescription desc;
                if (Runtimes.TryGetValue(expansions[i], out desc))
                {
                    // Add the inherited runtimes to the list
                    foreach (var inheritedRuntime in desc.InheritedRuntimes)
                    {
                        if (deduper.Add(inheritedRuntime))
                        {
                            yield return(inheritedRuntime);

                            expansions.Add(inheritedRuntime);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Find all possible dependencies for package id.
 /// </summary>
 private List <RuntimePackageDependency> FindRuntimeDependenciesInternal(RuntimeDependencyKey key)
 {
     // Find all compatible RIDs
     foreach (var expandedRuntime in ExpandRuntimeCached(key.RuntimeName))
     {
         RuntimeDescription runtimeDescription;
         if (Runtimes.TryGetValue(expandedRuntime, out runtimeDescription))
         {
             if (runtimeDescription.RuntimeDependencySets.TryGetValue(key.PackageId, out var dependencySet))
             {
                 return(dependencySet.Dependencies.Values.AsList());
             }
         }
     }
     return(new List <RuntimePackageDependency>());
 }
Beispiel #3
0
 public IEnumerable <RuntimePackageDependency> FindRuntimeDependencies(string runtimeName, string packageId)
 {
     // PERF: We could cache this for a particular (runtimeName,packageId) pair.
     foreach (var expandedRuntime in ExpandRuntime(runtimeName))
     {
         RuntimeDescription runtimeDescription;
         if (Runtimes.TryGetValue(expandedRuntime, out runtimeDescription))
         {
             RuntimeDependencySet dependencySet;
             if (runtimeDescription.RuntimeDependencySets.TryGetValue(packageId, out dependencySet))
             {
                 return(dependencySet.Dependencies.Values);
             }
         }
     }
     return(Enumerable.Empty <RuntimePackageDependency>());
 }
Beispiel #4
0
        public IEnumerable <string> ExpandRuntime(string runtime)
        {
            // Could this be faster? Sure! But we can refactor once it works and has tests
            yield return(runtime);

            // Try to expand the runtime based on the graph
            var deduper = Cache <string> .RentHashSet();

            var expansions = Cache <string> .RentList();

            deduper.Add(runtime);
            expansions.Add(runtime);
            for (var i = 0; i < expansions.Count; i++)
            {
                // expansions.Count will keep growing as we add items, but thats OK, we want to expand until we stop getting new items
                RuntimeDescription desc;
                if (Runtimes.TryGetValue(expansions[i], out desc))
                {
                    // Add the inherited runtimes to the list
                    var inheritedRuntimes = desc.InheritedRuntimes;
                    var count             = inheritedRuntimes.Count;
                    for (var r = 0; r < count; r++)
                    {
                        var inheritedRuntime = inheritedRuntimes[r];
                        if (deduper.Add(inheritedRuntime))
                        {
                            yield return(inheritedRuntime);

                            expansions.Add(inheritedRuntime);
                        }
                    }
                }
            }

            Cache <string> .ReleaseHashSet(deduper);

            Cache <string> .ReleaseList(expansions);
        }