コード例 #1
0
        internal static Position processAddSourceItem(int newSourceIndex, bool predicateValue, ref Position newItemPosition,
                                                      ref int?newFilteredIndex, List <FilteringItemInfo> filteringItemInfos, Positions <Position> filteredPositions, int count)
        {
            Position nextItemPosition;

            if (newSourceIndex < filteringItemInfos.Count)
            {
                FilteringItemInfo oldItemInfo = filteringItemInfos[newSourceIndex];

                Position oldItemInfoNextFilteredItemPosition = oldItemInfo.NextFilteredItemPosition;
                Position oldItemInfoFilteredPosition         = oldItemInfo.FilteredPosition;
                if (predicateValue)
                {
                    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, filteringItemInfos);
                }
                else
                {
                    nextItemPosition = oldItemInfoFilteredPosition ?? oldItemInfoNextFilteredItemPosition;
                }
            }
            else
            {
                if (predicateValue)
                {
                    newItemPosition  = filteredPositions.List[count];
                    newFilteredIndex = count;
                    nextItemPosition = filteredPositions.Add();
                }
                else
                {
                    //здесь newPositionIndex = null; так и должно быть
                    nextItemPosition = filteredPositions.List[count];
                }
            }

            return(nextItemPosition);
        }
コード例 #2
0
        private ItemInfo registerSourceItem(TSourceItem sourceItem, int index, ItemInfo itemInfo = null)
        {
            itemInfo = itemInfo == null?_sourcePositions.Insert(index) : _itemInfos[index];

            ExpressionWatcher watcher;

            if (!_selectorContainsParametrizedObservableComputationsCalls)
            {
                watcher = new ExpressionWatcher(_selectorExpressionInfo, sourceItem);
            }
            else
            {
                Expression <Func <TResultItem> > deparametrizedSelectorExpression =
                    (Expression <Func <TResultItem> >)_selectorExpression.ApplyParameters(new object[] { sourceItem });
                Expression <Func <TResultItem> > selectorExpression =
                    (Expression <Func <TResultItem> >)
                    new CallToConstantConverter().Visit(deparametrizedSelectorExpression);
                // ReSharper disable once PossibleNullReferenceException
                itemInfo.SelectorFunc = selectorExpression.Compile();
                watcher = new ExpressionWatcher(ExpressionWatcher.GetExpressionInfo(selectorExpression));
            }

            watcher.ValueChanged       = expressionWatcher_OnValueChanged;
            itemInfo.ExpressionWatcher = watcher;
            watcher._position          = itemInfo;

            return(itemInfo);
        }
コード例 #3
0
        private FilteringItemInfo registerSourceItem(TSourceItem sourceItem, int sourceIndex, Position position,
                                                     Position nextItemPosition, ExpressionWatcher watcher = null, Func <bool> predicateFunc = null,
                                                     List <IComputingInternal> nestedComputings           = null)
        {
            FilteringItemInfo itemInfo = _sourcePositions.Insert(sourceIndex);

            itemInfo.FilteredPosition         = position;
            itemInfo.NextFilteredItemPosition = nextItemPosition;

            if (watcher == null /*&& predicateFunc == null*/)
            {
                Utils.getItemInfoContent(
                    new object[] { sourceItem },
                    out watcher,
                    out predicateFunc,
                    out nestedComputings,
                    _predicateExpression,
                    out _predicateExpressionCallCount,
                    this,
                    _predicateContainsParametrizedObservableComputationsCalls,
                    _predicateExpressionInfo);
            }

            itemInfo.PredicateFunc     = predicateFunc;
            watcher.ValueChanged       = _thisAsFiltering.expressionWatcher_OnValueChanged;
            watcher._position          = itemInfo;
            itemInfo.ExpressionWatcher = watcher;
            itemInfo.NestedComputings  = nestedComputings;

            return(itemInfo);
        }
コード例 #4
0
        private ItemInfo registerSourceItem(TSourceItem sourceItem, int index, ItemInfo itemInfo = null)
        {
            itemInfo = itemInfo == null?_sourcePositions.Insert(index) : _itemInfos[index];

            ExpressionWatcher watcher;

            Utils.getItemInfoContent(
                new object[] { sourceItem },
                out watcher,
                out Func <TResultItem> predicateFunc,
                out List <IComputingInternal> nestedComputings,
                _selectorExpression,
                out _selectorExpressionСallCount,
                this,
                _selectorContainsParametrizedObservableComputationsCalls,
                _selectorExpressionInfo);

            itemInfo.SelectorFunc      = predicateFunc;
            itemInfo.NestedComputings  = nestedComputings;
            watcher.ValueChanged       = expressionWatcher_OnValueChanged;
            itemInfo.ExpressionWatcher = watcher;
            watcher._position          = itemInfo;

            return(itemInfo);
        }
コード例 #5
0
        private ItemInfo registerSourceItem(TSourceItem sourceItem, int sourceIndex)
        {
            ItemInfo itemInfo = _sourcePositions.Insert(sourceIndex);

            getNewExpressionWatcherAndPredicateFunc(sourceItem, out ExpressionWatcher watcher, out Func <bool> predicateFunc);

            itemInfo.PredicateFunc     = predicateFunc;
            watcher.ValueChanged       = expressionWatcher_OnValueChanged;
            watcher._position          = itemInfo;
            itemInfo.ExpressionWatcher = watcher;
            return(itemInfo);
        }
