Пример #1
0
        private void initializeFromSources()
        {
            if (_outerSourceNotifyCollectionChangedEventHandler != null)
            {
                _outerSource.CollectionChanged -= _outerSourceWeakNotifyCollectionChangedEventHandler.Handle;
                _outerSourceNotifyCollectionChangedEventHandler     = null;
                _outerSourceWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_innerSourceNotifyCollectionChangedEventHandler != null)
            {
                _innerSource.CollectionChanged -= _innerSourceWeakNotifyCollectionChangedEventHandler.Handle;
                _innerSourceNotifyCollectionChangedEventHandler     = null;
                _innerSourceWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_innerSourceAsINotifyPropertyChanged != null)
            {
                _innerSourceAsINotifyPropertyChanged.PropertyChanged -=
                    _innerSourceWeakPropertyChangedEventHandler.Handle;

                _innerSourceAsINotifyPropertyChanged        = null;
                _innerSourcePropertyChangedEventHandler     = null;
                _innerSourceWeakPropertyChangedEventHandler = null;
            }

            if (_outerSourceAsINotifyPropertyChanged != null)
            {
                _outerSourceAsINotifyPropertyChanged.PropertyChanged -=
                    _outerSourceWeakPropertyChangedEventHandler.Handle;

                _outerSourceAsINotifyPropertyChanged        = null;
                _outerSourcePropertyChangedEventHandler     = null;
                _outerSourceWeakPropertyChangedEventHandler = null;
            }


            if (_outerSource != null || _innerSource != null)
            {
                baseClearItems();
            }

            if (_outerSourceScalar != null)
            {
                _outerSource = _outerSourceScalar.Value;
            }
            _outerSourceAsList = (IList <TOuterSourceItem>)_outerSource;

            if (_innerSourceScalar != null)
            {
                _innerSource = _innerSourceScalar.Value;
            }
            _innerSourceAsList = (IList <TInnerSourceItem>)_innerSource;

            if (_outerSource != null && _innerSource != null)
            {
                _outerSourceAsObservableCollectionWithChangeMarker = _outerSourceAsList as ObservableCollectionWithChangeMarker <TOuterSourceItem>;

                if (_outerSourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedOuterSourceChangeMarker = _outerSourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _outerSourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_outerSource;

                    _outerSourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _outerSourceIndexerPropertyChangedEventRaised = true;                                                        // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _outerSourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_outerSourcePropertyChangedEventHandler);

                    _outerSourceAsINotifyPropertyChanged.PropertyChanged +=
                        _outerSourceWeakPropertyChangedEventHandler.Handle;
                }


                _innerSourceAsObservableCollectionWithChangeMarker = _innerSourceAsList as ObservableCollectionWithChangeMarker <TInnerSourceItem>;

                if (_innerSourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedInnerSourceChangeMarker = _innerSourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _innerSourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_innerSource;

                    _innerSourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _innerSourceIndexerPropertyChangedEventRaised = true;                                                        // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _innerSourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_innerSourcePropertyChangedEventHandler);

                    _innerSourceAsINotifyPropertyChanged.PropertyChanged +=
                        _innerSourceWeakPropertyChangedEventHandler.Handle;
                }


                // ReSharper disable once PossibleNullReferenceException
                int outerSourceCount = _outerSourceAsList.Count;
                // ReSharper disable once PossibleNullReferenceException
                int innerSourceCount = _innerSourceAsList.Count;
                int baseIndex        = 0;
                for (int outerSourceIndex = 0; outerSourceIndex < outerSourceCount; outerSourceIndex++)
                {
                    TOuterSourceItem sourceOuterItem = _outerSourceAsList[outerSourceIndex];
                    for (int innerSourceIndex = 0; innerSourceIndex < innerSourceCount; innerSourceIndex++)
                    {
                        TInnerSourceItem sourceInnerItem = _innerSourceAsList[innerSourceIndex];
                        JoinPair <TOuterSourceItem, TInnerSourceItem> joinPair = new JoinPair <TOuterSourceItem, TInnerSourceItem>(
                            sourceOuterItem, sourceInnerItem);
                        baseInsertItem(baseIndex + innerSourceIndex, joinPair);
                    }

                    baseIndex = baseIndex + innerSourceCount;
                }

                _outerSourceNotifyCollectionChangedEventHandler     = handleOuterSourceCollectionChanged;
                _outerSourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_outerSourceNotifyCollectionChangedEventHandler);

                _outerSource.CollectionChanged += _outerSourceWeakNotifyCollectionChangedEventHandler.Handle;

                _innerSourceNotifyCollectionChangedEventHandler     = handleInnerSourceCollectionChanged;
                _innerSourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_innerSourceNotifyCollectionChangedEventHandler);

                _innerSource.CollectionChanged += _innerSourceWeakNotifyCollectionChangedEventHandler.Handle;
            }
        }
