/// <summary> /// Walk all elements directly or indirectly associated with this model error /// </summary> /// <param name="callback"><see cref="AssociatedErrorElementCallback"/> delegate</param> public void WalkAssociatedElements(AssociatedErrorElementCallback callback) { foreach (ModelElement element in this.AssociatedElementCollection) { WalkAssociatedElements(element, callback); } }
/// <summary> /// Walk all elements directly or indirectly associated with a model error, /// starting with the specified associated element /// </summary> /// <param name="associatedElement">The associated <see cref="ModelElement"/></param> /// <param name="callback"><see cref="AssociatedErrorElementCallback"/> delegate</param> public static void WalkAssociatedElements(ModelElement associatedElement, AssociatedErrorElementCallback callback) { WalkAssociatedElementsHelper(associatedElement, callback, null); ElementLink elementLink; IElementLinkRoleHasIndirectModelErrorOwner indirectOwnerLink; if (null != (elementLink = associatedElement as ElementLink) && null != (indirectOwnerLink = elementLink as IElementLinkRoleHasIndirectModelErrorOwner)) { Guid[] guids; int roleCount; if (null != (guids = indirectOwnerLink.GetIndirectModelErrorOwnerElementLinkRoles()) && 0 != (roleCount = guids.Length)) { for (int i = 0; i < roleCount; ++i) { WalkAssociatedElementsHelper(DomainRoleInfo.GetRolePlayer(elementLink, guids[i]), callback, null); } } } }
private static void WalkAssociatedElementsHelper(ModelElement element, AssociatedErrorElementCallback callback, Predicate <ModelElement> filter) { if (element is IModelErrorOwner) { callback(element); } IHasIndirectModelErrorOwner indirectOwner; DomainDataDirectory domainDataDirectory = null; if (null != (indirectOwner = element as IHasIndirectModelErrorOwner)) { Guid[] indirectRoles; int indirectRoleCount; if (null != (indirectRoles = indirectOwner.GetIndirectModelErrorOwnerLinkRoles()) && 0 != (indirectRoleCount = indirectRoles.Length)) { domainDataDirectory = element.Store.DomainDataDirectory; for (int i = 0; i < indirectRoleCount; ++i) { foreach (ModelElement linkedElement in domainDataDirectory.FindDomainRole(indirectRoles[i]).GetLinkedElements(element)) { if (filter != null && filter(linkedElement)) { continue; } WalkAssociatedElementsHelper( linkedElement, callback, delegate(ModelElement testElement) { return(testElement == element || (filter != null && filter(testElement))); }); } } } } ElementLink elementLink; IElementLinkRoleHasIndirectModelErrorOwner indirectLinkRoleOwner; if (null != (indirectLinkRoleOwner = element as IElementLinkRoleHasIndirectModelErrorOwner) && null != (elementLink = element as ElementLink)) { Guid[] metaRoles = indirectLinkRoleOwner.GetIndirectModelErrorOwnerElementLinkRoles(); int roleCount; if (metaRoles != null && 0 != (roleCount = metaRoles.Length)) { if (domainDataDirectory == null) { domainDataDirectory = element.Store.DomainDataDirectory; } for (int i = 0; i < roleCount; ++i) { DomainRoleInfo metaRole = domainDataDirectory.FindDomainRole(metaRoles[i]); if (metaRole != null) { ModelElement rolePlayer = metaRole.GetRolePlayer(elementLink); if (filter != null && filter(rolePlayer)) { continue; } WalkAssociatedElementsHelper( rolePlayer, callback, delegate(ModelElement testElement) { return(testElement == element || (filter != null && filter(testElement))); }); } } } } }