void ISourceCollectionChangeProcessor.processSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                int         newIndex  = e.NewStartingIndex;
                TSourceItem addedItem = (TSourceItem)e.NewItems[0];
                registerSourceItem(addedItem, newIndex);
                break;

            case NotifyCollectionChangedAction.Remove:
                unregisterSourceItem(e.OldStartingIndex);
                break;

            case NotifyCollectionChangedAction.Replace:
                int         replacingSourceIndex = e.NewStartingIndex;
                TSourceItem replacingSourceItem  = (TSourceItem)e.NewItems[0];
                OrderingItemInfo <TOrderingValue> replacingItemInfo = _itemInfos[replacingSourceIndex];
                ExpressionWatcher oldExpressionWatcher = replacingItemInfo.ExpressionWatcher;

                Utils.disposeExpressionWatcher(oldExpressionWatcher, replacingItemInfo.NestedComputings, this,
                                               _orderingValueSelectorContainsParametrizedLiveLinqCalls);

                Utils.getItemInfoContent(
                    new object[] { replacingSourceItem },
                    out ExpressionWatcher newExpressionWatcher,
                    out Func <TOrderingValue> newGetOrderingValueFunc,
                    out List <IComputingInternal> nestedComputings,
                    _orderingValueSelectorExpression,
                    out _orderingValueSelectorExpressionCallCount,
                    this,
                    _orderingValueSelectorContainsParametrizedLiveLinqCalls,
                    _orderingValueSelectorExpressionInfo);

                replacingItemInfo.GetOrderingValueFunc           = newGetOrderingValueFunc;
                replacingItemInfo.ExpressionWatcher              = newExpressionWatcher;
                replacingItemInfo.ExpressionWatcher.ValueChanged = expressionWatcher_OnValueChanged;
                newExpressionWatcher._position     = oldExpressionWatcher._position;
                replacingItemInfo.NestedComputings = nestedComputings;

                baseSetItem(replacingItemInfo.OrderedItemInfo.Index, replacingSourceItem);
                processSourceItemChange(replacingSourceIndex, replacingSourceItem);
                break;

            case NotifyCollectionChangedAction.Move:
                int oldStartingIndex = e.OldStartingIndex;
                int newStartingIndex = e.NewStartingIndex;
                if (oldStartingIndex != newStartingIndex)
                {
                    _sourcePositions.Move(oldStartingIndex, newStartingIndex);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                processSource();
                break;
            }
        }
Beispiel #2
0
        void ISourceCollectionChangeProcessor.processSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            ItemInfo itemInfo;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                int         newStartingIndex = e.NewStartingIndex;
                TSourceItem addedItem        = (TSourceItem)e.NewItems[0];
                itemInfo = registerSourceItem(addedItem, newStartingIndex);
                baseInsertItem(newStartingIndex, applySelector(itemInfo, addedItem));
                break;

            case NotifyCollectionChangedAction.Remove:
                int oldStartingIndex = e.OldStartingIndex;
                unregisterSourceItem(oldStartingIndex);
                baseRemoveItem(oldStartingIndex);
                break;

            case NotifyCollectionChangedAction.Replace:
                int         newStartingIndex1 = e.NewStartingIndex;
                TSourceItem newItem           = (TSourceItem)e.NewItems[0];
                ItemInfo    replacingItemInfo = _itemInfos[newStartingIndex1];
                unregisterSourceItem(newStartingIndex1, true);
                itemInfo = registerSourceItem(newItem, newStartingIndex1, replacingItemInfo);
                baseSetItem(newStartingIndex1, applySelector(itemInfo, newItem));
                break;

            case NotifyCollectionChangedAction.Move:
                int oldStartingIndex2 = e.OldStartingIndex;
                int newStartingIndex2 = e.NewStartingIndex;
                if (oldStartingIndex2 != newStartingIndex2)
                {
                    _sourcePositions.Move(oldStartingIndex2, newStartingIndex2);
                    baseMoveItem(oldStartingIndex2, newStartingIndex2);
                }

                break;

            case NotifyCollectionChangedAction.Reset:
                processSource();
                break;
            }
        }