Пример #2
0
        private void initializeFromSource()
        {
            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                int itemInfosCount = _itemInfos.Count;
                for (int index = 0; index < itemInfosCount; index++)
                {
                    ItemInfo          itemInfo          = _itemInfos[index];
                    ExpressionWatcher expressionWatcher = itemInfo.ExpressionWatcher;
                    expressionWatcher.Dispose();
                }

                int capacity = _sourceScalar != null?Utils.getCapacity(_sourceScalar) : Utils.getCapacity(_source);

                _itemInfos       = new List <ItemInfo>(capacity);
                _sourcePositions = new Positions <ItemInfo>(_itemInfos);

                if (_rootSourceWrapper)
                {
                    _sourceAsList.CollectionChanged -= _sourceNotifyCollectionChangedEventHandler;
                }
                else
                {
                    _sourceAsList.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                    _sourceWeakNotifyCollectionChangedEventHandler = null;
                }

                _sourceNotifyCollectionChangedEventHandler = null;
            }

            _predicatePassedCount = 0;
            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = null;

            if (_source != null)
            {
                if (_source is ObservableCollectionWithChangeMarker <TSourceItem> sourceAsList)
                {
                    _sourceAsList      = sourceAsList;
                    _rootSourceWrapper = false;
                }
                else
                {
                    _sourceAsList      = new RootSourceWrapper <TSourceItem>(_source);
                    _rootSourceWrapper = true;
                }

                _lastProcessedSourceChangeMarker = _sourceAsList.ChangeMarkerField;

                int count = _sourceAsList.Count;
                for (int sourceIndex = 0; sourceIndex < count; sourceIndex++)
                {
                    TSourceItem sourceItem = _sourceAsList[sourceIndex];
                    ItemInfo    itemInfo   = registerSourceItem(sourceItem, sourceIndex);

                    if (ApplyPredicate(sourceIndex))
                    {
                        _predicatePassedCount++;
                        itemInfo.PredicateResult = true;
                    }
                }

                _sourceNotifyCollectionChangedEventHandler = handleSourceCollectionChanged;

                if (_rootSourceWrapper)
                {
                    _sourceAsList.CollectionChanged += _sourceNotifyCollectionChangedEventHandler;
                }
                else
                {
                    _sourceWeakNotifyCollectionChangedEventHandler =
                        new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);

                    _sourceAsList.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                }

                calculateValue();
            }
            else
            {
                if (_value)
                {
                    setValue(false);
                }
            }
        }
