GlossaryDocumentAccept Method

Accepts a visitor.

Namespace:  Aspose.Words.BuildingBlocks
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public override bool Accept(
	DocumentVisitor visitor
)

Parameters

visitor
Type: Aspose.WordsDocumentVisitor
The visitor that will visit the nodes.

Return Value

Type: Boolean
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.
Remarks

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Remarks

Calls VisitGlossaryDocumentStart(GlossaryDocument), then calls Accept(DocumentVisitor) for all child nodes of this node and then calls VisitGlossaryDocumentEnd(GlossaryDocument) at the end.

Remarks

Note: A glossary document node and its children are not visited when you execute a Visitor over a Document. If you want to execute a Visitor over a glossary document, you need to call Accept(DocumentVisitor).

Examples
Shows how to use GlossaryDocument and BuildingBlockCollection.
public void GlossaryDocument()
{
    Document doc = new Document();

    GlossaryDocument glossaryDoc = new GlossaryDocument();
    glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 1" });
    glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 2" });
    glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 3" });
    glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 4" });
    glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 5" });

    Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count);

    doc.GlossaryDocument = glossaryDoc;

    // There is a different ways how to get created building blocks
    Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name);
    Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name);
    Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name);
    Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name);

    // Get a block by gallery, category and name
    BuildingBlock block4 =
        glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4");

    // All GUIDs are the same by default
    Assert.AreEqual("00000000-0000-0000-0000-000000000000", block4.Guid.ToString());

    // To be able to uniquely identify blocks by GUID, each GUID must be unique
    // We will do that using a custom visitor
    GlossaryDocVisitor visitor = new GlossaryDocVisitor();
    glossaryDoc.Accept(visitor);

    Assert.AreEqual(5, visitor.GetDictionary().Count);

    Console.WriteLine(visitor.GetText());

    // We can find our new blocks in Microsoft Word via Insert > Quick Parts > Building Blocks Organizer...
    doc.Save(ArtifactsDir + "BuildingBlocks.GlossaryDocument.dotx"); 
}

/// <summary>
/// Simple implementation of giving each building block in a glossary document a unique GUID. Implemented as a Visitor.
/// </summary>
public class GlossaryDocVisitor : DocumentVisitor
{
    public GlossaryDocVisitor()
    {
        mBlocksByGuid = new Dictionary<Guid, BuildingBlock>();
        mBuilder = new StringBuilder();
    }

    public string GetText()
    {
        return mBuilder.ToString();
    }

    public Dictionary<Guid, BuildingBlock> GetDictionary()
    {
        return mBlocksByGuid;
    }

    public override VisitorAction VisitGlossaryDocumentStart(GlossaryDocument glossary)
    {
        mBuilder.AppendLine("Glossary document found!");
        return VisitorAction.Continue;
    }

    public override VisitorAction VisitGlossaryDocumentEnd(GlossaryDocument glossary)
    {
        mBuilder.AppendLine("Reached end of glossary!");
        mBuilder.AppendLine("BuildingBlocks found: " + mBlocksByGuid.Count);
        return VisitorAction.Continue;
    }

    public override VisitorAction VisitBuildingBlockStart(BuildingBlock block)
    {
        block.Guid = Guid.NewGuid();
        mBlocksByGuid.Add(block.Guid, block);
        return VisitorAction.Continue;
    }

    public override VisitorAction VisitBuildingBlockEnd(BuildingBlock block)
    {
        mBuilder.AppendLine("\tVisited block \"" + block.Name + "\"");
        mBuilder.AppendLine("\t Type: " + block.Type);
        mBuilder.AppendLine("\t Gallery: " + block.Gallery);
        mBuilder.AppendLine("\t Behavior: " + block.Behavior);
        mBuilder.AppendLine("\t Description: " + block.Description);

        return VisitorAction.Continue;
    }

    private readonly Dictionary<Guid, BuildingBlock> mBlocksByGuid;
    private readonly StringBuilder mBuilder;
}
See Also