예제 #1
0
        public IEnumerable CollectChildRecords(IEnumerable datasource, DataManagerRequest dm)
        {
            IEnumerable enumerable1 = (IEnumerable)SfBaseUtils.ChangeType((object)datasource, datasource.GetType());
            string      idMapping   = dm.IdMapping;

            object[] objArray = new object[0];
            if (enumerable1.GetType() == typeof(List <ExpandoObject>) || enumerable1.GetElementType() == typeof(ExpandoObject))
            {
                foreach (IDictionary <string, object> dictionary in datasource.Cast <ExpandoObject>().ToList <ExpandoObject>())
                {
                    object obj = dictionary[idMapping];
                    objArray = ((IEnumerable <object>)objArray).Concat <object>((IEnumerable <object>) new object[1]
                    {
                        obj
                    }).ToArray <object>();
                }
            }
            else
            {
                foreach (object obj1 in datasource)
                {
                    object obj2 = obj1.GetType().GetProperty(idMapping).GetValue(obj1);
                    objArray = ((IEnumerable <object>)objArray).Concat <object>((IEnumerable <object>) new object[1]
                    {
                        obj2
                    }).ToArray <object>();
                }
            }
            IEnumerable enumerable2 = (IEnumerable)null;

            foreach (object obj in objArray)
            {
                dm.Where[0].value = obj;
                IEnumerable enumerable3 = enumerable1.GetType() == typeof(List <ExpandoObject>) || enumerable1.GetElementType() == typeof(ExpandoObject) ? (IEnumerable)DynamicObjectOperation.PerformFiltering(enumerable1, dm.Where, dm.Where[0].Operator) : DataOperations.PerformFiltering(enumerable1, dm.Where, dm.Where[0].Operator);
                enumerable2 = enumerable2 == null || enumerable2.AsQueryable().Count() == 0 ? enumerable3 : (IEnumerable)((IEnumerable <object>)enumerable2).Concat <object>((IEnumerable <object>)enumerable3);
            }
            if (enumerable2 != null)
            {
                IEnumerable enumerable3 = this.CollectChildRecords(enumerable2, dm);
                if (dm.Sorted != null && dm.Sorted.Count > 0)
                {
                    enumerable3 = enumerable1.GetType() == typeof(List <ExpandoObject>) || enumerable1.GetElementType() == typeof(ExpandoObject) ? (IEnumerable)DynamicObjectOperation.PerformSorting(enumerable3.AsQueryable(), dm.Sorted) : DataOperations.PerformSorting(enumerable3, dm.Sorted);
                }
                datasource = (IEnumerable)((IEnumerable <object>)datasource).Concat <object>((IEnumerable <object>)enumerable3);
            }
            return(datasource);
        }
예제 #2
0
        public static Func <IEnumerable, string, string, object> CalculateAggregateFunc() => (Func <IEnumerable, string, string, object>)((items, property, pd) =>
        {
            string str         = pd;
            IQueryable source1 = items.AsQueryable();
            bool flag1         = items.Cast <object>().ToList <object>()[0].GetType().BaseType == typeof(DynamicObject);
            bool flag2         = items.Cast <object>().ToList <object>()[0].GetType() == typeof(ExpandoObject);
            if (flag1 | flag2)
            {
                IQueryable <IDynamicMetaObjectProvider> source2 = items.Cast <IDynamicMetaObjectProvider>().AsQueryable <IDynamicMetaObjectProvider>();
                switch (str)
                {
                case "Average":
                    if (flag1)
                    {
                        return((object)source2.Select <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetDynamicValue(item as DynamicObject, property))).ToList <object>().Average <object>((Func <object, double>)(value => Convert.ToDouble(value))));
                    }
                    return((object)source2.Select <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetExpandoValue(item as ExpandoObject, property))).ToList <object>().Average <object>((Func <object, double>)(value => Convert.ToDouble(value))));

                case "Count":
                    return((object)source2.Count());

                case "FalseCount":
                    List <WhereFilter> whereFilter1 = new List <WhereFilter>()
                    {
                        new WhereFilter()
                        {
                            Field    = property,
                            Operator = "equal",
                            value    = (object)false
                        }
                    };
                    return((object)DynamicObjectOperation.PerformFiltering(items, whereFilter1, (string)null).Count());

                case "Max":
                    if (flag1)
                    {
                        return(source2.Max <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetDynamicValue(item as DynamicObject, property))));
                    }
                    return(source2.Max <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetExpandoValue(item as ExpandoObject, property))));

                case "Min":
                    if (flag1)
                    {
                        return(source2.Min <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetDynamicValue(item as DynamicObject, property))));
                    }
                    return(source2.Min <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetExpandoValue(item as ExpandoObject, property))));

                case "Sum":
                    if (flag1)
                    {
                        return((object)source2.Select <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetDynamicValue(item as DynamicObject, property))).ToList <object>().Sum <object>((Func <object, double>)(value => Convert.ToDouble(value))));
                    }
                    return((object)source2.Select <IDynamicMetaObjectProvider, object>((Expression <Func <IDynamicMetaObjectProvider, object> >)(item => DataUtil.GetExpandoValue(item as ExpandoObject, property))).ToList <object>().Sum <object>((Func <object, double>)(value => Convert.ToDouble(value))));

                case "TrueCount":
                    List <WhereFilter> whereFilter2 = new List <WhereFilter>()
                    {
                        new WhereFilter()
                        {
                            Field    = property,
                            Operator = "equal",
                            value    = (object)true
                        }
                    };
                    return((object)DynamicObjectOperation.PerformFiltering(items, whereFilter2, (string)null).Count());

                default:
                    return((object)null);
                }
            }
            else
            {
                switch (str)
                {
                case "Average":
                    return(source1.Average(property));

                case "Count":
                    return((object)source1.Count());

                case "FalseCount":
                    return((object)source1.Where(property, (object)false, FilterType.Equals, false).Count());

                case "Max":
                    return(source1.Max(property));

                case "Min":
                    return(source1.Min(property));

                case "Sum":
                    return(source1.Sum(property));

                case "TrueCount":
                    return((object)source1.Where(property, (object)true, FilterType.Equals, false).Count());

                default:
                    return((object)null);
                }
            }
        });