Example #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();
                        }
                    }
                }
            }
        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, ProjectModel.DataContext.DataConstants.SOLUTION, solution)
                        .AddRule(actionId, DocumentModel.DataContext.DataConstants.DOCUMENT, document)
                        .AddRule(actionId, TextControl.DataContext.DataConstants.TEXT_CONTROL, textControl);

            var settingsStore       = expression.GetSettingsStore();
            var multipleOccurrences = settingsStore.GetValue(PostfixSettingsAccessor.SearchVarOccurrences);

            var definition = Lifetimes.Define(EternalLifetime.Instance, actionId);

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

                if (multipleOccurrences && !Shell.Instance.IsTestShell)
                {
                    var introduceAction = new IntroVariableAction();
                    if (introduceAction.Update(dataContext, new ActionPresentation(), () => false))
                    {
                        introduceAction.Execute(dataContext, delegate { });

                        if (executeAfter != null)
                        {
                            SubscribeAfterExecute(executeAfter);
                        }
                    }
                }
                else
                {
                    var workflow = new IntroduceVariableWorkflow(solution, actionId);
                    WorkflowExecuter.ExecuteBatch(dataContext, workflow);

#if RESHARPER8
                    if (executeAfter != null)
                    {
                        SubscribeAfterExecute(executeAfter);
                    }
#elif RESHARPER9
                    var finishedAction = executeAfter;
                    if (finishedAction != null)
                    {
                        workflow.SuccessfullyFinished += delegate { finishedAction(); }
                    }
                    ;
#endif
                }
            }
            finally
            {
                definition.Terminate();
            }
        }
Example #3
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, ProjectModel.DataContext.DataConstants.SOLUTION, solution)
                        .AddRule(actionId, DocumentModel.DataContext.DataConstants.DOCUMENT, document)
                        .AddRule(actionId, TextControl.DataContext.DataConstants.TEXT_CONTROL, textControl);

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

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

                // todo: introduce normal way to execute refactorings with occurences search
                if (multipleOccurrences && !Shell.Instance.IsTestShell)
                {
                    var introduceAction = new IntroVariableAction();
                    if (introduceAction.Update(dataContext, new ActionPresentation(), () => false))
                    {
                        introduceAction.Execute(dataContext, delegate { });

                        if (executeAfter != null)
                        {
                            IntroduceVariableTemplate.SubscribeAfterExecute(executeAfter);
                        }
                    }
                }
                else
                {
                    var workflow = new IntroduceVariableWorkflow(solution, actionId);
                    WorkflowExecuter.ExecuteBatch(dataContext, workflow);

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