InternalArrangeDependents( Module m, int rank) { // predicate required, because eventually there will be a module without a Tool, e.g. a Tool itself if (m.Tool != null) { if (null == m.Settings) { m.Requires(m.Tool); var child = m as IChildModule; if ((null == child) || (null == child.Parent)) { // children inherit the settings from their parents m.UsePublicPatches(m.Tool); } try { m.Settings = (m.Tool as ITool).CreateDefaultSettings(m); } catch (System.TypeInitializationException ex) { throw ex.InnerException; } } } if ((0 == m.Dependents.Count) && (0 == m.Requirements.Count)) { return; } if (m is IModuleGroup) { var children = m.Children; this.ApplyGroupDependenciesToChildren(children, m.Dependents); this.ApplyGroupRequirementsToChildren(children, m.Requirements); } var nextRank = rank + 1; var currentRank = this.DependencyGraph[nextRank]; foreach (var c in m.Dependents) { currentRank.Add(c); this.InternalArrangeDependents(c, nextRank); } foreach (var c in m.Requirements) { currentRank.Add(c); this.InternalArrangeDependents(c, nextRank); } }
ProcessModule( System.Collections.Generic.Dictionary <Module, int> map, System.Collections.Generic.Queue <Module> toProcess, Module module, int rankIndex) { if (module.Tool != null) { if (null == module.Settings) { module.Requires(module.Tool); var child = module as IChildModule; if ((null == child) || (null == child.Parent)) { // children inherit the settings from their parents module.UsePublicPatches(module.Tool); } try { module.Settings = (module.Tool as ITool).CreateDefaultSettings(module); } catch (System.TypeInitializationException ex) { throw ex.InnerException; } } } if ((0 == module.Dependents.Count) && (0 == module.Requirements.Count)) { return; } if (module is IModuleGroup) { var children = module.Children; this.ApplyGroupDependenciesToChildren(module, children, module.Dependents); this.ApplyGroupRequirementsToChildren(module, children, module.Requirements); } var nextRankIndex = rankIndex + 1; foreach (var dep in module.Dependents) { if (map.ContainsKey(dep)) { if (map[dep] < nextRankIndex) { MoveModuleRankTo(map, dep, nextRankIndex); } } else { SetModuleRank(map, dep, nextRankIndex); toProcess.Enqueue(dep); } } foreach (var dep in module.Requirements) { if (map.ContainsKey(dep)) { if (map[dep] < nextRankIndex) { MoveModuleRankTo(map, dep, nextRankIndex); } } else { SetModuleRank(map, dep, nextRankIndex); toProcess.Enqueue(dep); } } }