[2481] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2481] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
[2517] | 23 | using System.Linq;
|
---|
[2481] | 24 |
|
---|
[2504] | 25 | namespace HeuristicLab.PluginInfrastructure.Manager {
|
---|
| 26 | internal static class PluginDescriptionIterator {
|
---|
[2517] | 27 | internal static IEnumerable<PluginDescription> IterateDependenciesBottomUp(IEnumerable<PluginDescription> pluginDescriptions) {
|
---|
[2481] | 28 | // list to make sure we yield each description only once
|
---|
[2517] | 29 | HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
|
---|
[2481] | 30 | foreach (var desc in pluginDescriptions) {
|
---|
[2517] | 31 | foreach (var dependency in IterateDependenciesBottomUp(desc.Dependencies)) {
|
---|
[2481] | 32 | if (!yieldedDescriptions.Contains(dependency)) {
|
---|
| 33 | yieldedDescriptions.Add(dependency);
|
---|
| 34 | yield return dependency;
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
[2488] | 37 | if (!yieldedDescriptions.Contains(desc)) {
|
---|
| 38 | yieldedDescriptions.Add(desc);
|
---|
| 39 | yield return desc;
|
---|
| 40 | }
|
---|
[2481] | 41 | }
|
---|
| 42 | }
|
---|
[2517] | 43 |
|
---|
| 44 | internal static IEnumerable<PluginDescription> IterateDependentsTopDown(IEnumerable<PluginDescription> pluginDescriptions, IEnumerable<PluginDescription> allPlugins) {
|
---|
| 45 | HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
|
---|
| 46 | foreach (var desc in pluginDescriptions) {
|
---|
| 47 | foreach (var dependent in IterateDependentsTopDown(GetDependentPlugins(desc, allPlugins), allPlugins)) {
|
---|
| 48 | if (!yieldedDescriptions.Contains(dependent)) {
|
---|
| 49 | yieldedDescriptions.Add(dependent);
|
---|
| 50 | yield return dependent;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | if (!yieldedDescriptions.Contains(desc)) {
|
---|
| 54 | yieldedDescriptions.Add(desc);
|
---|
| 55 | yield return desc;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | private static IEnumerable<PluginDescription> GetDependentPlugins(PluginDescription desc, IEnumerable<PluginDescription> allPlugins) {
|
---|
| 61 | return from plugin in allPlugins
|
---|
| 62 | where plugin.Dependencies.Contains(desc)
|
---|
| 63 | select plugin;
|
---|
| 64 | }
|
---|
[2481] | 65 | }
|
---|
| 66 | }
|
---|