예제 #1
0
        private IEnumerable <Element> CreateGroupFolderElements(Type interfaceType, DataFieldDescriptor dataFieldDescriptor, IQueryable queryable, EntityToken parentEntityToken, PropertyInfoValueCollection propertyInfoValueCollection)
        {
            PropertyInfo propertyInfo = interfaceType.GetPropertiesRecursively().Single(f => f.Name == dataFieldDescriptor.Name);

            foreach (object obj in queryable)
            {
                var entityToken = new DataGroupingProviderHelperEntityToken(TypeManager.SerializeType(interfaceType))
                {
                    Payload        = this.OnGetPayload(parentEntityToken),
                    GroupingValues = new Dictionary <string, object>()
                };

                foreach (var kvp in propertyInfoValueCollection.PropertyValues)
                {
                    entityToken.GroupingValues.Add(kvp.Key.Name, kvp.Value);
                }
                entityToken.GroupingValues.Add(propertyInfo.Name, obj);


                var element = new Element(_elementProviderContext.CreateElementHandle(entityToken));


                string label = obj?.ToString() ?? string.Format(_undefinedLabelValue, dataFieldDescriptor.Name);
                if (obj is DateTime dt)
                {
                    label = dt.ToString("yyyy-MM-dd");
                }

                if (obj != null && dataFieldDescriptor.ForeignKeyReferenceTypeName != null)
                {
                    Type refType = TypeManager.GetType(dataFieldDescriptor.ForeignKeyReferenceTypeName);

                    IData data = DataFacade.TryGetDataByUniqueKey(refType, obj); // Could be a newly added null field...

                    if (data != null)
                    {
                        label = data.GetLabel();
                    }
                }


                element.VisualData = new ElementVisualizedData
                {
                    Label       = label,
                    ToolTip     = label,
                    HasChildren = true,
                    Icon        = this.FolderClosedIcon,
                    OpenedIcon  = this.FolderOpenIcon
                };

                PropertyInfoValueCollection propertyInfoValueCollectionCopy = propertyInfoValueCollection.Clone();
                propertyInfoValueCollectionCopy.AddPropertyValue(propertyInfo, obj);

                yield return(this.OnAddActions(element, propertyInfoValueCollectionCopy));
            }
        }
        private IEnumerable <Element> GetGroupChildrenFolders(DataGroupingProviderHelperEntityToken groupEntityToken, Type interfaceType, Func <IData, bool> filter, DataFieldDescriptor groupingDataFieldDescriptor, PropertyInfoValueCollection propertyInfoValueCollection)
        {
            IQueryable        queryable          = GetFilteredData(interfaceType, filter);
            ExpressionBuilder expressionBuilder  = new ExpressionBuilder(interfaceType, queryable);
            PropertyInfo      selectPropertyInfo = interfaceType.GetPropertiesRecursively(f => f.Name == groupingDataFieldDescriptor.Name).Single();

            IQueryable resultQueryable = expressionBuilder.
                                         Where(propertyInfoValueCollection, true).
                                         OrderBy(selectPropertyInfo, true, groupingDataFieldDescriptor.TreeOrderingProfile.OrderDescending).
                                         Select(selectPropertyInfo, true).
                                         Distinct().
                                         CreateQuery();

            return(CreateGroupFolderElements(interfaceType, groupingDataFieldDescriptor, resultQueryable, groupEntityToken, propertyInfoValueCollection));
        }
        private EntityToken GetGroupingEntityTokenParent(DataGroupingProviderHelperEntityToken groupingEntityToken)
        {
            Type type = TypeManager.TryGetType(groupingEntityToken.Type);

            if (groupingEntityToken.GroupingValues.Count == 1)
            {
                return(OnGetRootParentEntityToken(type, groupingEntityToken));
            }

            var newGroupingParentEntityToken = new DataGroupingProviderHelperEntityToken(groupingEntityToken.Type);

            newGroupingParentEntityToken.Payload        = this.OnGetPayload(groupingEntityToken);
            newGroupingParentEntityToken.GroupingValues = new Dictionary <string, object>();
            foreach (var kvp in groupingEntityToken.GroupingValues.Take(groupingEntityToken.GroupingValues.Count - 1))
            {
                newGroupingParentEntityToken.GroupingValues.Add(kvp.Key, NormalizeGroupingValue(kvp.Value));
            }

            return(newGroupingParentEntityToken);
        }
