///<summary> ///Adds another ProducerConsumer to the list of processing consumers. ///<para>This method will throw a CycleException if a consumer would be tasked to be its own producer.</para> ///</summary> public void AddConsumer(GhostLine <T> consumer) { if (AncestorDuplicate(consumer) || DescendantDuplicate(consumer)) { throw new CycleException("Adding this consumer would create a cycle."); } consumer.Parent = this; Consumers.Add(consumer); }
private bool AncestorDuplicate(GhostLine <T> candidate) { if (candidate.Parent == null) { return(false); } if (candidate.Parent == this) { return(true); } else { return(AncestorDuplicate(candidate.Parent)); } }
private bool DescendantDuplicate(GhostLine <T> candidate) { if (candidate == this) { return(true); } else { foreach (var child in candidate.Consumers) { if (DescendantDuplicate(child)) { return(true); } } } return(false); }