Exemplo n.º 1
0
        private async void Compare()
        {
            SuspendLayout();
            LeftPath  = cbLeftDirectory.Text;
            RightPath = cbRightDirectory.Text;
            treeView1.Nodes.Clear();

            // Directory compare
            compare = new DirectoryCompare(LeftPath, RightPath, filterExtensions);
            await compare.Parse();

            // create root noew
            treeView1.Nodes.Add(new TreeNode($"Comparison: {LeftPath} x {RightPath}", 0, 0));
            treeView1.Nodes[0].ContextMenuStrip = rootNodeMenu;

            unlisted.Clear();
            unlisted.UnionWith(compare.LeftFiles.Values);
            unlisted.UnionWith(compare.RightFiles.Values);

            // run tasks
            var tasks = MultiTask.Run(new Func <TreeNode>[]
            {
                () => { return(AddInconsistencies(new TreeNode("Left Analysis", 1, 1), compare.DuplicateLeft, compare.RefactoredLeft, compare.EmptyFilesLeft)); },
                () => { return(AddInconsistencies(new TreeNode("Right Analysis", 1, 1), compare.DuplicateRight, compare.RefactoredRight, compare.EmptyFilesRight)); },
                () => { return(AddMoved()); },
                () => { return(AddRenamed()); },
                () => { return(AddChanged()); },
                () => { return(AddRefactored()); },
                () => { return(AddUnchangedFiles()); }
            });

            Task.WaitAll(tasks);
            treeView1.BeginUpdate();
            foreach (var t in tasks)
            {
                if (t.Result.Nodes.Count > 0)
                {
                    treeView1.Nodes[0].Nodes.Add(t.Result);
                }
            }

            treeView1.Nodes[0].Nodes.Add(AddUnlisted());
            treeView1.EndUpdate();

            processTime.Stop();
            taskProgress1.Information = $"Processed in {processTime.ElapsedMilliseconds} ms";

            treeView1.Nodes[0].Expand();
            btStartRefresh.Enabled = true;
            ResumeLayout();

            var forget = Task.Run(() => { System.GC.Collect(); });
        }
Exemplo n.º 2
0
        private TreeNode AddInconsistencies(TreeNode root, CrossCompareSet duplicates, CrossCompareSet refactored, SortedSet <FileCompareData> empty)
        {
            var tasks = MultiTask.Run(new Func <TreeNode>[]
            {
                () => { return(AddDuplicates(new TreeNode("Left Duplicates", 1, 1), duplicates)); },
                () => { return(AddRefactored(new TreeNode("Left Refactored", 1, 1), refactored)); },
                () => { return(AddEmpty(new TreeNode("Left Empty", 1, 1), empty)); },
            });

            Task.WhenAll(tasks);
            foreach (var t in tasks)
            {
                var node = t.Result;
                if (node.Nodes.Count > 0)
                {
                    root.Nodes.Add(t.Result);
                }
            }

            return(root);
        }