示例#1
0
        protected override void processSource()
        {
            if (_sourceReadAndSubscribed)
            {
                _source.CollectionChanged -= handleSourceCollectionChanged;

                if (_sourceAsINotifyPropertyChanged != null)
                {
                    _sourceAsINotifyPropertyChanged.PropertyChanged -=
                        ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                    _sourceAsINotifyPropertyChanged = null;
                }

                _sourceCopy = new List <TSourceItem>(Utils.getCapacity(_sourceScalar, _source));
                _sourceReadAndSubscribed = false;
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               out _sourceAsList, true);

            if (_source != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);

                _source.CollectionChanged += handleSourceCollectionChanged;
                _sourceReadAndSubscribed   = true;
            }

            recalculateValue(true);
        }
示例#2
0
        protected override void processSource()
        {
            if (_sourceReadAndSubscribed)
            {
                _source.CollectionChanged -= handleSourceCollectionChanged;

                if (_oldItemsProcessor != null)
                {
                    processOldItems(_sourceAsList.ToArray(), this.ToArray());
                }

                int count = Count;
                for (int i = 0; i < count; i++)
                {
                    baseRemoveItem(0);
                }

                _sourceReadAndSubscribed = false;
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               out _sourceAsList, true);

            if (_sourceAsList != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);

                int count = _sourceAsList.Count;

                TSourceItem[] sourceCopy = new TSourceItem[count];
                _sourceAsList.CopyTo(sourceCopy, 0);

                _source.CollectionChanged += handleSourceCollectionChanged;

                TReturnValue[] returnValues = null;
                if (_newItemsProcessor != null)
                {
                    returnValues = processNewItems(sourceCopy);
                }

                for (int index = 0; index < count; index++)
                {
                    baseInsertItem(index, returnValues != null ? returnValues[index] : default);
                }

                _sourceReadAndSubscribed = true;
            }
        }
        protected override void initializeFromSource()
        {
            if (_sourceInitialized)
            {
                _source.CollectionChanged -= handleSourceCollectionChanged;

                int count = Count;
                for (int i = 0; i < count; i++)
                {
                    TSourceItem sourceItem = _sourceAsList[i];
                    baseRemoveItem(0);
                    if (_oldItemProcessor != null)
                    {
                        processOldItem(sourceItem);
                    }
                }

                _sourceInitialized = false;
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               ref _sourceAsList, true);

            if (_sourceAsList != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);

                int count = _sourceAsList.Count;

                TSourceItem[] sourceCopy = new TSourceItem[count];
                _sourceAsList.CopyTo(sourceCopy, 0);

                _source.CollectionChanged += handleSourceCollectionChanged;

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

                _sourceInitialized = true;
            }
        }
示例#4
0
        protected override void processSource()
        {
            if (_sourceReadAndSubscribed)
            {
                _source.CollectionChanged -= handleSourceCollectionChanged;

                if (_sourceAsINotifyPropertyChanged != null)
                {
                    _sourceAsINotifyPropertyChanged.PropertyChanged -=
                        ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                    _sourceAsINotifyPropertyChanged = null;
                }

                _sourceReadAndSubscribed = false;
            }


            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               out _sourceAsList, true);

            if (_source != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);

                _source.CollectionChanged += handleSourceCollectionChanged;

                TResult value = default(TResult);
                int     count = _sourceAsList.Count;
                for (int index = 0; index < count; index++)
                {
                    value = aggregate(_sourceAsList[index], value);
                }
                setValue(value);

                _sourceReadAndSubscribed = true;
            }
            else
            {
                setDefaultValue();
            }
        }
