using System; using System.Collections.Generic; using System.Linq; using Microsoft.Practices.Prism.Modularity; // ReSharper disable once CheckNamespace namespace DTS.Common { public class AggregateModuleCatalog : IModuleCatalog { private readonly List _catalogs = new List(); /// /// Initializes a new instance of the class. /// public AggregateModuleCatalog() { _catalogs.Add(new ModuleCatalog()); } /// /// Gets the collection of catalogs. /// /// A read-only collection of catalogs. private IEnumerable Catalogs => _catalogs.AsReadOnly(); /// /// Adds the catalog to the list of catalogs /// /// The catalog to add. public void AddCatalog(IModuleCatalog catalog) { if (catalog == null) throw new ArgumentNullException($"catalog"); _catalogs.Add(catalog); } /// /// Gets all the classes that are in the . /// /// public IEnumerable Modules { get { return Catalogs.SelectMany(x => x.Modules); } } /// /// Return the list of s that depends on. /// /// The to get the . /// /// An enumeration of that depends on. /// public IEnumerable GetDependentModules(ModuleInfo moduleInfo) { var catalog = _catalogs.Single(x => x.Modules.Contains(moduleInfo)); return catalog.GetDependentModules(moduleInfo); } /// /// Returns the collection of s that contain both the s in /// , but also all the modules they depend on. /// /// The modules to get the dependencies for. /// /// A collection of that contains both all s in /// and also all the they depend on. /// public IEnumerable CompleteListWithDependencies(IEnumerable modules) { var modulesGroupedByCatalog = modules.GroupBy(module => _catalogs.Single(catalog => catalog.Modules.Contains(module))); return modulesGroupedByCatalog.SelectMany(x => x.Key.CompleteListWithDependencies(x)); } /// /// Initializes the catalog, which may load and validate the modules. /// public void Initialize() { foreach (var catalog in Catalogs) { catalog.Initialize(); } } /// /// Adds a to the . /// /// The to add. public void AddModule(ModuleInfo moduleInfo) { _catalogs[0].AddModule(moduleInfo); } } }