Exemplo n.º 1
0
        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
            }
        }
Exemplo n.º 2
0
        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
            }
        }