Пример #3
0
        private void initializeFromSource()
        {
            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                _valueStringBuilder.Clear();

                int capacity = _sourceScalar != null?Utils.getCapacity(_sourceScalar) : Utils.getCapacity(_source);

                _resultRangePositions = new RangePositions <RangePosition>(new List <RangePosition>(capacity * 2));

                _source.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                _sourceNotifyCollectionChangedEventHandler     = null;
                _sourceWeakNotifyCollectionChangedEventHandler = null;
                setValue(String.Empty);
            }

            if (_sourceAsINotifyPropertyChanged != null)
            {
                _sourceAsINotifyPropertyChanged.PropertyChanged -=
                    _sourceWeakPropertyChangedEventHandler.Handle;

                _sourceAsINotifyPropertyChanged        = null;
                _sourcePropertyChangedEventHandler     = null;
                _sourceWeakPropertyChangedEventHandler = null;
            }

            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = (IList <string>)_source;

            if (_source != null)
            {
                _sourceAsObservableCollectionWithChangeMarker = _sourceAsList as ObservableCollectionWithChangeMarker <string>;

                if (_sourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedSourceChangeMarker = _sourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _sourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourceAsList;

                    _sourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _indexerPropertyChangedEventRaised =
                                true;                                 // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _sourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_sourcePropertyChangedEventHandler);

                    _sourceAsINotifyPropertyChanged.PropertyChanged += _sourceWeakPropertyChangedEventHandler.Handle;
                }

                _sourceNotifyCollectionChangedEventHandler     = handleSourceCollectionChanged;
                _sourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);
                _source.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;

                recalculateValue();
            }
            else
            {
                _valueStringBuilder.Clear();
                setValue(String.Empty);
            }
        }
Пример #4
0
        private void initializeFromSource()
        {
            int originalCount = _items.Count;

            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                int itemInfosCount = _itemInfos.Count;
                for (int index = 0; index < itemInfosCount; index++)
                {
                    ItemInfo          itemInfo          = _itemInfos[index];
                    ExpressionWatcher expressionWatcher = itemInfo.ExpressionWatcher;
                    expressionWatcher.Dispose();
                }

                int capacity = _sourceScalar != null?Utils.getCapacity(_sourceScalar) : Utils.getCapacity(_source);

                _filteredPositions = new Positions <Position>(new List <Position>(_initialCapacity));
                _itemInfos         = new List <ItemInfo>(capacity);
                _sourcePositions   = new Positions <ItemInfo>(_itemInfos);

                if (_rootSourceWrapper)
                {
                    _sourceAsList.CollectionChanged -= _sourceNotifyCollectionChangedEventHandler;
                }
                else
                {
                    _sourceAsList.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                    _sourceWeakNotifyCollectionChangedEventHandler = null;
                }

                _sourceNotifyCollectionChangedEventHandler = null;
            }

            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = null;

            if (_source != null)
            {
                if (_source is ObservableCollectionWithChangeMarker <TSourceItem> sourceAsList)
                {
                    _sourceAsList      = sourceAsList;
                    _rootSourceWrapper = false;
                }
                else
                {
                    _sourceAsList      = new RootSourceWrapper <TSourceItem>(_source);
                    _rootSourceWrapper = true;
                }

                _lastProcessedSourceChangeMarker = _sourceAsList.ChangeMarkerField;

                Position nextItemPosition = _filteredPositions.Add();
                int      count            = _sourceAsList.Count;
                int      insertingIndex   = 0;
                int      sourceIndex;

                for (sourceIndex = 0; sourceIndex < count; sourceIndex++)
                {
                    TSourceItem sourceItem = _sourceAsList[sourceIndex];
                    Position    currentFilteredItemPosition = null;

                    ItemInfo itemInfo = registerSourceItem(sourceItem, sourceIndex, null, null);

                    if (ApplyPredicate(sourceIndex))
                    {
                        if (originalCount > insertingIndex)
                        {
                            _items[insertingIndex++] = sourceItem;
                        }
                        else
                        {
                            _items.Insert(insertingIndex++, sourceItem);
                        }

                        currentFilteredItemPosition = nextItemPosition;
                        nextItemPosition            = _filteredPositions.Add();
                    }

                    itemInfo.FilteredPosition         = currentFilteredItemPosition;
                    itemInfo.NextFilteredItemPosition = nextItemPosition;
                }

                for (int index = originalCount - 1; index >= insertingIndex; index--)
                {
                    _items.RemoveAt(index);
                }

                _sourceNotifyCollectionChangedEventHandler = handleSourceCollectionChanged;

                if (_rootSourceWrapper)
                {
                    _sourceAsList.CollectionChanged += _sourceNotifyCollectionChangedEventHandler;
                }
                else
                {
                    _sourceWeakNotifyCollectionChangedEventHandler =
                        new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);

                    _sourceAsList.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                }
            }
            else
            {
                _items.Clear();
            }

            reset();
        }
