Ejemplo n.º 1
0
        public SearchViewModel(TreenodeViewModel root)
        {
            RootNode = root;

            searchWorker = new BackgroundWorker() {
                WorkerReportsProgress = true,
                WorkerSupportsCancellation = false
            };
            searchWorker.DoWork += new DoWorkEventHandler(SearchWorker_DoWork);
            searchWorker.ProgressChanged += new ProgressChangedEventHandler(SearchWorker_ProgressChanged);
            searchWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(searchWorker_RunWorkerCompleted);

            progressUpdateTimer.Elapsed += new ElapsedEventHandler(ProgressUpdateTimer_Elapsed);

            SearchCommand = new _SearchCommand(this);

            searchDpt = new DepthFirstSearch(TreenodeViewModel.GetTreenode(root));
            predicate = ((_SearchCommand)SearchCommand).SearchPredicate;
        }
        private void NextDifferenceCommandBinding_Executed(object sender)
        {
            if (nextDiffSearch == null) {
                TreenodeViewModel startNode = LeftFsmTree.SelectedItem ?? LeftFsmTree.RootNode;
                nextDiffSearch = new DepthFirstSearch(TreenodeViewModel.GetTreenode(startNode));

            }
            bool result = false;
            nextDiffSearch.FindNode((s) => {
                Treenode other = Treenode.NodeFromPath(s.FullPath, TreenodeViewModel.GetTreenode(RightFsmTree.RootNode));

                result = other == null || (other.DataType == DataType.ByteBlock && s.DataType == DataType.ByteBlock && other.DataAsString != s.DataAsString);

                if (result) {
                    LeftFsmTree.SelectNode(s);
                    if (other != null) {
                        RightFsmTree.SelectNode(other);

                        //try {
                        //	TextDiffTool diff = new TextDiffTool(Properties.Settings.Default.DiffToolPath);

                        //	string tmpl = Path.GetTempFileName();
                        //	string tmpr = Path.GetTempFileName();

                        //	using (StreamWriter sw = new StreamWriter(tmpl)) {
                        //		sw.WriteLine(LeftFsmTree.SelectedItem.DataAsString);
                        //		sw.Flush();
                        //	}
                        //	using (StreamWriter sw = new StreamWriter(tmpr)) {
                        //		sw.WriteLine(RightFsmTree.SelectedItem.DataAsString);
                        //		sw.Flush();
                        //	}

                        //	List<Change> changes = diff.Diff(tmpl, tmpr);
                        //} catch (Exception ex) {
                        //	MessageBox.Show("Error generating diff: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        //}
                    }
                }

                return result;
            });
            if (result == false) {
                MessageBox.Show("No more differences found", "No Differences", MessageBoxButton.OK);
                nextDiffSearch = null;
            }
        }