コード例 #1
0
        public void LocalDataSourceProvider_Clones_Descriptions()
        {
            var engineMock = new PivotEngineMock();
            LocalDataSourceProvider provider = new LocalDataSourceProvider(engineMock);

            using (provider.DeferRefresh())
            {
                provider.AggregateDescriptions.Add(new ListAggregateDescription()
                {
                    PropertyName = "Item1"
                });

                provider.FilterDescriptions.Add(new PropertyFilterDescription()
                {
                    PropertyName = "Item1", Condition = new DelegateCondition((i) => Convert.ToInt32(i) % 3 != 0)
                });
                provider.SortDescriptions.Add(new PropertySortDescription()
                {
                    PropertyName = "Item1", SortOrder = SortOrder.Descending
                });
                provider.GroupDescriptions.Add(new PropertyGroupDescription()
                {
                    PropertyName = "Item2", SortOrder = SortOrder.Descending
                });
                provider.ItemsSource = Enumerable.Range(0, 10).Select(t => new Tuple <int, int>(t, t)).ToList();
            }

            engineMock.ActionOnRebuildCube = (state) =>
            {
                Assert.AreNotSame(provider.AggregateDescriptions[0], state.AggregateDescriptions[0]);
                Assert.AreNotSame(provider.FilterDescriptions[0], state.FilterDescriptions[0]);
                Assert.AreNotSame(provider.GroupDescriptions[0], state.RowGroupDescriptions[0]);

                SortFieldComparer fieldComparer = state.ValueProvider.GetSortComparer() as SortFieldComparer;
                SortFieldComparer.InternalTestHook testHelper = new SortFieldComparer.InternalTestHook(fieldComparer);
                Assert.AreNotSame(provider.SortDescriptions[0], testHelper.SortDescriptions[0]);
            };
        }
コード例 #2
0
        /// <summary>
        /// Handles adding an item into the collection, and applying sorting, filtering, grouping, paging.
        /// </summary>
        /// <param name="item">Item to insert in the collection</param>
        /// <param name="index">Index to insert item into</param>
        private void ProcessInsertToCollection(object item, int index)
        {
            // first check to see if it passes the filter
            if (this.Filter == null || this.PassesFilter(item))
            {
                if (this.SortDescriptions.Count > 0)
                {
                    // create the SortFieldComparer to use
                    SortFieldComparer sortFieldComparer = new SortFieldComparer(this.SortDescriptions);

                    // check if the item would be in sorted order if inserted into the specified index
                    // otherwise, calculate the correct sorted index
                    if (index < 0 || /* if item was not originally part of list */
                        (index > 0 && (sortFieldComparer.Compare(item, this.InternalItemAt(index - 1)) < 0)) || /* item has moved up in the list */
                        ((index < this.InternalList.Count - 1) && (sortFieldComparer.Compare(item, this.InternalItemAt(index)) > 0))) /* item has moved down in the list */
                    {
                        index = sortFieldComparer.FindInsertIndex(item, this._internalList);
                    }
                }

                // make sure that the specified insert index is within the valid range
                // otherwise, just add it to the end. the index can be set to an invalid
                // value if the item was originally not in the collection, on a different
                // page, or if it had been previously filtered out.
                if (index < 0 || index > this._internalList.Count)
                {
                    index = this._internalList.Count;
                }

                this._internalList.Insert(index, item);
            }
        }
コード例 #3
0
 private void ProcessInsertToCollection(object item, int index)
 {
     if ((this.Filter == null) || this.PassesFilter(item))
     {
         if (this.SortDescriptions.Count > 0)
         {
             SortFieldComparer comparer = new SortFieldComparer(this.SortDescriptions);
             if (((index < 0) || ((index > 0) && (comparer.Compare(item, this.InternalItemAt(index - 1)) < 0))) || ((index < (this.InternalList.Count - 1)) && (comparer.Compare(item, this.InternalItemAt(index)) > 0)))
             {
                 index = comparer.FindInsertIndex(item, this._internalList);
             }
         }
         if ((index < 0) || (index > this._internalList.Count))
         {
             index = this._internalList.Count;
         }
         this._internalList.Insert(index, item);
     }
 }
