/// <summary>
        /// Process the specified HTTP Web request
        /// </summary>
        /// <param name="context">A <see cref="System.Web.HttpContext"/> object to service the HTTP request.</param>
        public void ProcessRequest(HttpContext context)
        {
            var contextWrapper = new HttpContextWrapper(context);
            var pageContext = new WebPageContext(contextWrapper, this.Page, null);

            this.Page.ExecutePageHierarchy(pageContext, contextWrapper.Response.Output, this._startPage.Value);
        }
예제 #2
0
        public void Render(ViewContext viewContext, System.IO.TextWriter writer)
        {
            var webViewPage = DependencyResolver.Current.GetService(type) as WebViewPage;
            if (webViewPage == null)
            {
                throw new InvalidOperationException("Invalid view type");
            }

            if (!String.IsNullOrEmpty(master))
            {
                overrideLayoutSetter(webViewPage, master);
            }

            webViewPage.VirtualPath = url;
            webViewPage.ViewContext = viewContext;
            webViewPage.ViewData = viewContext.ViewData;
            webViewPage.InitHelpers();

            WebPageRenderingBase startPage = null;
            if (!this.isPartial)
            {
                startPage = StartPage.GetStartPage(webViewPage, "_ViewStart", exts);
            }

            var pageContext = new WebPageContext(viewContext.HttpContext, webViewPage, null);
            webViewPage.ExecutePageHierarchy(pageContext, writer, startPage);

        }
            private WebViewPage CreatePage(ViewContext viewContext, System.IO.TextWriter writer, out WebPageContext pageContext, out WebPageRenderingBase startPage)
            {
                var webViewPage = (WebViewPage)Activator.CreateInstance(Compiled);

                if (!string.IsNullOrEmpty(MasterPath))
                {
                    LayoutSetter(webViewPage, MasterPath);
                }

                webViewPage.VirtualPath = Path;
                webViewPage.ViewContext = viewContext;
                webViewPage.ViewData = viewContext.ViewData;
                webViewPage.InitHelpers();

                pageContext = new WebPageContext(viewContext.HttpContext, webViewPage, null);

                startPage = null;
                if (StartPageGetter != null)
                {
                    startPage = StartPageGetter(webViewPage, "_ViewStart");
                }

                var asExecuting = webViewPage as WebPageExecutingBase;

                if (asExecuting != null)
                {
                    asExecuting.VirtualPathFactory = new PrecompiledVirtualPathFactory(CompiledTypeLookup, asExecuting.VirtualPathFactory);
                }

                return webViewPage;
            }
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            object instance = Activator.CreateInstance(_type);

            WebViewPage webViewPage = instance as WebViewPage;

            if (webViewPage == null)
            {
                throw new InvalidOperationException("Invalid view type");
            }

            webViewPage.VirtualPath = _virtualPath;
            webViewPage.ViewContext = viewContext;
            webViewPage.ViewData = viewContext.ViewData;
            webViewPage.InitHelpers();

            WebPageRenderingBase startPage = null;
            if (this.RunViewStartPages)
            {
                startPage = StartPage.GetStartPage(webViewPage, "_ViewStart", ViewStartFileExtensions);
            }

            var pageContext = new WebPageContext(viewContext.HttpContext, webViewPage, null);
            webViewPage.ExecutePageHierarchy(pageContext, writer, startPage);
        }
예제 #5
0
		public void Process(ViewContext viewContext, TextWriter writer)
		{
			object view = CreateViewInstance();
			if (view == null)
			{
				throw new InvalidOperationException(string.Format(
					CultureInfo.CurrentCulture,
					"View could not be created : {0}", ViewPath));
			}

			var initPage = view as IViewPage;
			if (initPage == null)
			{
				throw new InvalidOperationException(string.Format(
					CultureInfo.CurrentCulture,
					"wrong base type for view: {0}", ViewPath));
			}

			initPage.Layout = LayoutPath;
			initPage.VirtualPath = ViewPath;
			initPage.Context = viewContext.HttpContext;
			initPage.DataContainer = viewContext.ControllerContext.Data;
			initPage.SetData(viewContext.ControllerContext.Data.MainModel ?? viewContext.ControllerContext.Data);
			//initPage.InitHelpers();

			var webPageContext = new WebPageContext(viewContext.HttpContext, (WebPageBase) initPage, initPage.GetData());

			((WebPageBase) initPage).ExecutePageHierarchy(webPageContext, writer, (WebPageBase) initPage);
		}