コード例 #6
0
        private void registerSourceItem(TSourceItem sourceItem, int sourceIndex, bool initializing = false)
        {
            OrderingItemInfo <TOrderingValue> itemInfo = _sourcePositions.Insert(sourceIndex);

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

            itemInfo.GetOrderingValueFunc = getOrderingValueFunc;
            itemInfo.ExpressionWatcher    = expressionWatcher;
            itemInfo.NestedComputings     = nestedComputings;

            TOrderingValue orderingValue = getOrderingValue(itemInfo, sourceItem);
            int            orderedIndex  = getOrderedIndex(orderingValue);

            itemInfo.ExpressionWatcher.ValueChanged = expressionWatcher_OnValueChanged;
            itemInfo.ExpressionWatcher._position    = itemInfo;
            OrderedItemInfo <TOrderingValue> orderedItemInfo = _orderedPositions.Insert(orderedIndex);

            itemInfo.OrderedItemInfo = orderedItemInfo;
            orderedItemInfo.ItemInfo = itemInfo;
            _orderingValues.Insert(orderedIndex, orderingValue);

            if (_thenOrderingsCount > 0)
            {
                adjustEqualOrderingValueRangePosition(orderingValue, orderedItemInfo, orderedIndex, orderedIndex - 1, orderedIndex);
            }

            if (initializing)
            {
                _items.Insert(orderedIndex, sourceItem);
            }
            else
            {
                baseInsertItem(orderedIndex, sourceItem);
            }
        }
コード例 #7
0
        private ItemInfo registerSourceItem(TSourceItem sourceItem, int sourceIndex, Position position, Position nextItemPosition, ExpressionWatcher watcher = null, Func <bool> predicateFunc = null)
        {
            ItemInfo itemInfo = _sourcePositions.Insert(sourceIndex);

            itemInfo.FilteredPosition         = position;
            itemInfo.NextFilteredItemPosition = nextItemPosition;

            if (watcher == null /*&& predicateFunc == null*/)
            {
                getNewExpressionWatcherAndPredicateFunc(sourceItem, out watcher, out predicateFunc);
            }

            itemInfo.PredicateFunc     = predicateFunc;
            watcher.ValueChanged       = expressionWatcher_OnValueChanged;
            watcher._position          = itemInfo;
            itemInfo.ExpressionWatcher = watcher;

            return(itemInfo);
        }
コード例 #8
0
        internal static bool ProcessChangeSourceItem <TSourceItem>(int sourceIndex,
                                                                   TSourceItem sourceItem,
                                                                   List <FilteringItemInfo> filteringItemInfos,
                                                                   IFiltering <TSourceItem> filtering,
                                                                   Positions <Position> filteredPositions,
                                                                   CollectionComputing <TSourceItem> current,
                                                                   ExpressionWatcher expressionWatcher)
        {
            if (expressionWatcher._disposed)
            {
                return(false);
            }

            FilteringItemInfo itemInfo = filteringItemInfos[sourceIndex];

            bool newPredicateValue = filtering.applyPredicate(sourceItem, itemInfo.PredicateFunc);
            bool oldPredicateValue = itemInfo.FilteredPosition != null;

            if (newPredicateValue != oldPredicateValue)
            {
                if (newPredicateValue)
                {
                    int newIndex = itemInfo.NextFilteredItemPosition.Index;
                    itemInfo.FilteredPosition = filteredPositions.Insert(newIndex);
                    newIndex = itemInfo.FilteredPosition.Index;
                    modifyNextFilteredItemIndex(sourceIndex, itemInfo.FilteredPosition, filteringItemInfos);
                    current.baseInsertItem(newIndex, sourceItem);
                    return(true);
                }
                else // if (oldPredicaeValue)
                {
                    int index = itemInfo.FilteredPosition.Index;
                    filteredPositions.Remove(index);
                    itemInfo.FilteredPosition = null;
                    modifyNextFilteredItemIndex(sourceIndex, itemInfo.NextFilteredItemPosition, filteringItemInfos);
                    current.baseRemoveItem(index);
                    return(true);
                }
            }

            return(false);
        }
コード例 #9
0
        private ItemInfo registerSourceItem(TSourceItem sourceItem, int sourceIndex)
        {
            ItemInfo itemInfo = _sourcePositions.Insert(sourceIndex);

            Utils.getItemInfoContent(
                new object[] { sourceItem },
                out ExpressionWatcher watcher,
                out Func <bool> predicateFunc,
                out List <IComputingInternal> nestedComputings,
                _predicateExpression,
                out _predicateExpressionСallCount,
                this,
                _predicateContainsParametrizedObservableComputationCalls,
                _predicateExpressionInfo);

            itemInfo.PredicateFunc     = predicateFunc;
            watcher.ValueChanged       = expressionWatcher_OnValueChanged;
            watcher._position          = itemInfo;
            itemInfo.ExpressionWatcher = watcher;
            itemInfo.NestedComputings  = nestedComputings;
            return(itemInfo);
        }
コード例 #10
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;
        }