Beispiel #3
0
        internal static void ProcessMoveSourceItems <TSourceItem1>(int oldSourceIndex, int newSourceIndex1,
                                                                   List <FilteringItemInfo> filteringItemInfos, Positions <Position> filteredPositions,
                                                                   Positions <FilteringItemInfo> sourcePositions, CollectionComputing <TSourceItem1> current)
        {
            if (newSourceIndex1 != oldSourceIndex)
            {
                FilteringItemInfo itemInfoOfOldSourceIndex = filteringItemInfos[oldSourceIndex];
                FilteringItemInfo itemInfoOfNewSourceIndex = filteringItemInfos[newSourceIndex1];

                Position nextPosition1;

                Position itemInfoOfOldSourceIndexFilteredPosition         = itemInfoOfOldSourceIndex.FilteredPosition;
                Position itemInfoOfNewSourceIndexNextFilteredItemPosition = itemInfoOfNewSourceIndex.NextFilteredItemPosition;
                Position itemInfoOfNewSourceIndexFilteredPosition         = itemInfoOfNewSourceIndex.FilteredPosition;
                if (itemInfoOfOldSourceIndexFilteredPosition != null)
                {
                    int oldFilteredIndex = itemInfoOfOldSourceIndexFilteredPosition.Index;
                    int newFilteredIndex1;

                    Position newPosition1 = itemInfoOfOldSourceIndexFilteredPosition;
                    if (itemInfoOfNewSourceIndexFilteredPosition == null)
                    {
                        //nextPositionIndex = itemInfoOfNewSourceIndex.NextFilteredItemIndex;
                        nextPosition1 =
                            itemInfoOfNewSourceIndexNextFilteredItemPosition != itemInfoOfOldSourceIndexFilteredPosition
                                                                ? itemInfoOfNewSourceIndexNextFilteredItemPosition
                                                                : itemInfoOfOldSourceIndex.NextFilteredItemPosition;
                        newFilteredIndex1 = oldSourceIndex < newSourceIndex1
                                                        ? itemInfoOfNewSourceIndexNextFilteredItemPosition.Index - 1
                                                        : itemInfoOfNewSourceIndexNextFilteredItemPosition.Index;
                    }
                    else
                    {
                        nextPosition1 = oldSourceIndex < newSourceIndex1
                                                        ? itemInfoOfNewSourceIndexNextFilteredItemPosition
                                                        : itemInfoOfNewSourceIndexFilteredPosition;
                        newFilteredIndex1 = itemInfoOfNewSourceIndexFilteredPosition.Index;
                    }

                    filteredPositions.Move(
                        oldFilteredIndex,
                        newFilteredIndex1);

                    modifyNextFilteredItemIndex(oldSourceIndex,
                                                itemInfoOfOldSourceIndex.NextFilteredItemPosition, filteringItemInfos);

                    sourcePositions.Move(oldSourceIndex, newSourceIndex1);

                    itemInfoOfOldSourceIndex.NextFilteredItemPosition = nextPosition1;

                    modifyNextFilteredItemIndex(newSourceIndex1, newPosition1, filteringItemInfos);

                    current.baseMoveItem(oldFilteredIndex, newFilteredIndex1);
                }
                else
                {
                    nextPosition1 = oldSourceIndex < newSourceIndex1
                                                ? itemInfoOfNewSourceIndexNextFilteredItemPosition
                                                : (itemInfoOfNewSourceIndexFilteredPosition ?? itemInfoOfNewSourceIndexNextFilteredItemPosition);

                    itemInfoOfOldSourceIndex.NextFilteredItemPosition = nextPosition1;

                    sourcePositions.Move(oldSourceIndex, newSourceIndex1);
                }
            }
        }
		private void processSourceItemChange(int sourceIndex, TSourceItem sourceItem)
		{
			void notifyThenOrderings(int newOrderedIndex)
			{
				int processedThenOrderingsCount = 0;
				for (int thenOrderingIndex = 0; thenOrderingIndex < _thenOrderingsCount; thenOrderingIndex++)
				{
					IThenOrderingInternal<TSourceItem> thenOrdering = _thenOrderings[thenOrderingIndex];
                    thenOrdering.ProcessSourceItemChange(newOrderedIndex, sourceItem);
                    processedThenOrderingsCount++;
                    if (processedThenOrderingsCount == _thenOrderingsCount) break;
				}
			}

			OrderingItemInfo<TOrderingValue> itemInfo = _itemInfos[sourceIndex];
			OrderedItemInfo<TOrderingValue> orderedItemInfo = itemInfo.OrderedItemInfo;
			int orderedIndex = orderedItemInfo.Index;
            TOrderingValue orderingValue = getOrderingValue(itemInfo, sourceItem);

			if (_comparer.Compare(_orderingValues[orderedIndex], orderingValue) != 0)
			{
				int newOrderedIndex = getOrderedIndex(orderingValue);
				if (newOrderedIndex == Count)
					newOrderedIndex = newOrderedIndex - 1;
				else if (newOrderedIndex > orderedIndex) newOrderedIndex--;

				_orderingValues.RemoveAt(orderedIndex);
				_orderingValues.Insert(newOrderedIndex, orderingValue);

				_orderedPositions.Move(orderedIndex, newOrderedIndex);

				if (_thenOrderingsCount > 0)
				{
					RangePosition rangePosition = orderedItemInfo.RangePosition;
					if (rangePosition.Length == 1)
						_equalOrderingValueRangePositions.Remove(rangePosition.Index);
					else
						_equalOrderingValueRangePositions.ModifyLength(rangePosition.Index, -1);

					adjustEqualOrderingValueRangePosition(
						orderingValue, 
						orderedItemInfo, 
						newOrderedIndex,
						orderedIndex < newOrderedIndex ? newOrderedIndex : newOrderedIndex - 1,
						orderedIndex > newOrderedIndex ? newOrderedIndex : newOrderedIndex + 1);
				}

				if (orderedIndex != newOrderedIndex)
				{
					baseMoveItem(orderedIndex, newOrderedIndex);
				}
				else if (_thenOrderingsCount > 0)
				{
					notifyThenOrderings(newOrderedIndex);
				}
			}
			else if (_thenOrderingsCount > 0)
			{
				notifyThenOrderings(orderedIndex);
			}
		}
        private void handleSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            checkConsistent(sender, e);
            if (!_rootSourceWrapper && _lastProcessedSourceChangeMarker == _sourceAsList.ChangeMarkerField)
            {
                return;
            }

            _handledEventSender = sender;
            _handledEventArgs   = e;

            _lastProcessedSourceChangeMarker = !_lastProcessedSourceChangeMarker;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                _isConsistent = false;
                int         newSourceIndex  = e.NewStartingIndex;
                TSourceItem addedSourceItem = _sourceAsList[newSourceIndex];
                ItemInfo    itemInfo        = registerSourceItem(addedSourceItem, newSourceIndex);
                if (ApplyPredicate(newSourceIndex))
                {
                    _predicatePassedCount++;
                    itemInfo.PredicateResult = true;
                }

                calculateValue();
                _isConsistent = true;
                raiseConsistencyRestored();
                break;

            case NotifyCollectionChangedAction.Remove:
                int oldStartingIndex = e.OldStartingIndex;
                if (_itemInfos[oldStartingIndex].PredicateResult)
                {
                    _predicatePassedCount--;
                }
                unregisterSourceItem(oldStartingIndex);
                calculateValue();
                break;

            case NotifyCollectionChangedAction.Move:
                int newSourceIndex1 = e.NewStartingIndex;
                int oldSourceIndex  = e.OldStartingIndex;

                if (newSourceIndex1 != oldSourceIndex)
                {
                    _sourcePositions.Move(oldSourceIndex, newSourceIndex1);
                }

                break;

            case NotifyCollectionChangedAction.Reset:
                _isConsistent = false;
                initializeFromSource();
                _isConsistent = true;
                raiseConsistencyRestored();
                break;

            case NotifyCollectionChangedAction.Replace:
                _isConsistent = false;
                int               newStartingIndex     = e.NewStartingIndex;
                ItemInfo          replacingItemInfo    = _itemInfos[newStartingIndex];
                ExpressionWatcher oldExpressionWatcher = replacingItemInfo.ExpressionWatcher;
                oldExpressionWatcher.Dispose();
                if (replacingItemInfo.PredicateResult)
                {
                    _predicatePassedCount--;
                }

                ExpressionWatcher watcher;
                Func <bool>       predicateFunc;
                TSourceItem       replacingSourceItem = _sourceAsList[newStartingIndex];
                getNewExpressionWatcherAndPredicateFunc(replacingSourceItem, out watcher, out predicateFunc);
                replacingItemInfo.PredicateFunc = predicateFunc;
                watcher.ValueChanged            = expressionWatcher_OnValueChanged;
                watcher._position = oldExpressionWatcher._position;
                replacingItemInfo.ExpressionWatcher = watcher;

                if (ApplyPredicate(newStartingIndex))
                {
                    _predicatePassedCount++;
                    replacingItemInfo.PredicateResult = true;
                }
                else
                {
                    replacingItemInfo.PredicateResult = false;
                }

                calculateValue();
                _isConsistent = true;
                raiseConsistencyRestored();
                break;
            }

            _isConsistent = false;
            if (_deferredExpressionWatcherChangedProcessings != null)
            {
                while (_deferredExpressionWatcherChangedProcessings.Count > 0)
                {
                    ExpressionWatcher.Raise expressionWatcherRaise = _deferredExpressionWatcherChangedProcessings.Dequeue();
                    if (!expressionWatcherRaise.ExpressionWatcher._disposed)
                    {
                        _handledEventSender = expressionWatcherRaise.EventSender;
                        _handledEventArgs   = expressionWatcherRaise.EventArgs;
                        processExpressionWatcherValueChanged(expressionWatcherRaise.ExpressionWatcher);
                    }
                }
            }

            _isConsistent = true;
            raiseConsistencyRestored();

            _handledEventSender = null;
            _handledEventArgs   = null;
        }
