public void Execute(RazorCodeDocument document)
        {
            var sourceTree = document.GetSourceTree();

            if (sourceTree == null)
            {
                throw new InvalidOperationException("Need to create the source tree");
            }

            var csharpDocument = document.GetGeneratedCSharpDocument();

            if (csharpDocument == null)
            {
                var csharpRenderers = Engine.Features.OfType <ICSharpRenderer>();
                if (!csharpRenderers.Any())
                {
                    throw new InvalidOperationException("Need to create the csharp document");
                }

                var directives           = document.GetCSharpRenderingDirectives() ?? Enumerable.Empty <IRazorDirective>();
                var rendererOrchestrator = new CSharpRendererOrchestrator(csharpRenderers, directives, _host, document.ErrorSink);
                csharpDocument = rendererOrchestrator.Render(sourceTree);

                document.SetGeneratedCSharpDocument(csharpDocument);
            }
        }
Beispiel #2
0
        public void Execute(RazorCodeDocument document)
        {
            var chunkTree = document.GetChunkTree();

            if (chunkTree == null)
            {
                throw new InvalidOperationException("Need to create the chunk tree");
            }

            var sourceTree = document.GetSourceTree();

            if (sourceTree == null)
            {
                var loweringFeature = Engine.Features.OfType <DefaultCSharpSourceLoweringFeature>().FirstOrDefault();
                if (loweringFeature == null)
                {
                    throw new InvalidOperationException("Need to create the source tree");
                }

                sourceTree = loweringFeature.Execute(document, chunkTree);
            }

            var passes = Engine.Features.OfType <ICSharpSourceTreePass>().OrderBy(p => p.Order).ToArray();

            foreach (var pass in passes)
            {
                sourceTree = pass.Execute(document, sourceTree);
            }

            document.SetSourceTree(sourceTree);
        }