示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
        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)));
        }
示例#5
0
        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);
                }
            }
        }
示例#6
0
        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));
                }
            }
        }
示例#7
0
 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);
 }