Ejemplo n.º 1
0
        //[Test]
        //public void TestTable_SimpleSingle()
        //{
        //    using (Stream sIn = new FileStream(TESTFILE_DIR + "TableSimple2By2.xml", FileMode.Open))
        //    {
        //        DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null);

        //        tbl_Handler objectConsumer = new tbl_Handler(null);
        //        Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer);

        //        Assert.IsFalse(objectConsumer.HasNonDocElements(), "tbl tag should not generate any nondoc elements");
        //        Helper_VerifySingleDocElementWasDispatchedOfType(writerOut, typeof(Table));
        //        Assert.IsTrue(writerOut.Elements[0].IsContent);
        //        Assert.IsFalse(writerOut.Elements[0].IsStart);
        //    }
        //}


        #region Helpers
        private static void Helper_ParseFileIntoConsumer(Stream sIn, DocXReaderTestWriter writerOut, XMLConsumer objectConsumer)
        {
            Parser pft = new Parser(sIn, objectConsumer, writerOut);
            
            pft.StopOnTopLevelTargetFinished();
            pft.Parse();
            Assert.AreEqual(0, pft.m_targets.Count, "Should have completed any subtargets");
            Assert.IsFalse(objectConsumer.HasElementsToDispatch(), "All doc elements should have been dispatched by completion");
        }
Ejemplo n.º 2
0
        private bool DealWithTargetFinished(ref XMLConsumer target)
        {
            if (m_bStopOnTopLevelTargetFinished && m_targets.Count == 0)
                return false;

            if (target.GetSubConsumer() != null)
                throw new DocXReadException("A target that had finished also specified an available subconsumer");

            Queue<object> NonDocElements = target.GetNonDocElements();

            if (m_targets.Count == 0 && NonDocElements.Count > 0)
            {
                throw new DocXReadException("The last target has finished (stack empty) and has output that will not be used");
            }

            if (m_targets.Count == 0)
                return false;

            if (target is p_Handler)
                InsertSectionFormattingPlaceholdersIfRequired();

            target.Dispose();
            target = m_targets.Pop();

            while (NonDocElements.Count > 0)
            {
                object consumerOutput = NonDocElements.Dequeue();
                target.OnSubConsumerComplete(consumerOutput);

                // the fact that the sub-consumer is complete may allow the higher level consumer
                // to dispatch an element
                while (target.HasElementsToDispatch())
                    AddObject(target.GetNextElementToDispatch());
            }
            return true;
        }