public override void Process() { base.Process(); ProcessDynamicContent(); if (TableTag == null) { throw new NullReferenceException(); } var tableRows = TableTag.Table.Elements(WordMl.TableRowName); var dynamicRow = TableTag.DynamicRow.HasValue ? tableRows.ElementAt(TableTag.DynamicRow.Value - 1) : tableRows.Last(); ReplaceValues(dynamicRow); if (this.CreateDynamicContentTags) { var innerElements = TraverseUtils.ElementsBetween(this.TableTag.TagTable, this.TableTag.TagEndTable).ToList(); innerElements.Remove(); this.TableTag.TagTable.AddBeforeSelf(DocxHelper.CreateDynamicContentElement(innerElements, this.TableTag.TagTable, this.DynamicContentLockingType)); this.CleanUp(this.TableTag.TagTable, this.TableTag.TagEndTable); } else { RemoveTags(); } }
private void ProcessDynamicContent() { var dynamicContentTags = TraverseUtils.ElementsBetween(this.Tag.StartIf, this.Tag.EndIf).Where(element => element.IsSdt()).ToList(); foreach (var dynamicContentTag in dynamicContentTags) { var innerElements = dynamicContentTag.Element(WordMl.SdtContentName).Elements(); dynamicContentTag.AddAfterSelf(innerElements); dynamicContentTag.Remove(); } }
public override void Process() { base.Process(); this.ProcessDynamicContent(); bool truthful; try { truthful = bool.Parse(this.DataReader.ReadText(this.Tag.Conidition)); } catch (System.FormatException) { truthful = false; } catch (System.Xml.XPath.XPathException) { truthful = false; } if (!truthful) { if (this.CreateDynamicContentTags) { this.Tag.StartIf.AddBeforeSelf(DocxHelper.CreateDynamicContentElement(Enumerable.Empty <XElement>(), this.Tag.StartIf, this.DynamicContentLockingType)); } this.CleanUp(this.Tag.StartIf, this.Tag.EndIf); } else { if (this.CreateDynamicContentTags) { var innerElements = TraverseUtils.ElementsBetween(this.Tag.StartIf, this.Tag.EndIf).ToList(); innerElements.Remove(); this.Tag.StartIf.AddBeforeSelf(DocxHelper.CreateDynamicContentElement(innerElements, this.Tag.StartIf, this.DynamicContentLockingType)); this.CleanUp(this.Tag.StartIf, this.Tag.EndIf); } else { this.Tag.StartIf.Remove(); this.Tag.EndIf.Remove(); } } }
public override void Process() { base.Process(); this.ProcessDynamicContent(); var current = RepeaterTag.StartRepeater; var dataReaders = DataReader.GetReaders(RepeaterTag.Source).ToList(); var repeaterElements = TraverseUtils.SecondElementsBetween(RepeaterTag.StartRepeater, RepeaterTag.EndRepeater) .Select(RepeaterTag.MakeElementCallback).ToList(); for (var index = 0; index < dataReaders.Count; index++) { XElement endIfElementTmp = null; XElement endRepeaterElementTmp = null; XElement endItemTableElement = null; current = this.ProcessElements(repeaterElements, dataReaders[index], current, null, index + 1, ref endIfElementTmp, ref endRepeaterElementTmp, ref endItemTableElement); } foreach (var repeaterElement in repeaterElements) { repeaterElement.XElement.Remove(); } if (this.CreateDynamicContentTags) { var innerElements = TraverseUtils.ElementsBetween(this.RepeaterTag.StartRepeater, this.RepeaterTag.EndRepeater).ToList(); innerElements.Remove(); this.RepeaterTag.StartRepeater.AddBeforeSelf( DocxHelper.CreateDynamicContentElement( innerElements, this.RepeaterTag.StartRepeater, this.DynamicContentLockingType)); this.CleanUp(this.RepeaterTag.StartRepeater, this.RepeaterTag.EndRepeater); } else { this.RepeaterTag.StartRepeater.Remove(); this.RepeaterTag.EndRepeater.Remove(); } }
private void ProcessDynamicContent() { var dynamicContentTags = TraverseUtils.ElementsBetween(this.TableTag.TagTable, this.TableTag.TagEndTable) .Where( element => element.IsSdt() && element.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("dynamiccontent")) .ToList(); foreach (var dynamicContentTag in dynamicContentTags) { var innerElements = dynamicContentTag.Element(WordMl.SdtContentName).Elements(); dynamicContentTag.AddAfterSelf(innerElements); dynamicContentTag.Remove(); } }
public void TestOkay() { var parser = new RepeaterParser(); var tagProcessorMock = new TagProcessorMock <RepeaterProcessor>(); parser.Parse(tagProcessorMock, this.documentRoot.Descendants(WordMl.SdtName).First()); var result = tagProcessorMock.InnerProcessor.RepeaterTag; var repeaterElements = TraverseUtils.ElementsBetween(result.StartRepeater, result.EndRepeater) .Select(result.MakeElementCallback).ToList(); Assert.AreEqual(1, repeaterElements.Count); var childrenOfFirstElement = repeaterElements.First().Elements.ToList(); Assert.AreEqual(9, childrenOfFirstElement.Count); Assert.AreEqual("./Subject", childrenOfFirstElement[3].Expression); Assert.AreEqual(true, childrenOfFirstElement[5].IsIndex); Assert.AreEqual("./ExpireDate", childrenOfFirstElement[7].Expression); Assert.AreEqual("//test/certificates", result.Source); }
public void TestParseNested() { var parser = new RepeaterParser(); var rootProcessor = new RootProcessor(); parser.Parse(rootProcessor, this.nestedDocumentRoot.Descendants(WordMl.SdtName).First()); var repeaterProcessor = rootProcessor.Processors.First(); var result = ((RepeaterProcessor)repeaterProcessor).RepeaterTag; var repeaterElements = TraverseUtils.ElementsBetween(result.StartRepeater, result.EndRepeater) .Select(result.MakeElementCallback).ToList(); Assert.AreEqual(2, repeaterElements.Count); var textTag = repeaterElements.First(); Assert.IsTrue(textTag.XElement.IsSdt()); Assert.IsTrue(textTag.XElement.IsTag("Text")); var repeaterContent = repeaterElements[1].Elements.ToList(); Assert.AreEqual(10, repeaterContent.Count); var textSdt = repeaterContent[3]; Assert.IsNull(textSdt.Expression); Assert.IsTrue(textSdt.XElement.IsSdt()); Assert.IsTrue(textSdt.XElement.IsTag("Text")); Assert.AreEqual("./Subject", repeaterContent[4].Expression); Assert.AreEqual(true, repeaterContent[6].IsIndex); Assert.AreEqual("./ExpireDate", repeaterContent[8].Expression); Assert.AreEqual("//test/certificates", result.Source); Assert.IsTrue(repeaterProcessor.Processors.All(p => p is TextProcessor)); Assert.AreEqual(2, repeaterProcessor.Processors.Count); }
/// <summary> /// Removes all elements between and including passed elements /// </summary> /// <param name="from"></param> /// <param name="to"></param> public void CleanUp(XElement from, XElement to) { TraverseUtils.ElementsBetween(from, to).Remove(); from.Remove(); to.Remove(); }