Beispiel #6
0
        private void handleSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            checkConsistent(sender, e);
            if (!_rootSourceWrapper && _lastProcessedSourceChangeMarker == _sourceAsList.ChangeMarkerField)
            {
                return;
            }

            _handledEventSender = sender;
            _handledEventArgs   = e;

            _lastProcessedSourceChangeMarker = !_lastProcessedSourceChangeMarker;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                _isConsistent = false;
                int         newSourceIndex  = e.NewStartingIndex;
                TSourceItem addedSourceItem = _sourceAsList[newSourceIndex];
                Position    newItemPosition = null;
                Position    nextItemPosition;

                int?newFilteredIndex = null;

                getNewExpressionWatcherAndPredicateFunc(addedSourceItem, out ExpressionWatcher newWatcher, out Func <bool> newPredicateFunc);

                if (newSourceIndex < _itemInfos.Count)
                {
                    ItemInfo oldItemInfo = _itemInfos[newSourceIndex];

                    Position oldItemInfoNextFilteredItemPosition = oldItemInfo.NextFilteredItemPosition;
                    Position oldItemInfoFilteredPosition         = oldItemInfo.FilteredPosition;
                    if (applyPredicate(addedSourceItem, newPredicateFunc))
                    {
                        if (oldItemInfoFilteredPosition == null)
                        {
                            newItemPosition  = _filteredPositions.Insert(oldItemInfoNextFilteredItemPosition.Index);
                            nextItemPosition = oldItemInfoNextFilteredItemPosition;
                            newFilteredIndex = newItemPosition.Index;
                        }
                        else
                        {
                            int filteredIndex = oldItemInfoFilteredPosition.Index;
                            newFilteredIndex = filteredIndex;
                            newItemPosition  = _filteredPositions.Insert(filteredIndex);
                            nextItemPosition = oldItemInfoFilteredPosition;
                        }

                        modifyNextFilteredItemIndex(newSourceIndex, newItemPosition);
                    }
                    else
                    {
                        nextItemPosition = oldItemInfoFilteredPosition ?? oldItemInfoNextFilteredItemPosition;
                    }
                }
                else
                {
                    if (applyPredicate(addedSourceItem, newPredicateFunc))
                    {
                        newItemPosition  = _filteredPositions.List[Count];
                        newFilteredIndex = Count;
                        nextItemPosition = _filteredPositions.Add();
                    }
                    else
                    {
                        //здесь newPositionIndex = null; так и должно быть
                        nextItemPosition = _filteredPositions.List[Count];
                    }
                }

                registerSourceItem(addedSourceItem, newSourceIndex, newItemPosition, nextItemPosition, newWatcher, newPredicateFunc);

                if (newFilteredIndex != null)
                {
                    baseInsertItem(newFilteredIndex.Value, addedSourceItem);
                }

                _isConsistent = true;
                raiseConsistencyRestored();
                break;

            case NotifyCollectionChangedAction.Remove:
                unregisterSourceItem(e.OldStartingIndex);
                break;

            case NotifyCollectionChangedAction.Move:
                _isConsistent = false;
                int newSourceIndex1 = e.NewStartingIndex;
                int oldSourceIndex  = e.OldStartingIndex;

                if (newSourceIndex1 != oldSourceIndex)
                {
                    ItemInfo itemInfoOfOldSourceIndex = _itemInfos[oldSourceIndex];
                    ItemInfo itemInfoOfNewSourceIndex = _itemInfos[newSourceIndex1];

                    Position newPosition1;
                    Position nextPosition1;

                    Position itemInfoOfOldSourceIndexFilteredPosition         = itemInfoOfOldSourceIndex.FilteredPosition;
                    Position itemInfoOfNewSourceIndexNextFilteredItemPosition = itemInfoOfNewSourceIndex.NextFilteredItemPosition;
                    Position itemInfoOfNewSourceIndexFilteredPosition         = itemInfoOfNewSourceIndex.FilteredPosition;
                    if (itemInfoOfOldSourceIndexFilteredPosition != null)
                    {
                        int oldFilteredIndex = itemInfoOfOldSourceIndexFilteredPosition.Index;
                        int newFilteredIndex1;

                        newPosition1 = itemInfoOfOldSourceIndexFilteredPosition;
                        if (itemInfoOfNewSourceIndexFilteredPosition == null)
                        {
                            //nextPositionIndex = itemInfoOfNewSourceIndex.NextFilteredItemIndex;
                            nextPosition1 =
                                itemInfoOfNewSourceIndexNextFilteredItemPosition != itemInfoOfOldSourceIndexFilteredPosition
                                                                                ? itemInfoOfNewSourceIndexNextFilteredItemPosition
                                                                                : itemInfoOfOldSourceIndex.NextFilteredItemPosition;
                            newFilteredIndex1 = oldSourceIndex < newSourceIndex1 ?
                                                itemInfoOfNewSourceIndexNextFilteredItemPosition.Index - 1 :
                                                itemInfoOfNewSourceIndexNextFilteredItemPosition.Index;
                        }
                        else
                        {
                            nextPosition1 = oldSourceIndex < newSourceIndex1 ?
                                            itemInfoOfNewSourceIndexNextFilteredItemPosition :
                                            itemInfoOfNewSourceIndexFilteredPosition;
                            newFilteredIndex1 = itemInfoOfNewSourceIndexFilteredPosition.Index;
                        }

                        _filteredPositions.Move(
                            oldFilteredIndex,
                            newFilteredIndex1);

                        modifyNextFilteredItemIndex(oldSourceIndex, itemInfoOfOldSourceIndex.NextFilteredItemPosition);

                        _sourcePositions.Move(oldSourceIndex, newSourceIndex1);

                        itemInfoOfOldSourceIndex.NextFilteredItemPosition = nextPosition1;

                        modifyNextFilteredItemIndex(newSourceIndex1, newPosition1);

                        baseMoveItem(oldFilteredIndex, newFilteredIndex1);
                    }
                    else
                    {
                        nextPosition1 = oldSourceIndex < newSourceIndex1
                                                                ? itemInfoOfNewSourceIndexNextFilteredItemPosition
                                                                : (itemInfoOfNewSourceIndexFilteredPosition ?? itemInfoOfNewSourceIndexNextFilteredItemPosition);

                        itemInfoOfOldSourceIndex.NextFilteredItemPosition = nextPosition1;

                        _sourcePositions.Move(oldSourceIndex, newSourceIndex1);
                    }
                }
                _isConsistent = true;
                raiseConsistencyRestored();
                break;

            case NotifyCollectionChangedAction.Reset:
                _isConsistent = false;
                initializeFromSource();
                _isConsistent = true;
                raiseConsistencyRestored();
                break;

            case NotifyCollectionChangedAction.Replace:
                _isConsistent = false;
                int               sourceIndex          = e.NewStartingIndex;
                ItemInfo          replacingItemInfo    = _itemInfos[sourceIndex];
                ExpressionWatcher oldExpressionWatcher = replacingItemInfo.ExpressionWatcher;
                oldExpressionWatcher.Dispose();

                ExpressionWatcher watcher;
                Func <bool>       predicateFunc;
                TSourceItem       replacingSourceItem = _sourceAsList[sourceIndex];
                getNewExpressionWatcherAndPredicateFunc(replacingSourceItem, out watcher, out predicateFunc);
                replacingItemInfo.PredicateFunc = predicateFunc;
                watcher.ValueChanged            = expressionWatcher_OnValueChanged;
                watcher._position = oldExpressionWatcher._position;
                replacingItemInfo.ExpressionWatcher = watcher;

                if (!processChangeSourceItem(sourceIndex) && replacingItemInfo.FilteredPosition != null)
                {
                    baseSetItem(replacingItemInfo.FilteredPosition.Index, replacingSourceItem);
                }
                _isConsistent = true;
                raiseConsistencyRestored();
                break;
            }

            _isConsistent = false;
            if (_deferredExpressionWatcherChangedProcessings != null)
            {
                while (_deferredExpressionWatcherChangedProcessings.Count > 0)
                {
                    ExpressionWatcher.Raise expressionWatcherRaise = _deferredExpressionWatcherChangedProcessings.Dequeue();
                    if (!expressionWatcherRaise.ExpressionWatcher._disposed)
                    {
                        _handledEventSender = expressionWatcherRaise.EventSender;
                        _handledEventArgs   = expressionWatcherRaise.EventArgs;
                        processChangeSourceItem(expressionWatcherRaise.ExpressionWatcher._position.Index);
                    }
                }
            }

            _isConsistent = true;
            raiseConsistencyRestored();

            _handledEventSender = null;
            _handledEventArgs   = null;
        }
        private void handleSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            checkConsistent(sender, e);
            if (!_rootSourceWrapper && _lastProcessedSourceChangeMarker == _sourceAsList.ChangeMarkerField)
            {
                return;
            }

            _handledEventSender = sender;
            _handledEventArgs   = e;

            _lastProcessedSourceChangeMarker = !_lastProcessedSourceChangeMarker;

            ItemInfo itemInfo;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                _isConsistent = false;
                int         newStartingIndex = e.NewStartingIndex;
                TSourceItem addedItem        = _sourceAsList[newStartingIndex];
                itemInfo = registerSourceItem(addedItem, newStartingIndex);
                baseInsertItem(newStartingIndex, applySelector(itemInfo, addedItem));
                _isConsistent = true;
                raiseConsistencyRestored();
                break;

            case NotifyCollectionChangedAction.Remove:
                int oldStartingIndex = e.OldStartingIndex;
                unregisterSourceItem(oldStartingIndex);
                baseRemoveItem(oldStartingIndex);
                break;

            case NotifyCollectionChangedAction.Replace:
                _isConsistent = false;
                int         newStartingIndex1 = e.NewStartingIndex;
                TSourceItem newItem           = _sourceAsList[newStartingIndex1];
                ItemInfo    replacingItemInfo = _itemInfos[newStartingIndex1];
                unregisterSourceItem(newStartingIndex1, true);
                itemInfo = registerSourceItem(newItem, newStartingIndex1, replacingItemInfo);
                baseSetItem(newStartingIndex1, applySelector(itemInfo, newItem));
                _isConsistent = true;
                raiseConsistencyRestored();
                break;

            case NotifyCollectionChangedAction.Move:
                int oldStartingIndex2 = e.OldStartingIndex;
                int newStartingIndex2 = e.NewStartingIndex;
                if (oldStartingIndex2 != newStartingIndex2)
                {
                    _sourcePositions.Move(oldStartingIndex2, newStartingIndex2);
                    baseMoveItem(oldStartingIndex2, newStartingIndex2);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                _isConsistent = false;
                initializeFromSource();
                _isConsistent = true;
                raiseConsistencyRestored();
                break;
            }

            _isConsistent = false;
            if (_deferredExpressionWatcherChangedProcessings != null)
            {
                while (_deferredExpressionWatcherChangedProcessings.Count > 0)
                {
                    ExpressionWatcher.Raise expressionWatcherRaise = _deferredExpressionWatcherChangedProcessings.Dequeue();
                    if (!expressionWatcherRaise.ExpressionWatcher._disposed)
                    {
                        _handledEventSender = expressionWatcherRaise.EventSender;
                        _handledEventArgs   = expressionWatcherRaise.EventArgs;
                        processExpressionWatcherValueChanged(expressionWatcherRaise.ExpressionWatcher);
                    }
                }
            }

            _isConsistent = true;
            raiseConsistencyRestored();

            _handledEventSender = null;
            _handledEventArgs   = null;
        }
