示例#1
0
        private async Task InstructPageRenderingAsync(XElement page, Dictionary <string, string> valuesByReference)
        {
            AssertElementName(page, "page");

            _context = _context.BeforeBegin(page.Name.LocalName, hasContent: page.HasContent());
            await _builder.BeginWritePageAsync(_context);

            _context = _context.AfterBegin();

            await TraverseContainerElementAsync(page, valuesByReference);

            _context = _context.BeforeEnd();
            await _builder.EndWritePageAsync(_context);

            _context = _context.AfterEnd();
        }
示例#2
0
        public async Task InstructRenderingAsync(string markup, DocumentRenderModel model, IDocumentBuilderV1 builder)
        {
            if (_context != null)
            {
                throw new InvalidOperationException();
            }

            _context = new DocumentInstructionContextV1();
            _builder = builder;
            _model   = model;
            _listItemIndexContinueOffsetByNestingLevel = new Dictionary <int, int>();

            XDocument document = null;

            using (var sr = new StringReader(markup))
            {
                document = XDocument.Load(sr);
            }

            var root = document.Root;

            var valuesByReference = _model.Items.ToDictionary(i => i.Reference, i => i.Value);

            _context = _context.BeforeBegin(document.Root.Name.LocalName, hasContent: document.Root.HasContent());
            await builder.BeginWriteDocumentAsync(model, _context);

            _context = _context.AfterBegin();

            foreach (var page in root.Elements())
            {
                await WriteConditionalElementAsync(page, valuesByReference, async() =>
                {
                    await InstructPageRenderingAsync(page, valuesByReference);
                });
            }

            _context = _context.BeforeEnd();
            await builder.EndWriteDocumentAsync(_context);

            _context = _context.AfterEnd();
        }