private List<KspPartObject> FindParts (KspCraftObject craft, RegexFilter filter) { ui.DisplayUserMessage ($"Entering craft '{craft.Name}'..."); var partLookup = new PartLookup (craft); var parts = partLookup.LookupParts (filter).ToList (); ui.DisplayUserMessage ($"Found {parts.Count} matching parts"); return parts; }
public void CanLookupPartsUsingTheProvidedFilter () { // given var craft = createTestCraft (); var parts = craft.Children<KspPartObject> ().ToArray (); var target = new PartLookup (craft); // when / then Assert.That (target.LookupParts (new RegexFilter ("2")), Is.EqualTo (new[] { parts [2] })); Assert.That (target.LookupParts (new RegexFilter ("part[5-7]")), Is.EqualTo (new[] { parts [4], parts [5], parts [6] })); }
private Dictionary<KspPartObject, List<KspPartLinkProperty>> FindPartDependencies (KspCraftObject craft, RegexFilter filter) { ui.DisplayUserMessage ($"Entering craft '{craft.Name}'..."); var partLookup = new PartLookup (craft); var dependencies = partLookup.LookupParts (filter).ToList (); var dependentParts = new HashSet<KspPartObject> (); Parallel.ForEach (dependencies, dependency => { foreach (var part in partLookup.LookupSoftDependencies (dependency)) { lock (dependentParts) { dependentParts.Add (part); } } }); ui.DisplayUserMessage ($"Found {dependentParts.Count} dependent parts"); return dependentParts.ToDictionary (part => part, part => FindPartLinks (part, dependencies)); }
public void CanLookupSoftDependenciesOnAGivenPart () { // given var craft = createTestCraft (); var parts = craft.Children<KspPartObject> ().ToArray (); var dependency = parts [0]; var expectedDependencies = new[] { parts [3], // srfN to [0] parts [6], // link to [0] parts [7], // srfN to [0] parts [8], // attN to [0] }; var target = new PartLookup (craft); // when var actualDependencies = target.LookupSoftDependencies (dependency); // then Assert.That (actualDependencies, Is.EqualTo (expectedDependencies)); }
private List<KspPartObject> FindRemovedAndDependentParts (KspCraftObject craft, RegexFilter filter) { ui.DisplayUserMessage ($"Entering craft '{craft.Name}'..."); var partLookup = new PartLookup (craft); var removedParts = partLookup.LookupParts (filter).ToList (); ui.DisplayUserMessage ($"Found {removedParts.Count} parts to be removed"); var dependentParts = new HashSet<KspPartObject> (); Parallel.ForEach (removedParts, removedPart => { foreach (var part in partLookup.LookupHardDependencies (removedPart).Except (removedParts)) { lock (dependentParts) { dependentParts.Add (part); } } }); ui.DisplayUserMessage ($"Found {dependentParts.Count} dependent parts"); return removedParts.Concat (dependentParts).ToList (); }
public void CanLookupHardDependenciesOnAGivenPart () { // given var craft = createTestCraft (); var parts = craft.Children<KspPartObject> ().ToArray (); var dependency = parts [2]; var expectedDependencies = new[] { parts [1], // parent is [2] parts [5], // sym to [1] // parts [8] links do not not matter for hard-dependency check }; var target = new PartLookup (craft); // when var actualDependencies = target.LookupHardDependencies (dependency); // then Assert.That (actualDependencies, Is.EqualTo (expectedDependencies)); }