private void CompareDirectories() { Debug.Print("------ CompareDirectories"); ProgressPanel.Visibility = Visibility.Hidden; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); ViewModel.Clear(); ViewModel.GuiFrozen = true; ProgressBarCompare.Value = 0; ProgressBarCompare.Maximum = 'Z' - 'A'; string leftPath = ViewModel.LeftPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); string rightPath = ViewModel.RightPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); BackgroundCompare.progressHandler = new Progress <int>(CompareStatusUpdate); Task.Run(() => BackgroundCompare.CompareDirectories(leftPath, rightPath)).ContinueWith(CompareDirectoriesFinnished, TaskScheduler.FromCurrentSynchronizationContext()); progressTimer.Start(); }
private void CommandCancelCompare_Executed(object sender, ExecutedRoutedEventArgs e) { BackgroundCompare.Cancel(); }
private void CompareFiles() { Debug.Print("------ CompareFiles"); string leftPath = ""; string rightPath = ""; ProgressPanel.Visibility = Visibility.Hidden; if (ViewModel.Mode == CompareMode.File) { leftPath = ViewModel.LeftPath; rightPath = ViewModel.RightPath; } else if (ViewModel.MasterDetail && LeftFolder.SelectedFile != null && RightFolder.SelectedFile != null) { leftPath = LeftFolder.SelectedFile.Path; rightPath = RightFolder.SelectedFile.Path; } List <Line> leftLines = null; List <Line> rightLines = null; ViewModel.LeftFileEncoding = null; ViewModel.RightFileEncoding = null; try { if (File.Exists(leftPath)) { leftLines = new List <Line>(); leftSelection = leftPath; ViewModel.LeftFileEncoding = Unicode.GetEncoding(leftPath); ViewModel.LeftFileDirty = false; int i = 0; foreach (string s in File.ReadAllLines(leftPath, ViewModel.LeftFileEncoding.Type)) { leftLines.Add(new Line() { Type = TextState.Deleted, Text = s, LineIndex = i++ }); } } if (File.Exists(rightPath)) { rightLines = new List <Line>(); rightSelection = rightPath; ViewModel.RightFileEncoding = Unicode.GetEncoding(rightPath); ViewModel.RightFileDirty = false; int i = 0; foreach (string s in File.ReadAllLines(rightPath, ViewModel.RightFileEncoding.Type)) { rightLines.Add(new Line() { Type = TextState.New, Text = s, LineIndex = i++ }); } } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (leftLines?.Count > 0 && rightLines?.Count > 0) { ViewModel.GuiFrozen = true; ProgressBarCompare.Value = 0; ProgressBarCompare.Maximum = leftLines.Count + rightLines.Count; BackgroundCompare.progressHandler = new Progress <int>(CompareStatusUpdate); Task.Run(() => BackgroundCompare.CompareFiles(leftLines, rightLines)).ContinueWith(CompareFilesFinnished, TaskScheduler.FromCurrentSynchronizationContext()); progressTimer.Start(); } else { ViewModel.LeftFile = leftLines == null ? new ObservableCollection <Line>() : new ObservableCollection <Line>(leftLines); ViewModel.RightFile = rightLines == null ? new ObservableCollection <Line>() : new ObservableCollection <Line>(rightLines); InitNavigationState(); } }