private void addConnectable(FilteredConnectablesGroup rootGroup, IConnectable connectable, IEnumerable <ITECObject> parentPath) { if (!filterPredicate(connectable)) { return; } IRelatable rootScope = rootGroup.Scope as IRelatable ?? this.root; List <ITECObject> path = new List <ITECObject>(parentPath); if (rootScope != parentPath.First()) { path = rootScope.GetObjectPath(parentPath.First()); path.Remove(parentPath.First()); path.AddRange(parentPath); } if (path.Count == 0) { logger.Error("New connectable doesn't exist in root object."); return; } FilteredConnectablesGroup lastGroup = rootGroup; int lastIndex = 0; for (int i = path.Count - 1; i > 0; i--) { if (path[i] is ITECScope scope) { FilteredConnectablesGroup group = rootGroup.GetGroup(scope); if (group != null) { lastGroup = group; lastIndex = i; break; } } else { logger.Error("Object in path to connectable isn't ITECScope, cannot build group hierarchy."); return; } } FilteredConnectablesGroup currentGroup = lastGroup; for (int i = lastIndex + 1; i < path.Count; i++) { if (path[i] is ITECScope scope) { currentGroup = currentGroup.Add(scope); } else { logger.Error("Object in path to connectable isn't ITECScope, cannot build group hierarchy."); return; } } }
public static bool IsDirectDescendant(this IRelatable relatable, ITECObject item) { return(relatable.GetObjectPath(item).Count > 0); }