예제 #6
0
 public static IHtmlString ContextInfo(WebPageContext context)
 {
     var res = new StringBuilder();
     res.AppendLine("<pre style='margin:10px'>");
     res.AppendLine("WebPageContext: {0}", context.GetHashCode());
     res.AppendLine("</pre>");
     return new MvcHtmlString(res.ToString());
 }
예제 #7
0
 public override void ExecuteResult(ControllerContext context)
 {
     var types = BuildManager.GetCompiledType(VirtualPath);
     var webPage = Activator.CreateInstance(types) as WebPageBase;
     InThread(context, (ctx) =>
     {
         var pageContext = new WebPageContext(context.HttpContext, webPage, null);
         webPage.PushContext(pageContext, ctx.HttpContext.Response.Output);
         webPage.Execute();
         webPage.PopContext();
     });
 }
예제 #8
0
        public string ExecutCore(string basePath, string virtualPath, WebPageBase page)
        {
            var sb = new StringBuilder();
            using (var tw = new StringWriter(sb))
            {
                var context = new HttpContextWrapper(CreateContext(basePath, virtualPath, tw));
                var pageContext = new WebPageContext(context, page, null);
                page.PushContext(pageContext, tw);
                page.Execute();
                page.PopContext();
            }

            return sb.ToString();
        }
예제 #9
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            Type viewType = BuildManager.GetCompiledType(this.ViewPath);
            object instance = Activator.CreateInstance(viewType);
            WebViewPage page = instance as WebViewPage;

            page.VirtualPath = this.ViewPath;
            page.ViewContext = viewContext;
            page.ViewData = viewContext.ViewData;
            page.InitHelpers();

            WebPageContext pageContext = new WebPageContext(viewContext.HttpContext, null, null);
            WebPageRenderingBase startPage = StartPage.GetStartPage(page, "_ViewStart", new string[] { "cshtml", "vbhtml" });
            page.ExecutePageHierarchy(pageContext, writer, startPage);
        }
예제 #10
0
 public void Render(ViewContext viewContext, TextWriter writer)
 {
     WebViewPage webViewPage = type;
     if (webViewPage == null)
         throw new InvalidOperationException("Invalid view type");
     webViewPage.VirtualPath = virtualPath;
     webViewPage.ViewContext = viewContext;
     webViewPage.ViewData = viewContext.ViewData;
     webViewPage.InitHelpers();
     WebPageRenderingBase startPage = (WebPageRenderingBase)null;
     if (RunViewStartPages)
     {
         startPage = StartPage.GetStartPage(webViewPage, "_ViewStart", ViewStartFileExtensions);
     }
     WebPageContext pageContext = new WebPageContext(viewContext.HttpContext, webViewPage, null);
     webViewPage.ExecutePageHierarchy(pageContext, writer, startPage);
 }
        internal static WebPageContext CreateNestedPageContext <TModel>(WebPageContext parentContext, IDictionary <object, dynamic> pageData, TModel model, bool isLayoutPage)
        {
            var nestedContext = new WebPageContext
            {
                HttpContext = parentContext.HttpContext,
                OutputStack = parentContext.OutputStack,
                Validation  = parentContext.Validation,
                PageData    = pageData,
                Model       = model,
            };

            if (isLayoutPage)
            {
                nestedContext.BodyAction          = parentContext.BodyAction;
                nestedContext.SectionWritersStack = parentContext.SectionWritersStack;
            }
            return(nestedContext);
        }
예제 #12
0
        /// <summary>生成视图内容</summary>
        /// <param name="viewContext"></param>
        /// <param name="writer"></param>
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            var webViewPage = _viewPageActivator.Create(viewContext.Controller.ControllerContext, _type) as WebViewPage;
            if (webViewPage == null) throw new InvalidOperationException("无效视图类型");

            if (!String.IsNullOrEmpty(_masterPath))
            {
                _overriddenLayoutSetter.Value(webViewPage, _masterPath);
            }
            webViewPage.VirtualPath = _virtualPath;
            webViewPage.ViewContext = viewContext;
            webViewPage.ViewData = viewContext.ViewData;
            webViewPage.InitHelpers();

            WebPageRenderingBase startPage = null;
            if (RunViewStartPages) startPage = StartPage.GetStartPage(webViewPage, "_ViewStart", ViewStartFileExtensions);

            var pageContext = new WebPageContext(viewContext.HttpContext, webViewPage, null);
            webViewPage.ExecutePageHierarchy(pageContext, writer, startPage);
        }
