Beispiel #1
0
        public List <object> GetList(Type type, Dictionary <string, object> clauses)
        {
            if (typeof(Summary).IsAssignableFrom(type))
            {
                List <Type> types;
                if (clauses.ContainsKey("@Types"))
                {
                    types = (List <Type>)clauses["@Types"];
                }
                else
                {
                    types = ContentTypeHierarchy.GetSummaryContainers(type);
                }
                var typeGroups = types
                                 .GroupBy(ct => Registered(ct));
                List <object> res = new List <object>();

                foreach (var typeGroup in typeGroups)
                {
                    clauses["@Types"] = typeGroup.ToList();
                    res.AddRange(typeGroup.Key.GetList(type, clauses));
                }
                return(res);
            }
            return(Registered(type).GetList(type, clauses));
        }
Beispiel #2
0
        public IEnumerable <PropertyStore> Get(Type type, Dictionary <string, object> clauses, List <string> fields, bool excludeFields)
        {
            if (typeof(Summary).IsAssignableFrom(type))
            {
                if (clauses.ContainsKey("@Type"))
                {
                    return(Registered((Type)clauses["@Type"]).Get(type, clauses, fields, excludeFields));
                }

                List <Type> types;
                if (clauses.ContainsKey("@Types"))
                {
                    types = (List <Type>)clauses["@Types"];
                }
                else
                {
                    types = ContentTypeHierarchy.GetSummaryContainers(type);
                }

                var typeGroups = types
                                 .GroupBy(ct => Registered(ct));
                List <PropertyStore> resAll = new List <PropertyStore>();
                foreach (var typeGroup in typeGroups)
                {
                    clauses["@Types"] = typeGroup.ToList();
                    var res = typeGroup.Key.Get(type, clauses, fields, excludeFields);
                    resAll.AddRange(res);
                }
                return(resAll);
            }
            return(Registered(type).Get(type, clauses, fields, excludeFields));
        }
Beispiel #3
0
 /// <summary>
 /// Get items by a query
 /// </summary>
 /// <typeparam name="T">type of items returned by repository</typeparam>
 /// <param name="targetType">type of items these will produce, and in terms of which the query body is defined</param>
 /// <param name="queryBody">function to apply to a source queryable to filter to the queryable required</param>
 /// <returns>items in containers or the items themselves</returns>
 public IEnumerable <T> Get <T>(Type targetType, Func <IQueryable <T>, IQueryable <T> > queryBody) where T : class
 {
     if (typeof(Summary).IsAssignableFrom(targetType))
     {
         return(Get <T>(targetType, ContentTypeHierarchy.GetSummaryContainers(targetType), queryBody));
     }
     else
     {
         return(Registered(targetType).Get <T>(targetType, new Type[] { targetType }, queryBody));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Get items via a query
 /// </summary>
 /// <typeparam name="T">return type, this can be a summmary type, a content type, or a class from which several content types inherit.  The query will be applied across all content types which could output an item of this type.</typeparam>
 /// <typeparam name="TQuery">the type in terms of which the query is expressed: the content type or possibly a class from which several content types inherit</typeparam>
 /// <param name="queryBody">a function which takes an iqueryable and adds the query to the end of it</param>
 /// <returns>list of items of (or cast to) return type</returns>
 public IEnumerable <T> Get <T, TQuery>(Func <IQueryable <TQuery>, IQueryable <TQuery> > queryBody)
     where T : class
     where TQuery : class
 {
     if (typeof(Summary).IsAssignableFrom(typeof(T)))
     {
         return(Get <T, TQuery>(ContentTypeHierarchy.GetSummaryContainers(typeof(T)), queryBody));
     }
     else
     {
         return(Get <T, TQuery>(ContentTypeHierarchy.GetAssignableContentTypes(this, typeof(T)), queryBody));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Get a data item, or list of items, via the route which maps to them
        /// </summary>
        /// <typeparam name="T">type of the item(s), a generic list if a list of items, could be a summary type</typeparam>
        /// <param name="contentType">the content type of the item(s)</param>
        /// <param name="rd">route data</param>
        /// <returns>the mapped items(s)</returns>
        public T Get <T>(Type contentType, RouteData rd) where T : class
        {
            //CodeTimer.MarkTime("Get via route START");

            try
            {
                if (typeof(T).IsGenericType() && typeof(T).GetGenericTypeDefinition() == typeof(List <>))
                {
                    Type        elType = typeof(T).GetGenericArguments()[0];
                    ICollator   coll;
                    List <Type> contentTypes;
                    bool        isSummary = typeof(Summary).IsAssignableFrom(elType);
                    if (isSummary)
                    {
                        contentTypes = ContentTypeHierarchy.GetSummaryContainers(elType);
                        if (contentTypes.Select(ct => Registered(ct)).Distinct().Count() != 1)
                        {
                            throw new Exception("Content types containing summary type " + elType.FullName + " dont have 1 unique registered collator, requirement for a dataroute with list type");
                        }

                        coll = Registered(contentTypes.First());
                    }
                    else
                    {
                        coll         = Registered(elType);
                        contentTypes = new List <Type> {
                            elType
                        };
                    }

                    T itemList = (T)ReflectionX.InvokeGenericMethod(coll, "GetList",
                                                                    new Type[] { elType, isSummary ? elType : ContainerType(elType) },
                                                                    contentTypes,
                                                                    rd);
                    return(itemList);
                }
                else
                {
                    ICollator coll = Registered(contentType);
                    return(coll.Get <T>(new List <Address> {
                        coll.GetAddress(contentType, rd)
                    }).FirstOrDefault());
                }
            }
            finally
            {
                //CodeTimer.MarkTime("Get via route END");
            }
        }