/// <summary> /// expand the graph to paths /// </summary> /// <param name="graphTrace"></param> /// <returns></returns> public static IEnumerable <IEnumerable <GraphTrace> > Paths( this GraphTrace graphTrace, string finalKey = null, List <string> allowedKeys = null) { if (graphTrace.vertexExists && graphTrace.withs.Values.Sum(list => list.Count(gt => gt.vertexExists)) == 0) { if (finalKey == null || graphTrace.key == finalKey) { yield return(new List <GraphTrace> { }); } } else { foreach (var pair in graphTrace.withs) { if (allowedKeys == null || allowedKeys.Contains(pair.Key)) { foreach (var subTrace in pair.Value) { foreach (var subPath in subTrace.Paths(finalKey, allowedKeys)) { var path = new List <GraphTrace>() { subTrace }; path.AddRange(subPath); yield return(path); } } } } } }
internal static GraphTrace Populate(this GraphTrace graphTrace, Dictionary <string, Dictionary <string, BsonDocument> > entities) { graphTrace.edge = entities.TryGet(graphTrace.edgeType)?.TryGet(graphTrace.edgeId); graphTrace.vertex = entities.TryGet(graphTrace.vertexType)?.TryGet(graphTrace.vertexId); foreach (var subGraphTraces in graphTrace.withs.Values) { subGraphTraces.ForEach(subGraphTrace => { subGraphTrace.Parent = graphTrace; subGraphTrace.Populate(entities); }); } return(graphTrace); }
public static IEnumerable <string> SearchBranchByKey(this GraphTrace graphTrace, string key) { foreach (var name in graphTrace.withs.Keys) { foreach (var trace in graphTrace.withs[name]) { if (name == key && trace.vertexExists) { yield return(trace.vertexId); } foreach (var id in trace.SearchBranchByKey(key)) { yield return(id); } } } }