Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public void SetState(Connection connection, State state)
        {
            var couple = EndpointCouples.FirstOrDefault(e => e.Item1 == connection);

            if (couple == null)
            {
                return;
            }

            foreach (var ncdControlMessage in couple.Item2.GetMessages(state, couple.Item3))
            {
                OutputStack.Push(ncdControlMessage.GetMessage());
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
 void PrintLog(int Rule)
 {
     OutputStack.Push(WorkStack.Pop());
     Log += '\n' + "M (" + OutputStack.Peek() + "," + input[Counter] + ") = " + Convert.ToString(Rule);
 }
Ejemplo n.º 7
0
 void PrintLog(int Rule)
 {
     OutputStack.Push(WorkStack.Pop());
     Log += "M (" + OutputStack.Peek() + " , " + buffer.Token + ") = " + Convert.ToString(Rule) + "\n";
 }