[2481] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 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;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
[2517] | 25 | using System.Linq;
|
---|
[2481] | 26 |
|
---|
[2504] | 27 | namespace HeuristicLab.PluginInfrastructure.Manager {
|
---|
| 28 | internal static class PluginDescriptionIterator {
|
---|
[2517] | 29 | internal static IEnumerable<PluginDescription> IterateDependenciesBottomUp(IEnumerable<PluginDescription> pluginDescriptions) {
|
---|
[2481] | 30 | // list to make sure we yield each description only once
|
---|
[2517] | 31 | HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
|
---|
[2481] | 32 | foreach (var desc in pluginDescriptions) {
|
---|
[2517] | 33 | foreach (var dependency in IterateDependenciesBottomUp(desc.Dependencies)) {
|
---|
[2481] | 34 | if (!yieldedDescriptions.Contains(dependency)) {
|
---|
| 35 | yieldedDescriptions.Add(dependency);
|
---|
| 36 | yield return dependency;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
[2488] | 39 | if (!yieldedDescriptions.Contains(desc)) {
|
---|
| 40 | yieldedDescriptions.Add(desc);
|
---|
| 41 | yield return desc;
|
---|
| 42 | }
|
---|
[2481] | 43 | }
|
---|
| 44 | }
|
---|
[2517] | 45 |
|
---|
| 46 | internal static IEnumerable<PluginDescription> IterateDependentsTopDown(IEnumerable<PluginDescription> pluginDescriptions, IEnumerable<PluginDescription> allPlugins) {
|
---|
| 47 | HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
|
---|
| 48 | foreach (var desc in pluginDescriptions) {
|
---|
| 49 | foreach (var dependent in IterateDependentsTopDown(GetDependentPlugins(desc, allPlugins), allPlugins)) {
|
---|
| 50 | if (!yieldedDescriptions.Contains(dependent)) {
|
---|
| 51 | yieldedDescriptions.Add(dependent);
|
---|
| 52 | yield return dependent;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | if (!yieldedDescriptions.Contains(desc)) {
|
---|
| 56 | yieldedDescriptions.Add(desc);
|
---|
| 57 | yield return desc;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private static IEnumerable<PluginDescription> GetDependentPlugins(PluginDescription desc, IEnumerable<PluginDescription> allPlugins) {
|
---|
| 63 | return from plugin in allPlugins
|
---|
| 64 | where plugin.Dependencies.Contains(desc)
|
---|
| 65 | select plugin;
|
---|
| 66 | }
|
---|
[2481] | 67 | }
|
---|
| 68 | }
|
---|