Example #1
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 void Print(string message, CommandState?state = null)
        {
            var messages = OutputStack.Peek();
            var process  = state ?? State;

            message = message.Capitalize();

            switch (process)
            {
            case CommandState.Before:
                messages.BeforeOutput.Add(IsMulti ? $"{Noun.Name}: {message}" : message);
                break;

            case CommandState.During:
                messages.DuringOutput.Add(IsMulti ? $"{Noun.Name}: {message}" : message);
                break;

            case CommandState.After:
                messages.DuringOutput.Clear();
                messages.AfterOutput.Add(message);
                break;
            }
        }
Example #3
0
        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();
        }
Example #4
0
        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();
        }
Example #5
0
 void PrintLog(int Rule)
 {
     OutputStack.Push(WorkStack.Pop());
     Log += '\n' + "M (" + OutputStack.Peek() + "," + input[Counter] + ") = " + Convert.ToString(Rule);
 }
Example #6
0
 /// <summary>
 /// Constructor for the <c>NodeWriter</c> object. This will
 /// create the object that is used to control an output elements
 /// access to the generated XML document. This keeps a stack of
 /// active and uncommitted elements.
 /// </summary>
 /// <param name="result">
 /// this is the output for the resulting document
 /// </param>
 /// <param name="format">
 /// this is used to format the generated document
 /// </param>
 /// <param name="verbose">
 /// this determines if we expand the namespaces
 /// </param>
 private NodeWriter(Writer result, Format format, bool verbose) {
    this.writer = new Formatter(result, format);
    this.active = new HashSet();
    this.stack = new OutputStack(active);
    this.verbose = verbose;
 }
Example #7
0
 /// <summary>
 /// Constructor for the <c>OutputDocument</c> object. This
 /// is used to create an empty output node object that can be
 /// used to create a root element for the generated document.
 /// </summary>
 /// <param name="writer">
 /// this is the node writer to write the node to
 /// </param>
 /// <param name="stack">
 /// this is the stack that contains the open nodes
 /// </param>
 public OutputDocument(NodeWriter writer, OutputStack stack) {
    this.table = new OutputNodeMap(this);
    this.mode = Mode.INHERIT;
    this.writer = writer;
    this.stack = stack;
 }
Example #8
0
 public void Initialize(OutputStack outputStack)
 {
     myOutput = outputStack;
 }
Example #9
0
        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);
            }
        }
Example #10
0
 void PrintLog(int Rule)
 {
     OutputStack.Push(WorkStack.Pop());
     Log += "M (" + OutputStack.Peek() + " , " + buffer.Token + ") = " + Convert.ToString(Rule) + "\n";
 }