Esempio n. 1
0
        private CSharpCompilation CompileViews(ViewCompilationInfo[] results, string assemblyname)
        {
            var compilation = compiler.CreateCompilation(assemblyname);
            var syntaxTrees = new SyntaxTree[results.Length];

            Parallel.For(0, results.Length, ParalellOptions, i =>
            {
                ViewCompilationInfo result = results[i];
                SourceText sourceText      = SourceText.From(result.CSharpDocument.GeneratedCode, Encoding.UTF8);

                TemplateFileInfo fileInfo = result.TemplateFileInfo;
                SyntaxTree syntaxTree     = compiler.CreateSyntaxTree(sourceText).WithFilePath(fileInfo.FullPath ?? fileInfo.ViewEnginePath);
                syntaxTrees[i]            = syntaxTree;
            });

            compilation = compilation.AddSyntaxTrees(syntaxTrees);
            compilation = ExpressionRewriter.Rewrite(compilation);

            compilation = AssemblyMetadataGenerator.AddAssemblyMetadata(
                compiler,
                compilation,
                Options);

            return(compilation);
        }
Esempio n. 2
0
        private ViewCompilationInfo[] GenerateCode()
        {
            var files   = GetFiles();
            var results = new ViewCompilationInfo[files.Count];

            //TODO: finish
            //Parallel.For(0, results.Length, ParalellOptions, i =>
            //{
            //    TemplateFileInfo fileInfo = files[i];
            //    ViewCompilationInfo compilationInfo;
            //    using (var fileStream = fileInfo.CreateReadStream())
            //    {
            //        var razorTemplate = factoryProvider.SourceGenerator.GenerateCodeAsync(fileInfo.ViewEnginePath).Result;
            //        compilationInfo = new ViewCompilationInfo(fileInfo, razorTemplate.CSharpDocument);
            //    }

            //    results[i] = compilationInfo;
            //});

            return(results);
        }