示例#5
0
        protected override void initializeFromSource()
        {
            if (_sourceInitialized)
            {
                _valueStringBuilder.Clear();

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

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

                _source.CollectionChanged -= handleSourceCollectionChanged;

                if (_sourceAsINotifyPropertyChanged != null)
                {
                    _sourceAsINotifyPropertyChanged.PropertyChanged -=
                        ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                    _sourceAsINotifyPropertyChanged = null;
                }

                _sourceInitialized = false;
            }


            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               ref _sourceAsList, true);

            if (_source != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);

                _source.CollectionChanged += handleSourceCollectionChanged;
                _sourceInitialized         = true;
                recalculateValue();
            }
            else
            {
                _valueStringBuilder.Clear();
                setValue(String.Empty);
            }
        }
        protected override void initializeFromSource()
        {
            if (_sourceInitialized)
            {
                _source.CollectionChanged -= handleSourceCollectionChanged;

                if (_sourceAsINotifyPropertyChanged != null)
                {
                    _sourceAsINotifyPropertyChanged.PropertyChanged -=
                        ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                    _sourceAsINotifyPropertyChanged = null;
                }

                _sourceCopy = null;

                _sourceInitialized = false;
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               ref _sourceAsList, true);


            if (_source != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);

                _source.CollectionChanged += handleSourceCollectionChanged;
                _sourceCopy = new List <TSourceItem>(_sourceAsList);
                recalculateValue();


                _sourceInitialized = true;
            }
            else
            {
                _isDefaulted = true;
                setValue(_defaultValue);
            }
        }
        protected override void initializeFromSource()
        {
            int originalCount = _items.Count;

            if (_sourceInitialized)
            {
                _source.CollectionChanged -= handleSourceCollectionChanged;

                if (_sourceAsINotifyPropertyChanged != null)
                {
                    _sourceAsINotifyPropertyChanged.PropertyChanged -=
                        ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                    _sourceAsINotifyPropertyChanged = null;
                }

                _sourceInitialized = false;
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               ref _sourceAsList, true);

            if (_sourceAsList != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);


                int      count      = _sourceAsList.Count;
                object[] sourceCopy = new object[count];
                _sourceAsList.CopyTo(sourceCopy, 0);

                _source.CollectionChanged += handleSourceCollectionChanged;

                int sourceIndex;
                for (sourceIndex = 0; sourceIndex < count; sourceIndex++)
                {
                    if (originalCount > sourceIndex)
                    {
                        _items[sourceIndex] = (TResultItem)sourceCopy[sourceIndex];
                    }
                    else
                    {
                        _items.Insert(sourceIndex, (TResultItem)sourceCopy[sourceIndex]);
                    }
                }

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

                _sourceInitialized = true;
            }
            else
            {
                _items.Clear();
            }

            reset();
        }
示例#8
0
        private void doProcessSource(object sender, EventArgs e)
        {
            int originalCount = _items.Count;

            if (_sourceReadAndSubscribed)
            {
                uninitializeSource();

                _sourceReadAndSubscribed = false;

                void uninitializeSource()
                {
                    _source.CollectionChanged -= handleSourceCollectionChanged;

                    if (_sourceAsINotifyPropertyChanged != null)
                    {
                        _sourceAsINotifyPropertyChanged.PropertyChanged -=
                            ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                        _sourceAsINotifyPropertyChanged = null;
                    }
                }

                if (_sourceOcDispatcher != null)
                {
                    _sourceOcDispatcher.Invoke(
                        uninitializeSource,
                        _sourceOcDispatcherPriority,
                        _sourceOcDispatcherParameter,
                        this);
                }
                else
                {
                    uninitializeSource();
                }
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               out _sourceAsList, true);

            if (_sourceAsList != null && _isActive)
            {
                void readAndSubscribe()
                {
                    Utils.initializeFromHasChangeMarker(
                        out _sourceAsIHasChangeMarker,
                        _sourceAsList,
                        ref _lastProcessedSourceChangeMarker,
                        ref _sourceAsINotifyPropertyChanged,
                        (ISourceIndexerPropertyTracker)this);

                    int count = _sourceAsList.Count;

                    TSourceItem[] sourceCopy = new TSourceItem[count];
                    _sourceAsList.CopyTo(sourceCopy, 0);

                    _source.CollectionChanged += handleSourceCollectionChanged;

                    void resetAction()
                    {
                        _handledEventSender = sender;
                        _handledEventArgs   = e;

                        int sourceIndex = 0;

                        for (int index = 0; index < count; index++)
                        {
                            if (originalCount > sourceIndex)
                            {
                                _items[sourceIndex] = sourceCopy[index];
                            }
                            else
                            {
                                _items.Insert(sourceIndex, sourceCopy[index]);
                            }

                            sourceIndex++;
                        }

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

                        reset();

                        _handledEventSender = null;
                        _handledEventArgs   = null;
                    }

                    _destinationOcDispatcher.Invoke(
                        resetAction,
                        _destinationOcDispatcherPriority,
                        _destinationOcDispatcherParameter,
                        this);
                }

                if (_sourceOcDispatcher != null)
                {
                    _sourceOcDispatcher.Invoke(
                        readAndSubscribe,
                        _sourceOcDispatcherPriority,
                        _sourceOcDispatcherParameter,
                        this);
                }
                else
                {
                    readAndSubscribe();
                }

                _sourceReadAndSubscribed = true;
            }
            else
            {
                void clearItemsAction()
                {
                    _handledEventSender = sender;
                    _handledEventArgs   = e;
                    baseClearItems();
                    _handledEventSender = null;
                    _handledEventArgs   = null;
                }

                _destinationOcDispatcher.Invoke(
                    clearItemsAction,
                    _destinationOcDispatcherPriority,
                    _destinationOcDispatcherParameter,
                    this);
            }
        }
        protected override void processSource()
        {
            int originalCount = _items.Count;

            if (_sourceReadAndSubscribed)
            {
                int itemInfosCount = _itemInfos.Count;

                for (int index = 0; index < itemInfosCount; index++)
                {
                    ItemInfo itemInfo = _itemInfos[index];
                    if (itemInfo.Source != null)
                    {
                        itemInfo.Source.CollectionChanged -=
                            itemInfo.SourceNotifyCollectionChangedEventHandler;

                        if (itemInfo.SourceAsINotifyPropertyChanged != null)
                        {
                            itemInfo.SourceAsINotifyPropertyChanged.PropertyChanged -=
                                itemInfo.SourcePropertyChangedEventHandler;
                        }
                    }

                    if (itemInfo.SourceScalar != null)
                    {
                        itemInfo.SourceScalar.PropertyChanged -= itemInfo.SourceScalarPropertyChangedEventHandler;
                    }
                }

                Utils.initializeItemInfos(
                    Utils.getCapacity(_sourceScalar, _source),
                    out _itemInfos,
                    out _sourceRangePositions);

                _source.CollectionChanged -= HandleSourceCollectionChanged;

                if (_sourcesAsINotifyPropertyChanged != null)
                {
                    _sourcesAsINotifyPropertyChanged.PropertyChanged -=
                        ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                    _sourcesAsINotifyPropertyChanged = null;
                }

                _sourceReadAndSubscribed = false;
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               out _sourcesAsList, true);

            if (_source != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourcesAsIHasChangeMarker,
                    _sourcesAsList,
                    ref _lastProcessedSourcesChangeMarker,
                    ref _sourcesAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);


                int      plainIndex  = 0;
                int      count       = _sourcesAsList.Count;
                object[] sourcesCopy = new object[count];
                _sourcesAsList.CopyTo(sourcesCopy, 0);

                for (int index = 0; index < count; index++)
                {
                    object sourceItemObject = sourcesCopy[index];
                    IList  sourceItem       = sourceItemObject is IReadScalar <object> sourceItemScalar
                                                ? (IList)sourceItemScalar.Value : (IList)sourceItemObject;
                    int      sourceItemCount = sourceItem?.Count ?? 0;
                    ItemInfo itemInfo        = _sourceRangePositions.Add(sourceItemCount);
                    registerSourceItem(sourceItemObject, itemInfo);
                    IList <TSourceItem> sourceCopy = itemInfo.SourceCopy;

                    for (int sourceSourceIndex = 0; sourceSourceIndex < sourceItemCount; sourceSourceIndex++)
                    {
                        if (originalCount > plainIndex)
                        {
                            // ReSharper disable once PossibleNullReferenceException
                            _items[plainIndex++] = sourceCopy[sourceSourceIndex];
                        }
                        else
                        {
                            // ReSharper disable once PossibleNullReferenceException
                            _items.Insert(plainIndex++, sourceCopy[sourceSourceIndex]);
                        }
                    }
                }

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


                _source.CollectionChanged += HandleSourceCollectionChanged;
                _sourceReadAndSubscribed   = true;
            }
            else
            {
                _items.Clear();
            }

            reset();
        }
