protected override bool TryExecute(IFileGenerator generator, GeneratorExecutionHost executionHost)
        {
            ISolution    solution   = generator.DataProvider.Solution;
            IProjectFile sourceFile = generator.DataProvider.SourceFile.ToProjectFile();

            if (!ExecutionHelpers.TryExecuteGenerator(generator, out string generatedText, out string filePath))
            {
                return(false);
            }

            bool fileCreated = TryGenerateFile(
                solution,
                sourceFile,
                filePath,
                generatedText,
                out IProjectFile generatedFile
                );

            if (!fileCreated)
            {
                return(false);
            }

            NavigateToFile(solution, generatedFile);

            return(true);
        }
        public GotoGeneratorController(
            [NotNull] Lifetime lifetime,
            [NotNull] ISolution solution,
            [NotNull] IShellLocks locks,
            [NotNull] IDataContext context,
            IMainWindowPopupWindowContext mainWindowPopupWindowContext,
            bool enableMulticore) :
            base(lifetime, solution, solution, LibrariesFlag.SolutionOnly, locks, enableMulticore, new GotoByNameModel(lifetime), mainWindowPopupWindowContext)
        {
            this.EtcItemIcon     = IdeThemedIcons.SearchResults.Id;
            this.ItemsPassFilter = new Property <Func <IOccurrence, bool> >("ItemsPassFilter", this.DefaultFilter);
            GotoByNameModelManager instance = GotoByNameModelManager.GetInstance(solution);

            instance.ProcessModel <GotoGeneratorModelInitilizer>(this.Model, lifetime, this.GetType());

            ITextControl textControl = context.GetData(TextControlDataConstants.TEXT_CONTROL);

            Debug.Assert(textControl != null, "textControl != null");

            var dataBuilder           = new CSharpContextActionDataBuilder();
            var generatorDataProvider = new GeneratorDataProvider((ICSharpContextActionDataProvider)dataBuilder.Build(solution, textControl));

            var generatorsProvider        = solution.GetComponent <GeneratorsProvider>();
            var applicableGeneratorsCache = new ApplicableGeneratorsCache(generatorsProvider, generatorDataProvider);

            this.GotoContext.PutData(ApplicableGeneratorsCacheKey, applicableGeneratorsCache);

            _executionHost = context.GetComponent <GeneratorExecutionHost>();
        }
        protected override bool TryExecute(IInPlaceGenerator generator, GeneratorExecutionHost executionHost)
        {
            IDocument document = generator.DataProvider.Document;

            bool executed = ExecutionHelpers.TryExecuteGenerator(
                generator,
                out string generatedText,
                out TextRange rangeToDelete,
                out int positionToInsert,
                out IReadOnlyCollection <IUsingDirective> missingUsingDirectives
                );

            if (!executed)
            {
                return(false);
            }

            ISolution solution = generator.DataProvider.Solution;

            using (var progressIndicator = NullProgressIndicator.Create())
            {
                IProjectModelTransactionCookie transaction =
                    solution.CreateTransactionCookie(DefaultAction.Rollback, "T4 Generating file", progressIndicator);
                using (transaction)
                {
                    if (!rangeToDelete.IsEmpty)
                    {
                        document.DeleteText(rangeToDelete);
                    }

                    document.InsertText(positionToInsert, generatedText);

                    var treeTextRange = TreeTextRange.FromLength(new TreeOffset(positionToInsert), generatedText.Length);
                    ExecutionHelpers.FormatFileRangeAndAddUsingDirectives(solution, document, treeTextRange, missingUsingDirectives);

                    transaction.Commit(progressIndicator);
                }
            }

            return(true);
        }
        protected override bool TryExecute(
            IMultipleOutputGenerator generator,
            GeneratorExecutionHost executionHost)
        {
            ISolution solution = generator.DataProvider.Solution;

            IGenerator[] generators    = null;
            bool         gotGenerators = ExecutionHelpers.TryExecuteGenerator(
                generator,
                () => generators = generator.GetGenerators().ToArray()
                );

            if (!gotGenerators)
            {
                return(false);
            }

            bool generatorsExecuted = TryExecuteGenerators(
                generators,
                out List <FileGeneratorOutput> fileGeneratorOutputs,
                out List <InPlaceGeneratorOutput> inPlaceGeneratorOutputs
                );

            if (!generatorsExecuted)
            {
                return(false);
            }

            if (!TryGenerateFiles(solution, fileGeneratorOutputs, inPlaceGeneratorOutputs))
            {
                return(false);
            }

            NavigateToFiles(solution, fileGeneratorOutputs, inPlaceGeneratorOutputs);

            return(true);
        }