/// <summary> /// Updates the diff view with the supplied information. /// </summary> /// <param name="args"></param> /// <param name="r"></param> public void ShowDifferences(TextBinaryDiffArgs args, ProcessTextDiff r) { string captionA = string.Empty; string captionB = string.Empty; if (args.DiffType == DiffType.File) { try { this.StatusText = string.Format("{0} : {1}", Path.GetFileName(args.A), Path.GetFileName(args.B)); } catch { // System.IO throws exception on invalid file name } } else { this.StatusText = "Text Comparison"; } SetData(r.ListA, r.ListB, r.Script, args, r.IgnoreCase, r.IgnoreTextWhitespace, r.IsBinaryCompare); // Update the stats this.NumberOfLines = (uint)r.ListA.Count; this.MaxNumberOfLines = (uint)_ViewA.LineCount; int iDeletes = 0, iChanges = 0, iInserts = 0; foreach (var item in r.Script) { switch (item.EditType) { case AehnlichLib.Enums.EditType.Delete: iDeletes++; break; case AehnlichLib.Enums.EditType.Insert: iInserts++; break; case AehnlichLib.Enums.EditType.Change: iChanges++; break; case AehnlichLib.Enums.EditType.None: default: break; } } this.CountInserts = iInserts; this.CountDeletes = iDeletes; this.CountChanges = iChanges; _Args = args; }
private void CompareTextFilesCommand_Executed(string filePathA, string filePathB , bool reloadFromFile , FileContentInfo fileA, FileContentInfo fileB) { try { DiffCtrl.SetDiffViewOptions(_OptionsController.DiffDisplayOptions); var args = _OptionsController.GetTextBinaryDiffSetup(filePathA, filePathB, reloadFromFile); // Overwrite this on a document specific base (this may indicate Auto or specifc Binary, Xml, Text etc...) args.CompareType = DiffCtrl.ShouldBeComparedAs; var processDiff = new ProcessTextDiff(args); if (args.ReloadFromFile == false) { processDiff.SetupForTextComparison(fileA, fileB); } _DiffProgress.ResetProgressValues(_cancelTokenSource.Token); DiffProgress.ShowIndeterminatedProgress(); Task.Factory.StartNew <IDiffProgress>( (pr) => { return(processDiff.ProcessDiff(_DiffProgress, _DataSource)); }, TaskCreationOptions.LongRunning, _cancelTokenSource.Token) .ContinueWith((r) => { try { bool onError = false; bool taskCancelled = false; if (_cancelTokenSource != null) { // Re-create cancellation token if this task was cancelled // to support cancelable tasks in the future if (_cancelTokenSource.IsCancellationRequested) { taskCancelled = true; _cancelTokenSource.Dispose(); _cancelTokenSource = new CancellationTokenSource(); } } if (taskCancelled == false) { if (r.Result == null) { onError = true; } else { if (r.Result.ResultData == null) { onError = true; } } } if (onError == false && taskCancelled == false) { var diffResults = r.Result.ResultData as ProcessTextDiff; _DiffCtrl.ShowDifferences(args, diffResults); ////FocusControl = Focus.None; ////FocusControl = Focus.LeftView; _GotoLineController.MaxLineValue = _DiffCtrl.NumberOfLines; // Position view on first difference if thats available if (_DiffCtrl.GoToFirstDifferenceCommand.CanExecute(null)) { _DiffCtrl.GoToFirstDifferenceCommand.Execute(null); } NotifyPropertyChanged(() => DiffCtrl); } else { // Display Error } } finally { DiffProgress.ProgressDisplayOff(); } }, TaskScheduler.FromCurrentSynchronizationContext()); } catch { // Extend me with erro displays } }
private void CompareTextFilesCommand_Executed(string filePathA, string filePathB) { try { DiffCtrl.SetDiffViewOptions(_OptionsController.DiffDisplayOptions); var args = _OptionsController.GetTextBinaryDiffSetup(filePathA, filePathB); var processDiff = new ProcessTextDiff(args); _DiffProgress.ResetProgressValues(_cancelTokenSource.Token); Task.Factory.StartNew <IDiffProgress>( (pr) => processDiff.ProcessDiff(_DiffProgress), TaskCreationOptions.LongRunning, _cancelTokenSource.Token) .ContinueWith((r) => { bool onError = false; bool taskCancelled = false; if (_cancelTokenSource != null) { // Re-create cancellation token if this task was cancelled // to support cancelable tasks in the future if (_cancelTokenSource.IsCancellationRequested) { taskCancelled = true; _cancelTokenSource.Dispose(); _cancelTokenSource = new CancellationTokenSource(); } } if (taskCancelled == false) { if (r.Result == null) { onError = true; } else { if (r.Result.ResultData == null) { onError = true; } } } if (onError == false && taskCancelled == false) { var diffResults = r.Result.ResultData as ProcessTextDiff; _DiffCtrl.ShowDifferences(args, diffResults); ////FocusControl = Focus.None; ////FocusControl = Focus.LeftView; _GotoLineController.MaxLineValue = _DiffCtrl.NumberOfLines; // Position view on first difference if thats available if (_DiffCtrl.GoToFirstDifferenceCommand.CanExecute(null)) { _DiffCtrl.GoToFirstDifferenceCommand.Execute(null); } NotifyPropertyChanged(() => DiffCtrl); } else { // Display Error } }, TaskScheduler.FromCurrentSynchronizationContext()); } catch { // Extend me with erro displays } }
/// <summary> /// Sets up the left and right diff viewmodels which contain line by line information /// with reference to textual contents and whether it should be handled as insertion, /// deletion, change, or no change when comparing left side (ViewA) with right side (ViewB). /// </summary> /// <param name="args"></param> /// <param name="r"></param> private void SetData(TextBinaryDiffArgs args, ProcessTextDiff r) { _Args = args; ChangeDiffOptions changeDiffOptions = ChangeDiffOptions.None; if (r.IsComparedAs == CompareType.Binary) { changeDiffOptions |= ChangeDiffOptions.IgnoreBinaryPrefix; } else { if (r.IgnoreCase) { changeDiffOptions |= ChangeDiffOptions.IgnoreCase; } if (r.IgnoreTextWhitespace) { changeDiffOptions |= ChangeDiffOptions.IgnoreWhitespace; } } _ViewA.ChangeDiffOptions = changeDiffOptions; _ViewB.ChangeDiffOptions = changeDiffOptions; _ViewLineDiff.ChangeDiffOptions = changeDiffOptions; var factory = new LinesFactory(); factory.SetData(r.ListA, r.ListB, r.Script); _ViewA.SetData(args.A, factory.LinesA, factory.TextA , r.TextEncodingA, r.TextOriginalA, r.TextIsDirtyA, args.SpacesPerTab, r.IsComparedAs); _ViewB.SetData(args.B, factory.LinesB, factory.TextB , r.TextEncodingB, r.TextOriginalB, r.TextIsDirtyB, args.SpacesPerTab, r.IsComparedAs); NotifyPropertyChanged(() => this.IsDiffDataAvailable); this.IsComparedAs = r.IsComparedAs; Debug.Assert(IsComparedAs != CompareType.Auto, "This should always be specific (eg: Xml, Bunary, or Text)"); Debug.Assert(this._ViewA.LineCount == this._ViewB.LineCount, "Both DiffView's LineCounts must be the same"); // Sets the similarity value (0% - 100%) between 2 things shown in toolbar this.Similarity_Text = string.Format("{0:P}", r.Script.Similarity); // Show left and right file name labels over each ViewA and ViewB bool showNames = !string.IsNullOrEmpty(args.A) || !string.IsNullOrEmpty(args.B); this.edtLeft_Right_Visible = showNames; if (showNames) { this.edtLeft_Text = args.A; this.edtRight_Text = args.B; } this.currentDiffLine = -1; this.UpdateViewLineDiff(args.SpacesPerTab); // Update 2 line diff ViewLineDiff }