using System; using System.Collections; using System.Collections.Generic; namespace BismNormalizer.TabularCompare.TabularMetadata { /// /// Represents a chain of RelationshipLink objects, used to detect ambiguity in relationship paths. /// public class RelationshipChainsFromRoot : List { /// /// Find end table by name. /// /// Name of the end table. /// RelationshipLink object if found; null if not found. public RelationshipLink FindByEndTableName(string endTableName) { foreach (RelationshipLink ReferencedTable in this) { if (ReferencedTable.EndTable.Name == endTableName) { return ReferencedTable; } } return null; } /// /// Find the root RelationshipLink in the chain. /// /// RelationshipLink object if found; null if not found. public RelationshipLink FindRoot() { foreach (RelationshipLink ReferencedTable in this) { if (ReferencedTable.Root) { return ReferencedTable; } } return null; } /// /// Check if chain of RelationshipLink objects contains an end table with specified name. /// /// Name of the end table. /// Boolean indicating if the end table was found. public bool ContainsEndTableName(string endTableName) { foreach (RelationshipLink link in this) { if (link.EndTable.Name == endTableName) { return true; } } return false; } /// /// Check if chain of RelationshipLink objects contains an end table with specified name that is BiDi invoked. /// /// Name of the end table. /// Boolean indicating if the BiDi invoked end table was found. public bool ContainsBidiToEndTable(string endTableName) { foreach (RelationshipLink link in this) { if (link.EndTable.Name == endTableName && link.PrecedingPathBiDiInvoked) { return true; } } return false; } /// /// Remove end table from chain of RelationshipLink objects. /// /// Name of end table to remvoe. /// Boolean indicating if the end table was successfully removed. public bool RemoveByEndTableName(string endTableName) { foreach (RelationshipLink ReferencedTable in this) { if (ReferencedTable.EndTable.Name == endTableName) { this.Remove(ReferencedTable); return true; } } return false; } } }