private static bool BuildShortestPath(ref List <SqlRelationAttribute> res, RelationPath paths, Func <string, string, bool> isDestination, string previousSchema, string previousTable) { foreach (var nextPath in paths.NextPaths) { if (isDestination(nextPath.Schema, nextPath.Table)) { res.Insert(0, nextPath.SqlRelation); return(true); } var foundWanted = BuildShortestPath(ref res, nextPath, isDestination, paths.Schema, paths.Table); if (foundWanted) { //check if relation needs to be turned around, fex. 'gebouw -> terrobj <- tobjhnr', should be 'gebouw -> terrobj -> tobjhnr' if (nextPath.SqlRelation.SelfSchema == paths.Schema && nextPath.SqlRelation.SelfTable == paths.Table) { res.Insert(0, nextPath.SqlRelation); } else { res.Insert(0, nextPath.SqlRelation.CreateReverse()); } return(true); } } return(false); }
public void AddNextPath(RelationPath nextPath) { if (nextPath != null) { _NextPaths.Add(nextPath); } }
private static RelationPath BuildPathsTo(RelationPath path, string currentSchema, string currentTable, Func <string, string, bool> isDestination, string previousSchema, string previousTable, IEnumerable <SqlRelationAttribute> blacklist, List <string> usedPaths) { if (usedPaths == null) { usedPaths = new List <string>(); } if (path == null) { path = new RelationPath(); } path.Schema = currentSchema; path.Table = currentTable; var relationsFrom = GetRelationsFrom(currentSchema, currentTable); var relationsTo = GetRelationsTo(currentSchema, currentTable); foreach (var relation in relationsFrom) { //illegal paths if (blacklist != null && blacklist.Contains(relation)) { continue; } //when you go down the rabbit hole... no turning backsies dynamic currentPath = relation.ToString(); if (usedPaths.Contains(currentPath)) { continue; } usedPaths.Add(currentPath); //are we there yet? if (isDestination(relation.OtherSchema, relation.OtherTable)) { //yes! RelationPath nextPath = new RelationPath(); nextPath.PreviousPath = path; nextPath.Schema = relation.OtherSchema; nextPath.Table = relation.OtherTable; nextPath.SqlRelation = relation; path.AddNextPath(nextPath); //Return path } else { //no :( go further down the hole RelationPath nextPath = new RelationPath(); nextPath.PreviousPath = path; nextPath.SqlRelation = relation; nextPath = BuildPathsTo(nextPath, relation.OtherSchema, relation.OtherTable, isDestination, currentSchema, currentTable, blacklist, usedPaths); path.AddNextPath(nextPath); } } foreach (var relation in relationsTo) { //illegal paths if (blacklist != null && blacklist.Contains(relation)) { continue; } //when you go down the rabbit hole... no turning back var currentPath = relation.ToString(); if (usedPaths.Contains(currentPath)) { continue; } usedPaths.Add(currentPath); //are we there yet? if (isDestination(relation.SelfSchema, relation.SelfTable)) { //yes! RelationPath nextPath = new RelationPath(); nextPath.PreviousPath = path; nextPath.Schema = relation.SelfSchema; nextPath.Table = relation.SelfTable; nextPath.SqlRelation = relation; path.AddNextPath(nextPath); //Return path } else { //no :( go further down the hole RelationPath nextPath = new RelationPath(); nextPath.PreviousPath = path; nextPath.SqlRelation = relation; nextPath = BuildPathsTo(nextPath, relation.SelfSchema, relation.SelfTable, isDestination, currentSchema, currentTable, blacklist, usedPaths); path.AddNextPath(nextPath); } } return(path); }
private static RelationPath BuildPathsTo(RelationPath path, string currentSchema, string currentTable, string wantedSchema, string wantedTable, string previousSchema, string previousTable, IEnumerable <SqlRelationAttribute> blacklist, List <string> usedPaths) { return(BuildPathsTo(path, currentSchema, currentTable, (schema, table) => schema == wantedSchema && table == wantedTable, previousSchema, previousTable, blacklist, usedPaths)); }
private static bool BuildShortestPath(ref List <SqlRelationAttribute> res, RelationPath paths, string wantedSchema, string wantedTable, string previousSchema, string previousTable) { return(BuildShortestPath(ref res, paths, (schema, table) => schema == wantedSchema && table == wantedTable, previousSchema, previousTable)); }