/// <summary>
        /// Initializes a new instance of the <see cref="FilterCollectionManager"/> class.
        /// </summary>
        /// <param name="sourceCollection">The collection of <see cref="FilterDescriptor"/>s to manage</param>
        /// <param name="expressionCache">The cache with entries for the <see cref="FilterDescriptor"/>s</param>
        /// <param name="validationAction">The callback for validating items that are added or changed</param>
        public FilterCollectionManager(FilterDescriptorCollection sourceCollection, ExpressionCache expressionCache, Action <FilterDescriptor> validationAction)
        {
            if (sourceCollection == null)
            {
                throw new ArgumentNullException("sourceCollection");
            }
            if (expressionCache == null)
            {
                throw new ArgumentNullException("expressionCache");
            }
            if (validationAction == null)
            {
                throw new ArgumentNullException("validationAction");
            }

            this.ExpressionCache              = expressionCache;
            this._sourceCollection            = sourceCollection;
            this.ValidationAction             = (item) => validationAction((FilterDescriptor)item);
            this.AsINotifyPropertyChangedFunc = (item) => ((FilterDescriptor)item).Notifier;

            this.AddCollection(this._sourceCollection);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SortCollectionManager"/> class.
        /// </summary>
        /// <param name="sourceCollection">The collection of <see cref="SortDescriptor"/>s to manage</param>
        /// <param name="descriptionCollection">The collection of <see cref="SortDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param>
        /// <param name="expressionCache">The cache with entries for the <see cref="SortDescriptor"/>s</param>
        /// <param name="validationAction">The callback for validating items that are added or changed</param>
        public SortCollectionManager(SortDescriptorCollection sourceCollection, SortDescriptionCollection descriptionCollection, ExpressionCache expressionCache, Action <SortDescriptor> validationAction)
        {
            if (sourceCollection == null)
            {
                throw new ArgumentNullException("sourceCollection");
            }
            if (descriptionCollection == null)
            {
                throw new ArgumentNullException("descriptionCollection");
            }
            if (expressionCache == null)
            {
                throw new ArgumentNullException("expressionCache");
            }
            if (validationAction == null)
            {
                throw new ArgumentNullException("validationAction");
            }

            this._sourceCollection            = sourceCollection;
            this._descriptionCollection       = descriptionCollection;
            this.ExpressionCache              = expressionCache;
            this.ValidationAction             = (item) => validationAction((SortDescriptor)item);
            this.AsINotifyPropertyChangedFunc = (item) => ((SortDescriptor)item).Notifier;

            ((INotifyCollectionChanged)descriptionCollection).CollectionChanged += this.HandleDescriptionCollectionChanged;

            this.AddCollection(sourceCollection);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GroupCollectionManager"/> class.
        /// </summary>
        /// <param name="sourceCollection">The collection of <see cref="GroupDescriptor"/>s to manage</param>
        /// <param name="descriptionCollection">The collection of <see cref="GroupDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param>
        /// <param name="expressionCache">The cache with entries for the <see cref="GroupDescriptor"/>s</param>
        /// <param name="validationAction">The callback for validating items that are added or changed</param>
        public GroupCollectionManager(GroupDescriptorCollection sourceCollection, ObservableCollection <GroupDescription> descriptionCollection, ExpressionCache expressionCache, Action <GroupDescriptor> validationAction)
        {
            if (sourceCollection == null)
            {
                throw new ArgumentNullException("sourceCollection");
            }
            if (descriptionCollection == null)
            {
                throw new ArgumentNullException("descriptionCollection");
            }
            if (expressionCache == null)
            {
                throw new ArgumentNullException("expressionCache");
            }
            if (validationAction == null)
            {
                throw new ArgumentNullException("validationAction");
            }

            this._sourceCollection      = sourceCollection;
            this._descriptionCollection = descriptionCollection;
            this.ExpressionCache        = expressionCache;
            this._groupValidationAction = validationAction;

            this.ValidationAction             = this.Validate;
            this.AsINotifyPropertyChangedFunc = this.AsINotifyPropertyChanged;

            this.AddCollection(sourceCollection);
            this.AddCollection(descriptionCollection);
        }
Example #4
0
        /// <summary>
        /// Composes an <see cref="EntityQuery" /> for sorting and grouping purposes.
        /// </summary>
        /// <param name="source">The queryable source.</param>
        /// <param name="groupDescriptors">The group descriptors.</param>
        /// <param name="sortDescriptors">The sort descriptors.</param>
        /// <param name="expressionCache">Cache for storing built expressions</param>
        /// <returns>The composed <see cref="EntityQuery" />.</returns>
        public static EntityQuery OrderBy(
            EntityQuery source,
            GroupDescriptorCollection groupDescriptors,
            SortDescriptorCollection sortDescriptors,
            ExpressionCache expressionCache)
        {
            Debug.Assert(source != null, "Unexpected null source");
            Debug.Assert(sortDescriptors != null, "Unexpected null sortDescriptors");
            Debug.Assert(groupDescriptors != null, "Unexpected null groupDescriptors");

            bool hasOrderBy = false;

            // check the GroupDescriptors first
            foreach (GroupDescriptor groupDescriptor in groupDescriptors)
            {
                if (groupDescriptor != null && groupDescriptor.PropertyPath != null)
                {
                    Debug.Assert(expressionCache.ContainsKey(groupDescriptor), "There should be a cached group expression");

                    // check to see if we sort by the same parameter in desc order
                    bool sortAsc = true;
                    foreach (SortDescriptor sortDescriptor in sortDescriptors)
                    {
                        if (sortDescriptor != null)
                        {
                            string sortDescriptorPropertyPath  = sortDescriptor.PropertyPath;
                            string groupDescriptorPropertyPath = groupDescriptor.PropertyPath;

                            if (sortDescriptorPropertyPath != null &&
                                sortDescriptorPropertyPath.Equals(groupDescriptorPropertyPath))
                            {
                                if (sortDescriptor.Direction == ListSortDirection.Descending)
                                {
                                    sortAsc = false;
                                }

                                break;
                            }
                        }
                    }

                    string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy");
                    if (!sortAsc)
                    {
                        orderMethodName += "Descending";
                    }

                    source     = OrderBy(source, orderMethodName, expressionCache[groupDescriptor]);
                    hasOrderBy = true;
                }
            }

            // then check the SortDescriptors
            foreach (SortDescriptor sortDescriptor in sortDescriptors)
            {
                if (sortDescriptor != null)
                {
                    Debug.Assert(expressionCache.ContainsKey(sortDescriptor), "There should be a cached sort expression");

                    string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy");
                    if (sortDescriptor.Direction == ListSortDirection.Descending)
                    {
                        orderMethodName += "Descending";
                    }

                    source     = OrderBy(source, orderMethodName, expressionCache[sortDescriptor]);
                    hasOrderBy = true;
                }
            }

            return(source);
        }