コード例 #1
0
            private static void ExecuteRefactoring(
                [NotNull] ITextControl textControl,
                [NotNull] ICSharpExpression expression,
                [CanBeNull] Action executeAfter = null)
            {
                const string actionId = IntroVariableAction.ACTION_ID;

                var solution = expression.GetSolution();
                var document = textControl.Document;

                var expressionRange = expression.GetDocumentRange()
                                      .TextRange;

                textControl.Selection.SetRange(expressionRange);

                var rules = DataRules
                            .AddRule(actionId, ProjectModelDataConstants.SOLUTION, solution)
                            .AddRule(actionId, DocumentModelDataConstants.DOCUMENT, document)
                            .AddRule(actionId, TextControlDataConstants.TEXT_CONTROL, textControl);

                var settingsStore       = expression.GetSettingsStoreWithEditorConfig();
                var multipleOccurrences = settingsStore.GetValue(PostfixTemplatesSettingsAccessor.SearchVarOccurrences);

                // note: uber ugly code down here
                using (var definition = Lifetime.Define(Lifetime.Eternal, actionId))
                {
                    var dataContexts = solution.GetComponent <DataContexts>();
                    var dataContext  = dataContexts.CreateWithDataRules(definition.Lifetime, rules);

                    var workflow = new IntroduceVariableWorkflow(solution, actionId);
                    RefactoringActionUtil.ExecuteRefactoring(dataContext, workflow);

                    var finishedAction = executeAfter;
                    if (finishedAction != null)
                    {
                        var currentSession = HotspotSessionExecutor.Instance.CurrentSession;
                        if (currentSession != null) // ugly hack
                        {
                            currentSession.HotspotSession.Closed.Advise(Lifetime.Eternal,
                                                                        (e) =>
                            {
                                if (e.TerminationType == TerminationType.Finished)
                                {
                                    finishedAction();
                                }
                            });
                        }
                        else
                        {
                            finishedAction();
                        }
                    }
                }
            }