Exemplo n.º 1
0
        public T4PreprocessingResult Preprocess(IT4File file)
        {
            Logger.Verbose("Preprocessing a file");
            var psiSourceFile   = file.PhysicalPsiSourceFile.NotNull();
            var projectFile     = psiSourceFile.ToProjectFile().NotNull();
            var solution        = file.GetSolution();
            var contextFreeTree = psiSourceFile.BuildT4Tree();
            var location        = new T4FileLocation(solution.GetComponent <ProjectModelViewHost>().GetIdByItem(projectFile));

            try
            {
                string message = T4RiderCodeGeneration.GeneratePreprocessedCode(contextFreeTree).RawText;
                solution.Locks.ExecuteOrQueueEx(solution.GetLifetime(), "T4 template preprocessing", () =>
                {
                    using (WriteLockCookie.Create())
                    {
                        TargetFileManager.SavePreprocessResults(file, message);
                    }
                });
                return(new T4PreprocessingResult(location, true, new List <T4BuildMessage>()));
            }
            catch (T4OutputGenerationException e)
            {
                var message = BuildMessageConverter.ToT4BuildMessages(e.FailureDatum.AsEnumerable());
                return(new T4PreprocessingResult(location, false, message));
            }
        }
Exemplo n.º 2
0
 private string GenerateCode([NotNull] IT4File file)
 {
     Locks.AssertReadAccessAllowed();
     return(T4RiderCodeGeneration.GenerateExecutableCode(file).RawText);
 }