예제 #13
0
        // This method is only used by WebPageBase to allow passing in the view context and writer.
        public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
        {
            PushContext(pageContext, writer);

            if (startPage != null)
            {
                if (startPage != this)
                {
                    var startPageContext = Util.CreateNestedPageContext <object>(parentContext: pageContext, pageData: null, model: null, isLayoutPage: false);
                    startPageContext.Page = startPage;
                    startPage.PageContext = startPageContext;
                }
                startPage.ExecutePageHierarchy();
            }
            else
            {
                ExecutePageHierarchy();
            }
            PopContext();
        }
예제 #14
0
        private WebPageContext CreatePageContextFromParameters(
            bool isLayoutPage,
            params object[] data
            )
        {
            object first = null;

            if (data != null && data.Length > 0)
            {
                first = data[0];
            }

            var pageData = PageDataDictionary <dynamic> .CreatePageDataFromParameters(PageData, data);

            return(WebPageContext.CreateNestedPageContext(
                       PageContext,
                       pageData,
                       first,
                       isLayoutPage
                       ));
        }
예제 #15
0
        public void PushContext(WebPageContext pageContext, TextWriter writer)
        {
            _currentWriter   = writer;
            PageContext      = pageContext;
            pageContext.Page = this;

            InitializePage();

            // Create a temporary writer
            _tempWriter = new StringWriter(CultureInfo.InvariantCulture);

            // Render the page into it
            OutputStack.Push(_tempWriter);
            SectionWritersStack.Push(new Dictionary <string, SectionWriter>(StringComparer.OrdinalIgnoreCase));

            // If the body is defined in the ViewData, remove it and store it on the instance
            // so that it won't affect rendering of partial pages when they call VerifyRenderedBodyOrSections
            if (PageContext.BodyAction != null)
            {
                _body = PageContext.BodyAction;
                PageContext.BodyAction = null;
            }
        }
        public static string Render(this WebViewPage view, HttpContextBase httpContext, object model = null)
        {
            StringWriter writer = new StringWriter();
            view.Initialize(httpContext, writer);
            view.ViewData.Model = model;
            WebPageContext webPageContext = new WebPageContext(view.ViewContext.HttpContext, null, model);

            // Using private reflection to access some internals
            // Also make sure the use the same writer used for initializing the ViewContext in the OutputStack
            // Note: ideally we would not have to do this, but WebPages is just not mockable enough :(

            // Add the writer to the output stack
            PropertyInfo outputStackProp = typeof(WebPageContext).GetProperty("OutputStack", BindingFlags.Instance | BindingFlags.NonPublic);
            Stack<TextWriter> outputStack = (Stack<TextWriter>)outputStackProp.GetValue(webPageContext, null);
            outputStack.Push(writer);

            // Push some section writer dictionary onto the stack. We need two, because the logic in WebPageBase.RenderBody
            // checks that as a way to make sure the layout page is not called directly
            PropertyInfo sectionWritersStackProp = typeof(WebPageContext).GetProperty("SectionWritersStack", BindingFlags.Instance | BindingFlags.NonPublic);
            Stack<Dictionary<string, SectionWriter>> sectionWritersStack = (Stack<Dictionary<string, SectionWriter>>)sectionWritersStackProp.GetValue(webPageContext, null);
            Dictionary<string, SectionWriter> sectionWriters = new Dictionary<string, SectionWriter>(StringComparer.OrdinalIgnoreCase);
            sectionWritersStack.Push(sectionWriters);
            sectionWritersStack.Push(sectionWriters);

            // Set the body delegate to do nothing
            PropertyInfo bodyActionProp = typeof(WebPageContext).GetProperty("BodyAction", BindingFlags.Instance | BindingFlags.NonPublic);
            bodyActionProp.SetValue(webPageContext, (Action<TextWriter>)(w => { }), null);

            // Set the page context on the view (the property is public, but the setter is internal)
            PropertyInfo pageContextProp = typeof(WebPageRenderingBase).GetProperty("PageContext", BindingFlags.Instance | BindingFlags.Public);
            pageContextProp.SetValue(view, webPageContext, BindingFlags.NonPublic, null, null, null);

            // Execute/render the view
            view.Execute();

            return writer.ToString();
        }
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
        public void Init(HttpApplication context)
        {
            const string errorPage = "~/Views/Shared/Error.cshtml";

            // When ever an error occurs on the Http Application, we'll now handle it, here.
            context.Error += (sender, e) =>
            {
                HttpContext.Current.ClearError();

                IWebObjectFactory webObjectFactory = BuildManager.GetObjectFactory(errorPage, true);

                WebPageBase webPageBase = webObjectFactory.CreateInstance() as WebPageBase;

                if (webPageBase == null)
                {
                    throw new InvalidOperationException("Failed to create an instance of the following page: " + errorPage);
                }

                var wrapper = new HttpContextWrapper(HttpContext.Current);
                var webPageContext = new WebPageContext(wrapper, null, null);

                webPageBase.ExecutePageHierarchy(webPageContext, HttpContext.Current.Response.Output);
            };
        }
