public DomainObjectGraphTraverser(DomainObject rootObject, IGraphTraversalStrategy strategy) { ArgumentUtility.CheckNotNull("rootObject", rootObject); ArgumentUtility.CheckNotNull("strategy", strategy); _rootObject = rootObject; _strategy = strategy; }
/// <summary> /// Loads the object with the specified <see cref="ObjectID"/> plus all objects directly or indirectly referenced by it into the /// transporter, as specified by the <see cref="IGraphTraversalStrategy"/>. Each object behaves as if it were loaded via <see cref="Load"/>. /// </summary> /// <param name="objectID">The <see cref="ObjectID"/> of the object which is to be loaded together with its related objects.</param> /// <param name="strategy">An <see cref="IGraphTraversalStrategy"/> instance defining which related object links to follow and which /// objects to include in the set of transported objects.</param> /// <returns>The loaded objects, whose properties can be manipulated before they are transported.</returns> /// <seealso cref="DomainObjectGraphTraverser.GetFlattenedRelatedObjectGraph"/> public IEnumerable <DomainObject> LoadRecursive(ObjectID objectID, IGraphTraversalStrategy strategy) { ArgumentUtility.CheckNotNull("objectID", objectID); ArgumentUtility.CheckNotNull("strategy", strategy); DomainObject sourceObject = _transportTransaction.GetObject(objectID, false); using (_transportTransaction.EnterNonDiscardingScope()) { HashSet <DomainObject> graph = new DomainObjectGraphTraverser(sourceObject, strategy).GetFlattenedRelatedObjectGraph(); foreach (DomainObject domainObject in graph) { Load(domainObject.ID); // explicitly call load rather than just implicitly loading it into the transaction for consistency } return(graph); } }
protected virtual IEnumerable <Tuple <DomainObject, int> > GetNextTraversedObjects(DomainObject current, int currentDepth, IGraphTraversalStrategy strategy) { var properties = new PropertyIndexer(current); foreach (PropertyAccessor property in properties.AsEnumerable()) { switch (property.PropertyData.Kind) { case PropertyKind.RelatedObject: if (strategy.ShouldFollowLink(_rootObject, current, currentDepth, property)) { var relatedObject = (DomainObject)property.GetValueWithoutTypeCheck(); if (relatedObject != null) { yield return(Tuple.Create(relatedObject, currentDepth + 1)); } } break; case PropertyKind.RelatedObjectCollection: if (strategy.ShouldFollowLink(_rootObject, current, currentDepth, property)) { foreach (DomainObject relatedObject in (DomainObjectCollection)property.GetValueWithoutTypeCheck()) { if (relatedObject != null) { yield return(Tuple.Create(relatedObject, currentDepth + 1)); } } } break; } } }