PackagesToRemove( Array <PackageDefinition> toRemove, Array <PackageDefinition> packageDefinitions, PackageDefinition masterDefinitionFile) { var additionalToRemove = new Array <PackageDefinition>(); foreach (var r in toRemove) { foreach (var p in packageDefinitions) { if (!p.Parents.Any()) { // immediately ignore any packages that have no parents // as these are scheduled to be deleted // avoids a possible infinite recursion into PackagesToRemove continue; } if (p.Parents.Contains(r)) { p.Parents.Remove(r); } if (0 == p.Parents.Count() && p != masterDefinitionFile && !toRemove.Contains(p)) { additionalToRemove.AddUnique(p); } } } if (additionalToRemove.Count() > 0) { // recurse additionalToRemove.AddRangeUnique(PackagesToRemove(additionalToRemove, packageDefinitions, masterDefinitionFile)); } return(additionalToRemove); }
PackagesToRemove( Array <PackageDefinition> toRemove, Array <PackageDefinition> packageDefinitions, PackageDefinition masterDefinitionFile) { var additionalToRemove = new Array <PackageDefinition>(); foreach (var r in toRemove) { foreach (var p in packageDefinitions) { if (p.Parents.Contains(r)) { p.Parents.Remove(r); } if (0 == p.Parents.Count() && p != masterDefinitionFile && !toRemove.Contains(p)) { additionalToRemove.AddUnique(p); } } } if (additionalToRemove.Count() > 0) { // recurse additionalToRemove.AddRangeUnique(PackagesToRemove(additionalToRemove, packageDefinitions, masterDefinitionFile)); } return(additionalToRemove); }
FindPackagesToRemove( Array <PackageDefinition> initialToRemove, Array <PackageDefinition> packageDefinitions, PackageDefinition masterDefinitionFile) { var totalToRemove = new Array <PackageDefinition>(initialToRemove); var queuedForRemoval = new System.Collections.Generic.Queue <PackageDefinition>(initialToRemove); while (queuedForRemoval.Count > 0) { var current = queuedForRemoval.Dequeue(); totalToRemove.AddUnique(current); Log.DebugMessage("Examining: {0}", current.ToString()); foreach (var package in packageDefinitions) { if (package.Parents.Contains(current)) { Log.DebugMessage("Package {0} parents include {1}, so removing reference", package.ToString(), current.ToString()); package.Parents.Remove(current); } if (!package.Parents.Any() && package != masterDefinitionFile && !totalToRemove.Contains(package) && !queuedForRemoval.Contains(package)) { Log.DebugMessage("*** Package {0} enqueued for removal since no-one refers to it", package.ToString()); queuedForRemoval.Enqueue(package); } } } return(totalToRemove); }