예제 #18
0
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
 {
     this.PushContext(pageContext, writer);
       if (startPage != null)
       {
     if (startPage != this)
     {
       WebPageContext nestedPageContext = WebPageContext.CreateNestedPageContext<object>(pageContext, (IDictionary<object, object>) null, (object) null, false);
       nestedPageContext.Page = startPage;
       startPage.PageContext = nestedPageContext;
     }
     startPage.ExecutePageHierarchy();
       }
       else
     base.ExecutePageHierarchy();
       this.PopContext();
 }
예제 #19
0
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer)
 {
     WebPageBase webPageBase = this;
       WebPageRenderingBase pageRenderingBase = (WebPageRenderingBase) null;
       WebPageContext pageContext1 = pageContext;
       TextWriter writer1 = writer;
       WebPageRenderingBase startPage = pageRenderingBase;
       webPageBase.ExecutePageHierarchy(pageContext1, writer1, startPage);
 }
예제 #20
0
        public void PushContext(WebPageContext pageContext, TextWriter writer) {
            _currentWriter = writer;
            PageContext = pageContext;
            pageContext.Page = this;

            InitializePage();

            // Create a temporary writer
            _tempWriter = new StringWriter(CultureInfo.InvariantCulture);

            // Render the page into it
            OutputStack.Push(_tempWriter);
            SectionWritersStack.Push(new Dictionary<string, SectionWriter>(StringComparer.OrdinalIgnoreCase));

            // If the body is defined in the ViewData, remove it and store it on the instance
            // so that it won't affect rendering of partial pages when they call VerifyRenderedBodyOrSections
            if (PageContext.BodyAction != null) {
                _body = PageContext.BodyAction;
                PageContext.BodyAction = null;
            }
        }
예제 #21
0
        // This method is only used by WebPageBase to allow passing in the view context and writer.
        public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) {
            PushContext(pageContext, writer);

            if (startPage != null) {
                if (startPage != this) {
                    var startPageContext = Util.CreateNestedPageContext<object>(parentContext: pageContext, pageData: null, model: null, isLayoutPage: false);
                    startPageContext.Page = startPage;
                    startPage.PageContext = startPageContext;
                }
                startPage.ExecutePageHierarchy();
            }
            else {
                ExecutePageHierarchy();
            }
            PopContext();
        }
예제 #22
0
 internal static void GenerateSourceFilesHeader(WebPageContext context)
 {
     if (context.SourceFiles.Any())
     {
         var files = String.Join("|", context.SourceFiles);
         // Since the characters in the value are files that may include characters outside of the ASCII set, header encoding as specified in RFC2047. 
         // =?<charset>?<encoding>?...?= 
         // In the following case, UTF8 is used with base64 encoding 
         var encodedText = "=?UTF-8?B?" + Convert.ToBase64String(Encoding.UTF8.GetBytes(files)) + "?=";
         context.HttpContext.Response.AddHeader("X-SourceFiles", encodedText);
     }
 }