예제 #4
0
        /// <exclude />
        public static EntityToken Deserialize(string serializedEntityToken)
        {
            string type, source, id;
            Dictionary <string, string> dic;

            DoDeserialize(serializedEntityToken, out type, out source, out id, out dic);

            var entityToken = new DataGroupingProviderHelperEntityToken(type);

            if (dic.ContainsKey("Payload"))
            {
                entityToken._payload = dic["Payload"];
            }

            entityToken.GroupingValues = new Dictionary <string, object>();

            Type dataType = TypeManager.GetType(type);

            List <PropertyInfo> propertyInfos = dataType.GetPropertiesRecursively();

            foreach (var kvp in dic)
            {
                PropertyInfo propertyInfo = propertyInfos.Where(f => f.Name == kvp.Key).SingleOrDefault();

                if (propertyInfo == null)
                {
                    continue;
                }

                object value = null;
                if (kvp.Value != _magicNullValue)
                {
                    value = StringConversionServices.DeserializeValue(kvp.Value, propertyInfo.PropertyType);
                }


                entityToken.GroupingValues.Add(kvp.Key, value);
            }

            return(entityToken);
        }
예제 #5
0
        private EntityToken GetDataEntityTokenParent(DataEntityToken dataEntityToken)
        {
            Type interfaceType = dataEntityToken.InterfaceType;

            if (!OnOwnsType(interfaceType))
            {
                return(null);
            }

            var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

            IEnumerable <DataFieldDescriptor> groupingDataFieldDescriptors =
                from dfd in dataTypeDescriptor.Fields
                where dfd.GroupByPriority != 0
                orderby dfd.GroupByPriority
                select dfd;

            if (!groupingDataFieldDescriptors.Any())
            {
                return(OnGetRootParentEntityToken(interfaceType, dataEntityToken));
            }

            IData data = dataEntityToken.Data;

            var parentToken = new DataGroupingProviderHelperEntityToken(dataEntityToken.Type)
            {
                Payload        = this.OnGetPayload(dataEntityToken),
                GroupingValues = new Dictionary <string, object>()
            };

            foreach (DataFieldDescriptor dfd in groupingDataFieldDescriptors)
            {
                PropertyInfo propertyInfo = interfaceType.GetPropertiesRecursively().Single(f => f.Name == dfd.Name);

                object value = propertyInfo.GetValue(data, null);
                parentToken.GroupingValues.Add(propertyInfo.Name, NormalizeGroupingValue(value));
            }

            return(parentToken);
        }
        public IEnumerable <Element> GetGroupChildren(DataGroupingProviderHelperEntityToken groupEntityToken, bool includeForeignFolders)
        {
            Type interfaceType = TypeManager.GetType(groupEntityToken.Type);

            var propertyInfoValueCollection = new PropertyInfoValueCollection();

            foreach (var kvp in groupEntityToken.GroupingValues)
            {
                PropertyInfo propertyInfo = interfaceType.GetPropertiesRecursively().Single(f => f.Name == kvp.Key);
                propertyInfoValueCollection.AddPropertyValue(propertyInfo, kvp.Value);
            }

            var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

            DataFieldDescriptor groupingDataFieldDescriptor =
                (from dfd in dataTypeDescriptor.Fields
                 where dfd.GroupByPriority == groupEntityToken.GroupingValues.Count + 1
                 select dfd).SingleOrDefault();

            if (groupingDataFieldDescriptor != null &&
                propertyInfoValueCollection.PropertyValues.Any(f => f.Key.Name == groupingDataFieldDescriptor.Name))
            {
                // Grouping ordering has ben changed, at the moment the best thing we can do its to return no elements
                // TODO: This class and the whole attach element provider stuff should be redone
                return(new Element[] { });
            }

            Func <IData, bool> filter = null;

            if (this.OnGetLeafsFilter != null)
            {
                filter = this.OnGetLeafsFilter(groupEntityToken);
            }

            using (new DataScope(this.OnGetDataScopeIdentifier(interfaceType)))
            {
                if (groupingDataFieldDescriptor != null)
                {
                    PropertyInfoValueCollection propertyInfoValueCol = propertyInfoValueCollection.Clone();
                    List <Element> elements = GetGroupChildrenFolders(groupEntityToken, interfaceType, filter, groupingDataFieldDescriptor, propertyInfoValueCol).ToList();

                    if (groupingDataFieldDescriptor.ForeignKeyReferenceTypeName != null)
                    {
                        elements = (groupingDataFieldDescriptor.TreeOrderingProfile.OrderDescending ?
                                    elements.OrderByDescending(f => f.VisualData.Label) :
                                    elements.OrderBy(f => f.VisualData.Label)).ToList();
                    }

                    if (includeForeignFolders)
                    {
                        using (new DataScope(UserSettings.ForeignLocaleCultureInfo))
                        {
                            PropertyInfoValueCollection foreignPropertyInfoValueCol = propertyInfoValueCollection.Clone();
                            elements.AddRange(GetGroupChildrenFolders(groupEntityToken, interfaceType, filter, groupingDataFieldDescriptor, foreignPropertyInfoValueCol));
                        }
                    }

                    return(elements.Distinct());
                }
                else
                {
                    PropertyInfoValueCollection propertyInfoValueCol = propertyInfoValueCollection.Clone();
                    List <Element> elements = GetGroupChildrenLeafs(interfaceType, filter, propertyInfoValueCol, false).ToList();

                    if (!dataTypeDescriptor.Fields.Any(f => f.TreeOrderingProfile.OrderPriority.HasValue && f.ForeignKeyReferenceTypeName == null))
                    {
                        var labelFieldDescriptor = dataTypeDescriptor.Fields.FirstOrDefault(f => f.Name == dataTypeDescriptor.LabelFieldName);
                        if (labelFieldDescriptor != null && labelFieldDescriptor.ForeignKeyReferenceTypeName != null)
                        {
                            elements = (labelFieldDescriptor.TreeOrderingProfile.OrderDescending ?
                                        elements.OrderByDescending(f => f.VisualData.Label) :
                                        elements.OrderBy(f => f.VisualData.Label)).ToList();
                        }
                    }

                    if (includeForeignFolders)
                    {
                        using (new DataScope(UserSettings.ForeignLocaleCultureInfo))
                        {
                            PropertyInfoValueCollection foreignPropertyInfoValueCol = propertyInfoValueCollection.Clone();
                            elements.AddRange(GetGroupChildrenLeafs(interfaceType, filter, foreignPropertyInfoValueCol, true));
                        }
                    }

                    return(elements.Distinct());
                }
            }
        }
 public IEnumerable <Element> GetGroupChildren(DataGroupingProviderHelperEntityToken groupEntityToken)
 {
     return(GetGroupChildren(groupEntityToken, false));
 }
        /// <exclude />
        public static EntityToken Deserialize(string serializedEntityToken)
        {
            string type, source, id;
            Dictionary<string, string> dic;

            DoDeserialize(serializedEntityToken, out type, out source, out id, out dic);

            var entityToken = new DataGroupingProviderHelperEntityToken(type);

            if (dic.ContainsKey("Payload"))
            {
                entityToken._payload = dic["Payload"];
            }            

            entityToken.GroupingValues = new Dictionary<string, object>();

            Type dataType = TypeManager.GetType(type);

            List<PropertyInfo> propertyInfos = dataType.GetPropertiesRecursively();
            foreach (var kvp in dic)
            {
                PropertyInfo propertyInfo = propertyInfos.Where(f => f.Name == kvp.Key).SingleOrDefault();

                if (propertyInfo == null) continue;

                object value = null;
                if (kvp.Value != _magicNullValue)
                {
                    value = StringConversionServices.DeserializeValue(kvp.Value, propertyInfo.PropertyType);
                }


                entityToken.GroupingValues.Add(kvp.Key, value);
            }

            return entityToken;
        }