private BuildTreeViewModel Merge(BuildTreeViewModel tree1, BuildTreeViewModel tree2) { var taggedNodes = new List <BuildTreeNodeViewModel>(); TagAllNodesForDeletion(tree1, taggedNodes); foreach (var child in tree2.Children) { MergeInternal(tree1, child, taggedNodes); } RemoveTaggedNodes(tree1, taggedNodes); return(tree1); }
public async Task <BuildTreeViewModel> ProduceAsync(IBuildTree tree, BuildTreeViewModel?existingTree, IBuildTreeSortingDefinition buildTreeSortingDefinition) { var stopWatch = new Stopwatch(); stopWatch.Start(); Log.Debug().Message("Producing ViewModel for BuildTree.").Write(); var buildTreeResult = await Task.Run(() => { var groupsAsList = tree.GroupDefinition.ToList(); var sortingsAsList = buildTreeSortingDefinition.ToList(); Log.Debug().Message($"Grouping by {string.Join(",", tree.GroupDefinition)}.").Write(); var buildTree = new BuildTreeViewModel(tree); var firstLevelSorting = !buildTreeSortingDefinition.Any() ? SortingDefinition.AlphabeticalDescending : buildTreeSortingDefinition.First(); buildTree.SetSorting(firstLevelSorting); var children = CreateChildren(tree.Children, groupsAsList, sortingsAsList, 0); foreach (var childVm in children) { buildTree.Children.Add(childVm); } return(buildTree); }); if (existingTree != null) { Log.Debug().Message("Merging with existing tree.").Write(); buildTreeResult = Merge(existingTree, buildTreeResult); } var treeDepth = GetMaxDepth(buildTreeResult); Log.Debug().Message($"Setting max depths, which is {treeDepth}.").Write(); SetMaxDepths(buildTreeResult, treeDepth); SetBuildIsFromPullRequest(buildTreeResult); stopWatch.Stop(); Log.Info().Message($"Produced ViewModels for BuildTree in {stopWatch.ElapsedMilliseconds} ms. Displayed nodes: {GetNodeCount(buildTreeResult)}").Write(); return(buildTreeResult); }
public BuildTreeViewModel Produce(IBuildTree tree, BuildTreeViewModel existingTree) { var groupsAsList = tree.GroupDefinition.ToList(); var buildTree = new BuildTreeViewModel(tree); var children = CreateChildren(tree.Children, groupsAsList); foreach (var childVm in children) { buildTree.Children.Add(childVm); } if (existingTree != null) { buildTree = Merge(existingTree, buildTree); } var treeDepth = SetCurrentDepths(buildTree); SetMaxDepths(buildTree, treeDepth); return(buildTree); }