예제 #23
0
 /// <summary>
 /// Executes the code in a set of dependent web pages by using the specified parameters.
 /// </summary>
 /// <param name="pageContext">The context data for the page.</param><param name="writer">The writer to use to write the executed HTML.</param>
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer);
예제 #24
0
 private bool PrepareStartPage(WebPageContext pageContext, WebPageRenderingBase startPage)
 {
     if (startPage != null && startPage != this)
     {
         var startPageContext = WebPageContext.CreateNestedPageContext<object>(parentContext: pageContext, pageData: null, model: null, isLayoutPage: false);
         startPageContext.Page = startPage;
         startPage.PageContext = startPageContext;
         return true;
     }
     return false;
 }
예제 #25
0
 /// <summary>
 /// Inserts the specified context at the top of the <see cref="P:System.Web.WebPages.WebPageBase.OutputStack"/> instance.
 /// </summary>
 /// <param name="pageContext">The page context to push onto the <see cref="P:System.Web.WebPages.WebPageBase.OutputStack"/> instance.</param><param name="writer">The writer for the page context.</param>
 public void PushContext(WebPageContext pageContext, TextWriter writer);
예제 #26
0
 /// <summary>
 /// Executes the code in a set of dependent web pages by using the specified context, writer, and start page.
 /// </summary>
 /// <param name="pageContext">The context data for the page.</param><param name="writer">The writer to use to write the executed HTML.</param><param name="startPage">The page to start execution in the page hierarchy.</param>
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage);
        protected Task<ActionResult> AsyncView()
        {
            AsyncManager.Sync(() =>
            {
                var result = View();

                var viewEngineResult = result.ViewEngineCollection.FindView(ControllerContext, ControllerContext.RouteData.GetRequiredString("action"), result.MasterName);
                result.View = viewEngineResult.View;

                CurrentView = result.View as IView;

                // If we are profiling using MiniProfiler, unwrap the view
                if (CurrentView.GetType().FullName == "StackExchange.Profiling.MVCHelpers.ProfilingViewEngine+WrappedView")
                {
                    CurrentView = CurrentView.GetType().GetField("wrapped", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(CurrentView) as IView;
                }

                // Instantiate the view class. There are alot of internal/private reflections here
                var _buildManager = typeof(BuildManagerCompiledView).GetProperty("BuildManager", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(CurrentView, null);
                IViewPageActivator _viewPageActivator = typeof(BuildManagerCompiledView).GetField("ViewPageActivator", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(CurrentView) as IViewPageActivator;

                Type compiledType = _buildManager.GetType().GetMethod("System.Web.Mvc.IBuildManager.GetCompiledType", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_buildManager, new object[] { ((dynamic)CurrentView).ViewPath }) as Type;
                if (compiledType != null)
                {
                    Page = _viewPageActivator.Create(ControllerContext, compiledType) as WebViewPage;
                }

                // Create a new textwriter to hold the body that we flush early.
                TextWriter output = new StringWriter(CultureInfo.CurrentCulture);

                ViewContext viewContext = new ViewContext(ControllerContext, CurrentView, this.ViewData, this.TempData, output);
                Page.VirtualPath = ((dynamic)CurrentView).ViewPath;
                Page.ViewContext = viewContext;
                Page.ViewData = viewContext.ViewData;
                Page.InitHelpers();

                WebPageRenderingBase startPage = null;
                dynamic razorView = new ExposedObject(CurrentView);
                if (((dynamic)CurrentView).RunViewStartPages)
                {
                    startPage = razorView.StartPageLookup(Page, "_ViewStart", ((dynamic)CurrentView).ViewStartFileExtensions);
                }

                // ExecutePageHierarchy
                var pageContext = new WebPageContext(ControllerContext.HttpContext, null, null);
                Page.PushContext(pageContext, output);

                if (startPage != null)
                {
                    if (startPage != Page)
                    {
                        IDictionary<object, object> pageData = null;
                        object model = null;
                        bool isLayoutPage = false;
                        //WebPageContext webPageContext = WebPageContext.CreateNestedPageContext<object>(pageContext, pageData, model, isLayoutPage);
                        var method = typeof(WebPageContext).GetMethod("CreateNestedPageContext", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(new Type[] { typeof(object) });
                        WebPageContext webPageContext = method.Invoke(null, new object[] { pageContext, pageData, model, isLayoutPage }) as WebPageContext;

                        ((dynamic)new ExposedObject(webPageContext)).Page = startPage;
                        ((dynamic)new ExposedObject(startPage)).PageContext = webPageContext;
                    }
                    startPage.ExecutePageHierarchy();
                }
                else
                {
                    Page.ExecutePageHierarchy();
                }

                // Move Async Sections into a new dictionary. This prevents them being treated as standard sections and throwing required exceptions
                Dictionary<string, SectionWriter> sectionWriters = typeof(WebPageBase).GetProperty("SectionWriters", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Page, new object[] { }) as Dictionary<string, SectionWriter>;
                AsyncSections = sectionWriters.Where(x => x.Key.EndsWith("Async")).ToDictionary(x => x.Key, x => x.Value);
                foreach (var section in AsyncSections.Keys)
                {
                    sectionWriters.Remove(section);
                }

                // End ExecutePageHierarchy
                Page.PopContext(); // This actually starts the rendering but we flush as part of RenderBodyAsync

                // Keep a reference to the last part of the page after the RenderBodyAsync call, so we can send it after all async sections have been rendered
                finalWriter = Page.ViewContext.Writer;
            });

            // Wait for all the async operations to complete before returning the empty async task so that we ensure the httpcontext will always be ready for async sections to render to
            EventWaitHandle allOperationsComplete = new EventWaitHandle(false, EventResetMode.ManualReset);
            AsyncManager.OutstandingOperations.Completed += (s, ea) => { allOperationsComplete.Set(); };

            return Task.Factory.StartNew(() =>
            {
                allOperationsComplete.WaitOne();

                // Send the last part of the page after the RenderBodyAsync call if there is one
                if (finalWriter != null)
                {
                    AsyncManager.Sync(() =>
                    {
                        Page.Flush(finalWriter);
                    });
                }

                // Return an empty result because at this point, the entire page has been rendered
                return (ActionResult)null;
            });
        }
예제 #28
0
        private void RendererPage(object sender, EventArgs e)
        {
            Guid templateId = _job.Page.TemplateId;
            var renderingInfo = _renderingInfo[templateId];

            if (renderingInfo == null)
            {
                Exception loadingException = _loadingExceptions[templateId];
                if (loadingException != null)
                {
                    throw loadingException;
                }

                Verify.ThrowInvalidOperationException("Missing template '{0}'".FormatWith(templateId));
            }

            string output;
            FunctionContextContainer functionContextContainer;

            RazorPageTemplate webPage = null;
            try
            {
                webPage = WebPageBase.CreateInstanceFromVirtualPath(renderingInfo.ControlVirtualPath) as AspNet.Razor.RazorPageTemplate;
                Verify.IsNotNull(webPage, "Razor compilation failed or base type does not inherit '{0}'",
                                 typeof (AspNet.Razor.RazorPageTemplate).FullName);

                webPage.Configure();

                functionContextContainer = PageRenderer.GetPageRenderFunctionContextContainer();

                using (Profiler.Measure("Evaluating placeholders"))
                {
                    TemplateDefinitionHelper.BindPlaceholders(webPage, _job, renderingInfo.PlaceholderProperties,
                                                              functionContextContainer);
                }

                // Executing razor code
                var httpContext = new HttpContextWrapper(HttpContext.Current);
                var startPage = StartPage.GetStartPage(webPage, "_PageStart", new[] {"cshtml"});
                var pageContext = new WebPageContext(httpContext, webPage, startPage);
                pageContext.PageData.Add(RazorHelper.PageContext_FunctionContextContainer, functionContextContainer);

                var sb = new StringBuilder();
                using (var writer = new StringWriter(sb))
                {
                    using (Profiler.Measure("Executing Razor page template"))
                    {
                        webPage.ExecutePageHierarchy(pageContext, writer);
                    }
                }

                output = sb.ToString();
            }
            finally
            {
                if (webPage != null)
                {
                    webPage.Dispose();
                }
            }

            XDocument resultDocument = XDocument.Parse(output);

            var controlMapper = (IXElementToControlMapper)functionContextContainer.XEmbedableMapper;
            Control control = PageRenderer.Render(resultDocument, functionContextContainer, controlMapper, _job.Page);

            using (Profiler.Measure("ASP.NET controls: PagePreInit"))
            {
                _aspnetPage.Controls.Add(control);
            }
        }
예제 #29
0
 public Task ExecutePageHierarchyAsync(WebPageContext pageContext, TextWriter writer)
 {
     return(ExecutePageHierarchyAsync(pageContext, writer, startPage: null));
 }
예제 #30
0
 public void PushContext(WebPageContext pageContext, TextWriter writer)
 {
     this._currentWriter = writer;
       this.PageContext = pageContext;
       pageContext.Page = (WebPageRenderingBase) this;
       this.InitializePage();
       this._tempWriter = (TextWriter) new StringWriter((IFormatProvider) CultureInfo.InvariantCulture);
       this.OutputStack.Push(this._tempWriter);
       this.SectionWritersStack.Push(new Dictionary<string, SectionWriter>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase));
       if (this.PageContext.BodyAction == null)
     return;
       this._body = this.PageContext.BodyAction;
       this.PageContext.BodyAction = (Action<TextWriter>) null;
 }
예제 #31
0
 private WebPageBase PrepareRenderPage(string path, bool isLayoutPage, object[] data, out WebPageContext pageContext)
 {
     path = NormalizePath(path);
     var subPage = CreatePageFromVirtualPath(path, Context, VirtualPathFactory.Exists, DisplayModeProvider, DisplayMode);
     pageContext = CreatePageContextFromParameters(isLayoutPage, data);
     subPage.ConfigurePage(this);
     return subPage;
 }
예제 #32
0
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer)
 {
     ExecutePageHierarchy(pageContext, writer, startPage: null);
 }
            public void Render(ViewContext viewContext, TextWriter writer)
            {
                var basePage = (WebPageBase)Activator.CreateInstance(_type);
                if (basePage == null)
                {
                    throw new InvalidOperationException("Invalid view type: " + _virtualPath);
                }
                basePage.VirtualPath = _virtualPath;
                basePage.VirtualPathFactory = this;

                var startPage = _runViewStartPages
                    ? StartPage.GetStartPage(basePage, "_ViewStart", _viewEngine.FileExtensions)
                    : null;

                var webViewPage = basePage as WebViewPage;
                if (webViewPage != null)
                {
                    webViewPage.ViewContext = viewContext;
                    webViewPage.ViewData = viewContext.ViewData;
                    webViewPage.InitHelpers();
                }

                var pageContext = new WebPageContext(viewContext.HttpContext, basePage, null);
                basePage.ExecutePageHierarchy(pageContext, writer, startPage);
            }
예제 #34
0
        public async Task ExecutePageHierarchyAsync(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
        {
            PushContext(pageContext, writer);

            if (PrepareStartPage(pageContext, startPage))
            {
                await startPage.ExecutePageHierarchyAsync().ConfigureAwait(false);
            }
            else
            {
                await ExecutePageHierarchyAsync().ConfigureAwait(false);
            }
            await PopContextAsync().ConfigureAwait(false);
        }
예제 #35
0
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) {
     ExecutePageHierarchy(pageContext, writer, startPage: null);
 }
 /// <summary>
 /// Creates the specified web page context.
 /// </summary>
 /// <param name="webPageContext">The web page context.</param>
 /// <returns>JavascriptHelper</returns>
 /// <remarks>
 /// Used in @helper functions:
 /// 	var script = StateTheaterMvc.Component.JavascriptHelper.Create(WebPageContext.Current);
 /// </remarks>
 public static JavascriptHelper Create(WebPageContext webPageContext)
 {
     return  JavascriptHelper.Create(((WebViewPage)webPageContext.Page).ViewContext);
 }
예제 #37
0
        private WebPageBase PrepareRenderPage(string path, bool isLayoutPage, object[] data, out WebPageContext pageContext)
        {
            path = NormalizePath(path);
            var subPage = CreatePageFromVirtualPath(path, Context, VirtualPathFactory.Exists, DisplayModeProvider, DisplayMode);

            pageContext = CreatePageContextFromParameters(isLayoutPage, data);
            subPage.ConfigurePage(this);
            return(subPage);
        }