コード例 #4
0
        //------------------------------------------------------
        //
        //  Protected Methods
        //
        //------------------------------------------------------

        #region Protected Methods

        /// <summary>
        /// Re-create the view, using any <seealso cref="CollectionView.SortDescriptions"/> and/or <seealso cref="CollectionView.Filter"/>.
        /// </summary>
        protected override void RefreshOverride()
        {
            bool   wasEmpty                = IsEmpty;
            object oldCurrentItem          = CurrentItem;
            bool   oldIsCurrentAfterLast   = IsCurrentAfterLast;
            bool   oldIsCurrentBeforeFirst = IsCurrentBeforeFirst;
            int    oldCurrentPosition      = CurrentPosition;

            // force currency off the collection (gives user a chance to save dirty information)
            OnCurrentChanging();

            if (SortDescriptions.Count > 0 || Filter != null)
            {
                // filter the view list
                if (Filter == null)
                {
                    _viewList = new ArrayList(_rawList);
                }
                else
                {
                    // optimized for footprint: initialize to size 0 and let AL amortize cost of growth
                    _viewList = new ArrayList();
                    for (int k = 0; k < _rawList.Count; ++k)
                    {
                        if (Filter(_rawList[k]))
                        {
                            _viewList.Add(_rawList[k]);
                        }
                    }
                }

                // sort the view list
                if (_sort != null && _sort.Count > 0 && ViewCount > 0)
                {
                    SortFieldComparer.SortHelper(_viewList, new SortFieldComparer(_sort, Culture));
                }
            }
            else    // no sort or filter
            {
                _viewList = _rawList;
            }

            if (IsEmpty || oldIsCurrentBeforeFirst)
            {
                _MoveCurrentToPosition(-1);
            }
            else if (oldIsCurrentAfterLast)
            {
                _MoveCurrentToPosition(ViewCount);
            }
            else if (oldCurrentItem != null) // set currency back to old current item, or first if not found
            {
                int index = _viewList.IndexOf(oldCurrentItem);
                if (index < 0)
                {
                    index = 0;
                }
                _MoveCurrentToPosition(index);
            }

            ClearIsModified();
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            OnCurrentChanged();

            if (IsCurrentAfterLast != oldIsCurrentAfterLast)
            {
                OnPropertyChanged(IsCurrentAfterLastPropertyName);
            }

            if (IsCurrentBeforeFirst != oldIsCurrentBeforeFirst)
            {
                OnPropertyChanged(IsCurrentBeforeFirstPropertyName);
            }

            if (oldCurrentPosition != CurrentPosition)
            {
                OnPropertyChanged(CurrentPositionPropertyName);
            }

            if (oldCurrentItem != CurrentItem)
            {
                OnPropertyChanged(CurrentItemPropertyName);
            }
        }
コード例 #5
0
        // Token: 0x06007815 RID: 30741 RVA: 0x00223A18 File Offset: 0x00221C18
        protected override void RefreshOverride()
        {
            bool   isEmpty              = this.IsEmpty;
            object currentItem          = this.CurrentItem;
            bool   isCurrentAfterLast   = this.IsCurrentAfterLast;
            bool   isCurrentBeforeFirst = this.IsCurrentBeforeFirst;
            int    currentPosition      = this.CurrentPosition;

            base.OnCurrentChanging();
            if (this.SortDescriptions.Count > 0 || this.Filter != null)
            {
                if (this.Filter == null)
                {
                    this._viewList = new ArrayList(this._rawList);
                }
                else
                {
                    this._viewList = new ArrayList();
                    for (int i = 0; i < this._rawList.Count; i++)
                    {
                        if (this.Filter(this._rawList[i]))
                        {
                            this._viewList.Add(this._rawList[i]);
                        }
                    }
                }
                if (this._sort != null && this._sort.Count > 0 && this.ViewCount > 0)
                {
                    SortFieldComparer.SortHelper(this._viewList, new SortFieldComparer(this._sort, this.Culture));
                }
            }
            else
            {
                this._viewList = this._rawList;
            }
            if (this.IsEmpty || isCurrentBeforeFirst)
            {
                this._MoveCurrentToPosition(-1);
            }
            else if (isCurrentAfterLast)
            {
                this._MoveCurrentToPosition(this.ViewCount);
            }
            else if (currentItem != null)
            {
                int num = this._viewList.IndexOf(currentItem);
                if (num < 0)
                {
                    num = 0;
                }
                this._MoveCurrentToPosition(num);
            }
            this.ClearIsModified();
            this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            this.OnCurrentChanged();
            if (this.IsCurrentAfterLast != isCurrentAfterLast)
            {
                this.OnPropertyChanged("IsCurrentAfterLast");
            }
            if (this.IsCurrentBeforeFirst != isCurrentBeforeFirst)
            {
                this.OnPropertyChanged("IsCurrentBeforeFirst");
            }
            if (currentPosition != this.CurrentPosition)
            {
                this.OnPropertyChanged("CurrentPosition");
            }
            if (currentItem != this.CurrentItem)
            {
                this.OnPropertyChanged("CurrentItem");
            }
        }