示例#10
0
        private void doInitializeFromSource()
        {
            int originalCount = _items.Count;

            if (_sourceInitialized)
            {
                if (_destinationDispatcher != null)
                {
                    _destinationDispatcher.Invoke(baseClearItems, this);
                }
                else
                {
                    _collectionDestinationDispatcher.Invoke(baseClearItems, this, NotifyCollectionChangedAction.Reset, null, null, 0, 0);
                }

                _source.CollectionChanged -= handleSourceCollectionChanged;

                if (_sourceAsINotifyPropertyChanged != null)
                {
                    _sourceAsINotifyPropertyChanged.PropertyChanged -=
                        ((ISourceIndexerPropertyTracker)this).HandleSourcePropertyChanged;
                    _sourceAsINotifyPropertyChanged = null;
                }

                _sourceInitialized = false;
            }

            Utils.changeSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                               ref _sourceAsList, true);

            if (_sourceAsList != null && _isActive)
            {
                Utils.initializeFromHasChangeMarker(
                    out _sourceAsIHasChangeMarker,
                    _sourceAsList,
                    ref _lastProcessedSourceChangeMarker,
                    ref _sourceAsINotifyPropertyChanged,
                    (ISourceIndexerPropertyTracker)this);

                int           count      = _sourceAsList.Count;
                TSourceItem[] sourceCopy = new TSourceItem[count];
                _sourceAsList.CopyTo(sourceCopy, 0);

                _source.CollectionChanged += handleSourceCollectionChanged;

                int sourceIndex;
                for (sourceIndex = 0; sourceIndex < count; sourceIndex++)
                {
                    if (originalCount > sourceIndex)
                    {
                        _items[sourceIndex] = sourceCopy[sourceIndex];
                    }
                    else
                    {
                        _items.Insert(sourceIndex, sourceCopy[sourceIndex]);
                    }
                }

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

                _sourceInitialized = true;
            }
            else
            {
                _items.Clear();
            }

            if (_destinationDispatcher != null)
            {
                _destinationDispatcher.Invoke(reset, this);
            }
            else
            {
                _collectionDestinationDispatcher.Invoke(reset, this, NotifyCollectionChangedAction.Reset, null, null, 0, 0);
            }
        }