Example #1
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);
        }
Example #2
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);
        }
        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;
            }
        }
        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);
            }
        }
Example #5
0
        internal static bool  ProcessReplaceSourceItem <TExpression, TSourceItem>(
            FilteringItemInfo replacingItemInfo,
            TSourceItem sourceItem,
            object[] sourceItems,
            int sourceIndex, bool predicateContainsParametrizedObservableComputationsCalls,
            Expression <TExpression> predicateExpression,
            out int predicateExpressionCallCount,
            ExpressionWatcher.ExpressionInfo orderingValueSelectorExpressionInfo,
            List <FilteringItemInfo> filteringItemInfos,
            Positions <Position> filteredPositions, IFiltering <TSourceItem> thisAsFiltering,
            CollectionComputing <TSourceItem> current)
        {
            ExpressionWatcher oldExpressionWatcher = replacingItemInfo.ExpressionWatcher;

            Utils.disposeExpressionWatcher(oldExpressionWatcher, replacingItemInfo.NestedComputings, thisAsFiltering,
                                           predicateContainsParametrizedObservableComputationsCalls);

            Utils.getItemInfoContent(
                sourceItems,
                out ExpressionWatcher watcher,
                out Func <bool> predicateFunc,
                out List <IComputingInternal> nestedComputings1,
                predicateExpression,
                out predicateExpressionCallCount,
                thisAsFiltering,
                predicateContainsParametrizedObservableComputationsCalls,
                orderingValueSelectorExpressionInfo);

            replacingItemInfo.PredicateFunc = predicateFunc;
            watcher.ValueChanged            = thisAsFiltering.expressionWatcher_OnValueChanged;
            watcher._position = oldExpressionWatcher._position;
            replacingItemInfo.ExpressionWatcher = watcher;
            replacingItemInfo.NestedComputings  = nestedComputings1;
            bool replace = !ProcessChangeSourceItem(sourceIndex, sourceItem, filteringItemInfos, thisAsFiltering,
                                                    filteredPositions, current) &&
                           replacingItemInfo.FilteredPosition != null;

            return(replace);
        }
Example #6
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);
        }
Example #7
0
        void ISourceCollectionChangeProcessor.processSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                int         newSourceIndex  = e.NewStartingIndex;
                TSourceItem addedSourceItem = (TSourceItem)e.NewItems[0];
                Position    newItemPosition = null;
                Position    nextItemPosition;

                int?newFilteredIndex = null;

                Utils.getItemInfoContent(
                    new object[] { addedSourceItem },
                    out ExpressionWatcher newWatcher,
                    out Func <bool> newPredicateFunc,
                    out List <IComputingInternal> nestedComputings,
                    _predicateExpression,
                    out _predicateExpressionCallCount,
                    this,
                    _predicateContainsParametrizedObservableComputationsCalls,
                    _predicateExpressionInfo);

                bool predicateValue = _thisAsFiltering.applyPredicate(addedSourceItem, newPredicateFunc);
                nextItemPosition = FilteringUtils.processAddSourceItem(newSourceIndex, predicateValue, ref newItemPosition,
                                                                       ref newFilteredIndex, _itemInfos, _filteredPositions, Count);

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

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

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

            case NotifyCollectionChangedAction.Move:
                FilteringUtils.ProcessMoveSourceItems(e.OldStartingIndex, e.NewStartingIndex, _itemInfos,
                                                      _filteredPositions, _sourcePositions, this);
                break;

            case NotifyCollectionChangedAction.Reset:
                processSource();
                break;

            case NotifyCollectionChangedAction.Replace:
                int         sourceIndex         = e.NewStartingIndex;
                TSourceItem replacingSourceItem = (TSourceItem)e.NewItems[0];

                FilteringItemInfo replacingItemInfo = _itemInfos[sourceIndex];
                bool replace = FilteringUtils.ProcessReplaceSourceItem(replacingItemInfo, replacingSourceItem,
                                                                       new object[] { replacingSourceItem },
                                                                       sourceIndex, _predicateContainsParametrizedObservableComputationsCalls, _predicateExpression,
                                                                       out _predicateExpressionCallCount, _predicateExpressionInfo, _itemInfos, _filteredPositions,
                                                                       _thisAsFiltering, this);

                if (replace)
                {
                    baseSetItem(replacingItemInfo.FilteredPosition.Index, replacingSourceItem);
                }
                break;
            }
        }
Example #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;
            }
        }