-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathPrecompilationView.cs
More file actions
65 lines (55 loc) · 2.34 KB
/
PrecompilationView.cs
File metadata and controls
65 lines (55 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Web.Mvc;
using System.Web.WebPages;
namespace StackExchange.Precompilation
{
internal class PrecompilationView : IView
{
private readonly string _virtualPath;
private readonly string _masterPath;
private readonly Type _viewType;
private readonly ProfiledVirtualPathProviderViewEngine _viewEngine;
private readonly bool _runViewStart;
public PrecompilationView(string virtualPath, string masterPath, Type viewType, bool runViewStart, ProfiledVirtualPathProviderViewEngine viewEngine)
{
_virtualPath = virtualPath;
_masterPath = masterPath;
_viewType = viewType;
_runViewStart = runViewStart;
_viewEngine = viewEngine;
}
private WebPageBase CreatePage(ViewContext viewContext, System.IO.TextWriter writer, out WebPageContext pageContext, out WebPageRenderingBase startPage)
{
var basePage = (WebPageBase)Activator.CreateInstance(_viewType);
basePage.VirtualPath = _virtualPath;
basePage.VirtualPathFactory = _viewEngine.VirtualPathFactory;
pageContext = new WebPageContext(viewContext.HttpContext, basePage, viewContext.ViewData?.Model);
startPage = _runViewStart
? StartPage.GetStartPage(basePage, "_ViewStart", _viewEngine.FileExtensions)
: null;
var viewPage = basePage as WebViewPage;
if (viewPage != null)
{
if (!string.IsNullOrEmpty(_masterPath))
{
Hacks.SetOverriddenLayoutPath(viewPage, _masterPath);
}
viewPage.ViewContext = viewContext;
viewPage.ViewData = viewContext.ViewData;
viewPage.InitHelpers();
}
return basePage;
}
public void Render(ViewContext viewContext, System.IO.TextWriter writer)
{
using (_viewEngine.DoProfileStep("Render"))
{
var webViewPage = CreatePage(viewContext, writer, out var pageContext, out var startPage);
using (_viewEngine.DoProfileStep("ExecutePageHierarchy"))
{
webViewPage.ExecutePageHierarchy(pageContext, writer, startPage);
}
}
}
}
}