private string BuildDependenciesAsStringFor(PackageDefinition package) { string result = string.Empty; foreach (string dependency in package.Dependencies) { PackageDefinition dependencyDefinition = Nodes.First(p => p.Package == dependency); if (dependencyDefinition.Added) continue; if (dependencyDefinition.Visited) throw new InvalidOperationException("Can't have a cycle in installation order"); dependencyDefinition.MarkAsVisited(); result += BuildDependenciesAsStringFor(dependencyDefinition) + ", "; } package.MarkAsAdded(); return result + package.Package; }
private void BuildDependenciesFor(PackageDefinition package, ref Queue<string> dependencyQueue) { foreach (string dependency in package.Dependencies) { PackageDefinition dependencyDefinition = Nodes.First(p => p.Package == dependency); if (dependencyDefinition.Added) continue; if(dependencyDefinition.Visited) throw new InvalidOperationException("Can't have a cycle in installation order"); dependencyDefinition.MarkAsVisited(); BuildDependenciesFor(dependencyDefinition,ref dependencyQueue); } dependencyQueue.Enqueue(package.Package); package.MarkAsAdded(); }