public static TMap Map <TMap>(this SortedGraph sortedGraph, TMap map) { var type = typeof(TMap); foreach (var property in type.GetProperties()) { var propertyType = property.PropertyType; if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == ListGenericType) { var queryType = propertyType.GetGenericArguments()[0]; var documents = sortedGraph.ByKey(property.Name, queryType).ToList(); IList list = property.GetValue(map) as IList; foreach (var document in documents) { list.Add(BsonSerializer.Deserialize(document, queryType)); } } else { var queryType = property.PropertyType; var documents = sortedGraph.ByKey(property.Name, queryType).ToList(); var first = documents.FirstOrDefault(); property.SetValue(map, first); } } return(map); }
public static T ByTypeId <T>(this SortedGraph sortedGraph, string id) where T : DocumentBase { var type = typeof(T); var dict = sortedGraph.entities.ContainsKey(type.Name) ? sortedGraph.entities[type.Name] : null; if (dict == null) { return(null); } return(dict.ContainsKey(id)? BsonSerializer.Deserialize <T>(dict[id]) : null); }
public static bool HasTypeId <T>(this SortedGraph sortedGraph, string id) where T : DocumentBase { var type = typeof(T); var dict = sortedGraph.entities.ContainsKey(type.Name) ? sortedGraph.entities[type.Name] : null; if (dict == null) { return(false); } return(dict.ContainsKey(id)); }
public static Dictionary <string, T> ByType <T>(this SortedGraph sortedGraph) where T : DocumentBase { var type = typeof(T); var dict = sortedGraph.entities.ContainsKey(type.Name) ? sortedGraph.entities[type.Name] : null; if (dict == null) { return(new Dictionary <string, T>()); } return(dict.ToDictionary(pair => pair.Key, pair => BsonSerializer.Deserialize <T>(pair.Value))); }
public static IEnumerable <BsonDocument> ByKey(this SortedGraph sortedGraph, string key, Type type) { var dict = sortedGraph.entities.ContainsKey(type.Name)? sortedGraph.entities[type.Name]: null; if (dict == null) { yield break; } foreach (var id in sortedGraph.graph.SelectMany(trace => trace.SearchBranchByKey(key))) { var doc = dict?[id]; if (doc != null) { yield return(doc); } } }
public static IEnumerable <T> ByKey <T>(this SortedGraph sortedGraph, string key) { var type = typeof(T); var dict = sortedGraph.entities.ContainsKey(type.Name) ? sortedGraph.entities[type.Name] : null; if (dict == null) { yield break; } foreach (var id in sortedGraph.graph.SelectMany(trace => trace.SearchBranchByKey(key))) { var doc = dict?[id]; if (doc != null) { yield return(BsonSerializer.Deserialize <T>(doc)); } } }
public static IEnumerable <IEnumerable <GraphTrace> > Paths( this SortedGraph sortedGraph, string finalKey = null, List <string> allowedKeys = null) { return(sortedGraph.graph.SelectMany(graphTrace => { List <List <GraphTrace> > results = new List <List <GraphTrace> >(); foreach (var paths in graphTrace.Paths()) { var path = new List <GraphTrace>() { graphTrace }; path.AddRange(paths); results.Add(path); } return results; })); }
internal static SortedGraph Populate(this SortedGraph sortedGraph) { sortedGraph.graph.ForEach(graphTrace => graphTrace.Populate(sortedGraph.entities)); return(sortedGraph); }