/// <summary> /// Show error message. /// </summary> /// <param name="errorMessage">Message to show</param> protected void OnError(string errorMessage) { ErrorOccurred = true; CommonVsUtilities.ShowMessageBoxEx( Resources.ErrorDialog_Title, errorMessage, MessageBoxButtons.OK, MessageBoxDefaultButton.Button1, MessageBoxIcon.Error); }
/// <summary> /// The DoOperation method begins the entire refactoring process. /// The launch point for the refactoring operation must call this method. /// overall flow /// 1) UI flows input into an instance of a derivation of this class ... (ctor) /// 2) The class may present its own UI (cancel) /// 3) It creates an ContributorInput object /// 4) Feeds it to the manager (or base class, depending on how you look at it) /// 5) Proposals returned /// 6) Merge proposals /// 7) Preview UI (optional)kind /// 8) Apply changes (or cancel or fail) /// </summary> public void DoOperation() { try { // If we don't have a ContributorInput yet, call OnGetContributorInput method to get ContributorInput for this operation. if (ContributorInput == null) { ContributorInput = OnGetContributorInput(); } if (ErrorOccurred || IsCancelled) { return; } if (ContributorInput == null) { // If not cancelled and contributorInput is null, throw exception. throw new InvalidOperationException(); } // Collect the list of files to change FileChanges = GetFileChanges(); using (var cursor = WaitCursorHelper.NewWaitCursor()) { if (HasPreviewWindow) { // Log names of files with error to event log OnBeforeShowPreviewWindow(); if (ErrorOccurred || IsCancelled) { return; } if (PreviewData.ChangeList == null || PreviewData.ChangeList.Count == 0) { if (System.Windows.MessageBox.Show( Resources.RefactoringOperation_NoChangesToPreview, Resources.RefactoringOperation_NoChangesToPreviewTitle, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { ApplyChanges(); } } else { // After feed the preview window with PreviewChangesEngine, the engine will call back the ApplyChanges // method in this Operation if user clicks Apply button. ShowPreviewWindow(); } } else { // If no preview needed, apply the changes. ApplyChanges(); } } if (ErrorOccurred || IsCancelled) { return; } } catch (InvalidOperationException ex) { OnError(string.Format(CultureInfo.CurrentCulture, Resources.Error_FailedOperation, ex.Message)); } catch (OperationCanceledException ex) { var errorMessage = ex.Message; if (string.IsNullOrEmpty(errorMessage)) { errorMessage = Resources.Dialog_CancelRefactoring; } CancelOperation(); CommonVsUtilities.ShowMessageBoxEx( Resources.RefactorDialog_Title, errorMessage, MessageBoxButtons.OK, MessageBoxDefaultButton.Button1, MessageBoxIcon.Error); } finally { UnregisterEvents(); } }