public void Build(NGenerics.DataStructures.Trees.GeneralTree<DirectoryCrawler.IDirectoryTreeNode> features) { this.ditaMapBuilder.Build(features); var actionVisitor = new ActionVisitor<IDirectoryTreeNode>(node => { var featureDirectoryTreeNode = node as FeatureDirectoryTreeNode; if (featureDirectoryTreeNode != null) { this.ditaFeatureFormatter.Format(featureDirectoryTreeNode); } }); features.AcceptVisitor(actionVisitor); }
public void Build(NGenerics.DataStructures.Trees.GeneralTree<DirectoryCrawler.IDirectoryTreeNode> features) { string filename = string.IsNullOrEmpty(this.configuration.SystemUnderTestName) ? "features.docx" : this.configuration.SystemUnderTestName + ".docx"; var documentFileName = Path.Combine(this.configuration.OutputFolder.FullName, filename); if (File.Exists(documentFileName)) File.Delete(documentFileName); using (var wordProcessingDocument = WordprocessingDocument.Create(documentFileName, DocumentFormat.OpenXml.WordprocessingDocumentType.Document)) { var mainDocumentPart = wordProcessingDocument.AddMainDocumentPart(); this.wordStyleApplicator.AddStylesPartToPackage(wordProcessingDocument); this.wordStyleApplicator.AddStylesWithEffectsPartToPackage(wordProcessingDocument); this.wordFontApplicator.AddFontTablePartToPackage(wordProcessingDocument); var documentSettingsPart = mainDocumentPart.AddNewPart<DocumentSettingsPart>(); documentSettingsPart.Settings = new Settings(); this.wordHeaderFooterFormatter.ApplyHeaderAndFooter(wordProcessingDocument); var document = new Document(); var body = new Body(); document.Append(body); var actionVisitor = new ActionVisitor<IDirectoryTreeNode>(node => { var featureDirectoryTreeNode = node as FeatureDirectoryTreeNode; if (featureDirectoryTreeNode != null) { this.wordFeatureFormatter.Format(body, featureDirectoryTreeNode); } }); features.AcceptVisitor(actionVisitor); mainDocumentPart.Document = document; mainDocumentPart.Document.Save(); } // HACK - Add the table of contents using (var wordProcessingDocument = WordprocessingDocument.Open(documentFileName, true)) { XElement firstPara = wordProcessingDocument .MainDocumentPart .GetXDocument() .Descendants(W.p) .FirstOrDefault(); TocAdder.AddToc(wordProcessingDocument, firstPara, @"TOC \o '1-2' \h \z \u", null, 4); } }