Пример #5
0
        private void initializeFromSource(object sender, EventArgs eventArgs)
        {
            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                int count = Count;
                for (int i = 0; i < count; i++)
                {
                    TSourceItem sourceItem = _sourceAsList[i];
                    baseRemoveItem(0);
                    if (_oldItemProcessor != null)
                    {
                        processOldItem(sourceItem);
                    }
                }

                if (_rootSourceWrapper)
                {
                    _sourceAsList.CollectionChanged -= _sourceNotifyCollectionChangedEventHandler;
                }
                else
                {
                    _sourceAsList.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                    _sourceWeakNotifyCollectionChangedEventHandler = null;
                }

                _sourceNotifyCollectionChangedEventHandler = null;
            }

            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = null;

            if (_source != null)
            {
                if (_source is ObservableCollectionWithChangeMarker <TSourceItem> sourceAsList)
                {
                    _sourceAsList      = sourceAsList;
                    _rootSourceWrapper = false;
                }
                else
                {
                    _sourceAsList      = new RootSourceWrapper <TSourceItem>(_source);
                    _rootSourceWrapper = true;
                }

                _lastProcessedSourceChangeMarker = _sourceAsList.ChangeMarkerField;

                int count = _sourceAsList.Count;
                for (int index = 0; index < count; index++)
                {
                    TSourceItem sourceItem = _sourceAsList[index];
                    if (_newItemProcessor != null)
                    {
                        processNewItem(sourceItem);
                    }
                    baseInsertItem(index, sourceItem);
                }

                _sourceNotifyCollectionChangedEventHandler = handleSourceCollectionChanged;

                if (_rootSourceWrapper)
                {
                    _sourceAsList.CollectionChanged += _sourceNotifyCollectionChangedEventHandler;
                }
                else
                {
                    _sourceWeakNotifyCollectionChangedEventHandler =
                        new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);

                    _sourceAsList.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                }
            }
        }
Пример #6
0
        private void initializeFromSource()
        {
            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                _source.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                _sourceNotifyCollectionChangedEventHandler     = null;
                _sourceWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_sourceAsINotifyPropertyChanged != null)
            {
                _sourceAsINotifyPropertyChanged.PropertyChanged -=
                    _sourceWeakPropertyChangedEventHandler.Handle;

                _sourceAsINotifyPropertyChanged        = null;
                _sourcePropertyChangedEventHandler     = null;
                _sourceWeakPropertyChangedEventHandler = null;
            }

            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = (IList <TSourceItem>)_source;

            if (_source != null)
            {
                _sourceAsObservableCollectionWithChangeMarker = _sourceAsList as ObservableCollectionWithChangeMarker <TSourceItem>;

                if (_sourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedSourceChangeMarker = _sourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _sourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourceAsList;

                    _sourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _indexerPropertyChangedEventRaised =
                                true;                                 // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _sourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_sourcePropertyChangedEventHandler);

                    _sourceAsINotifyPropertyChanged.PropertyChanged += _sourceWeakPropertyChangedEventHandler.Handle;
                }

                _sourceNotifyCollectionChangedEventHandler     = handleSourceCollectionChanged;
                _sourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);

                _source.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;
            }

            recalculateValue();
        }