Beispiel #8
0
        void ISourceCollectionChangeProcessor.processSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:

                int         newSourceIndex  = e.NewStartingIndex;
                TSourceItem addedSourceItem = (TSourceItem)e.NewItems[0];
                ItemInfo    itemInfo        = registerSourceItem(addedSourceItem, newSourceIndex);
                if (applyPredicate(addedSourceItem, itemInfo.PredicateFunc))
                {
                    _predicatePassedCount++;
                    itemInfo.PredicateResult = true;
                }

                calculateValue();
                break;

            case NotifyCollectionChangedAction.Remove:
                int oldStartingIndex = e.OldStartingIndex;
                if (_itemInfos[oldStartingIndex].PredicateResult)
                {
                    _predicatePassedCount--;
                }
                unregisterSourceItem(oldStartingIndex);
                calculateValue();
                break;

            case NotifyCollectionChangedAction.Move:
                int newSourceIndex1 = e.NewStartingIndex;
                int oldSourceIndex  = e.OldStartingIndex;

                if (newSourceIndex1 != oldSourceIndex)
                {
                    _sourcePositions.Move(oldSourceIndex, newSourceIndex1);
                }

                break;

            case NotifyCollectionChangedAction.Reset:
                initializeFromSource();
                break;

            case NotifyCollectionChangedAction.Replace:
                int               newStartingIndex     = e.NewStartingIndex;
                ItemInfo          replacingItemInfo    = _itemInfos[newStartingIndex];
                ExpressionWatcher oldExpressionWatcher = replacingItemInfo.ExpressionWatcher;
                Utils.disposeExpressionWatcher(oldExpressionWatcher, replacingItemInfo.NestedComputings, this,
                                               _predicateContainsParametrizedObservableComputationCalls);

                if (replacingItemInfo.PredicateResult)
                {
                    _predicatePassedCount--;
                }

                ExpressionWatcher watcher;
                Func <bool>       predicateFunc;
                TSourceItem       replacingSourceItem = (TSourceItem)e.NewItems[0];
                Utils.getItemInfoContent(
                    new object[] { replacingSourceItem },
                    out watcher,
                    out predicateFunc,
                    out List <IComputingInternal> nestedComputings1,
                    _predicateExpression,
                    out _predicateExpressionСallCount,
                    this,
                    _predicateContainsParametrizedObservableComputationCalls,
                    _predicateExpressionInfo);

                replacingItemInfo.PredicateFunc = predicateFunc;
                watcher.ValueChanged            = expressionWatcher_OnValueChanged;
                watcher._position = oldExpressionWatcher._position;
                replacingItemInfo.ExpressionWatcher = watcher;
                replacingItemInfo.NestedComputings  = nestedComputings1;

                if (applyPredicate(replacingSourceItem, predicateFunc))
                {
                    _predicatePassedCount++;
                    replacingItemInfo.PredicateResult = true;
                }
                else
                {
                    replacingItemInfo.PredicateResult = false;
                }

                calculateValue();
                break;
            }
        }