public void PopContext() { string renderedContent = _tempWriter.ToString(); OutputStack.Pop(); if (!String.IsNullOrEmpty(Layout)) { string layoutPagePath = NormalizeLayoutPagePath(Layout); Util.EnsureValidPageType(this, layoutPagePath); // If a layout file was specified, render it passing our page content OutputStack.Push(_currentWriter); RenderSurrounding( layoutPagePath, w => w.Write(renderedContent)); OutputStack.Pop(); } else { // Otherwise, just render the page _currentWriter.Write(renderedContent); } VerifyRenderedBodyOrSections(); SectionWritersStack.Pop(); }
public void PopContext() { // Using the CopyTo extension method on the _tempWriter instead of .ToString() // to avoid allocating large strings that then end up on the Large object heap. OutputStack.Pop(); if (!String.IsNullOrEmpty(Layout)) { string layoutPagePath = NormalizeLayoutPagePath(Layout); // If a layout file was specified, render it passing our page content. OutputStack.Push(_currentWriter); RenderSurrounding( layoutPagePath, _tempWriter.CopyTo); OutputStack.Pop(); } else { // Otherwise, just render the page. _tempWriter.CopyTo(_currentWriter); } VerifyRenderedBodyOrSections(); SectionWritersStack.Pop(); }
public virtual void Render(TextWriter writer) { PushContext(WebPageContext, writer); OutputStack.Push(writer); Execute(); OutputStack.Pop(); PopContext(); }
public void PopState(CommandOutput commandOutput = null) { var popped = OutputStack.Pop(); if (commandOutput == null) { OrderedOutput.Add(popped.Output); } }
public HelperResult RenderSection(string name, bool required) { EnsurePageCanBeRequestedDirectly("RenderSection"); if (PreviousSectionWriters.ContainsKey(name)) { var result = new HelperResult(tw => { if (_renderedSections.Contains(name)) { throw new HttpException(String.Format(CultureInfo.InvariantCulture, WebPageResources.WebPage_SectionAleadyRendered, name)); } var body = PreviousSectionWriters[name]; // Since the body can also call RenderSection, we need to temporarily remove // the current sections from the stack. var top = SectionWritersStack.Pop(); bool pushed = false; try { if (Output != tw) { OutputStack.Push(tw); pushed = true; } body(); } finally { if (pushed) { OutputStack.Pop(); } } SectionWritersStack.Push(top); _renderedSections.Add(name); }); return(result); } else if (required) { // If the section is not found, and it is not optional, throw an error. throw new HttpException(String.Format(CultureInfo.InvariantCulture, WebPageResources.WebPage_SectionNotDefined, name)); } else { // If the section is optional and not found, then don't do anything. return(null); } }
public void PopContext() { string renderedContent = _tempWriter.ToString(); OutputStack.Pop(); if (!String.IsNullOrEmpty(Layout)) { // If a layout file was specified, render it passing our page content OutputStack.Push(_currentWriter); RenderSurrounding( Layout, w => w.Write(renderedContent)); OutputStack.Pop(); } else { // Otherwise, just render the page _currentWriter.Write(renderedContent); } VerifyRenderedBodyOrSections(); SectionWritersStack.Pop(); }