Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
c_hoppen
in reply to: WCrihfield

It's getting stranger and stranger... 

With my test assembly (2650 files & 10000 Occurrences), the following code takes about 1.5 seconds. Always. The assembly is already open.

ComponentOccurrences occs = assmDoc.ComponentDefinition.Occurrences;
foreach (Document document in assmDoc.AllReferencedDocuments)
{
    if (IsMatching(document, sd))
    {
        ComponentOccurrencesEnumerator leafOccs = occs.get_AllReferencedOccurrences(document);
        foreach (ComponentOccurrence occ in leafOccs)
        {
            oCol.Add(occ);
        }
    }
}

Traversing the assembly occurrences leads to the same result:

foreach (ComponentOccurrence occ in assmDoc.ComponentDefinition.Occurrences)
{
    if (IsMatching(occ.Definition.Document as Document, sd))
        oCol.Add(occ);
    if (occ.SubOccurrences.Count > 0)
        TraverseAssembly(occ.SubOccurrences, sd, oCol);
}
......
private static void TraverseAssembly(ComponentOccurrencesEnumerator subOccurrences, SearchDefinition sd, ObjectCollection oCol)
{
    foreach(ComponentOccurrence occ in subOccurrences)
    {
        if (IsMatching(occ.Definition.Document as Document, sd))
            oCol.Add(occ);
        if (occ.SubOccurrences.Count > 0)
            TraverseAssembly(occ.SubOccurrences, sd, oCol);
    }
}

But it takes 17 seconds for the first call, and a quick glance for subsequent calls ( < 500 mSec).