private void processSource(bool replaceSource)
        {
            if (_sourceReadAndSubscribed)
            {
                _valueStringBuilder.Clear();

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

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

                if (replaceSource)
                {
                    Utils.unsubscribeSource(
                        _source,
                        ref _sourceAsINotifyPropertyChanged,
                        this,
                        handleSourceCollectionChanged);
                }

                _sourceReadAndSubscribed = false;
            }

            if (replaceSource)
            {
                Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                                    out _sourceAsList, true);
            }

            if (_isActive)
            {
                if (_source != null)
                {
                    if (replaceSource)
                    {
                        Utils.subscribeSource(
                            out _sourceAsIHasTickTackVersion,
                            _sourceAsList,
                            ref _lastProcessedSourceTickTackVersion,
                            ref _sourceAsINotifyPropertyChanged,
                            (ISourceIndexerPropertyTracker)this,
                            _source,
                            handleSourceCollectionChanged);
                    }

                    _sourceReadAndSubscribed = true;
                    recalculateValue();
                }
                else
                {
                    setValue(string.Empty);
                }
            }
            else
            {
                setDefaultValue();
            }
        }
        private void processSource(bool replaceSource)
        {
            if (_sourceReadAndSubscribed)
            {
                if (replaceSource)
                {
                    Utils.unsubscribeSource(
                        _source,
                        ref _sourceAsINotifyPropertyChanged,
                        this,
                        handleSourceCollectionChanged);
                }

                _sourceReadAndSubscribed = false;
            }

            if (replaceSource)
            {
                Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                                    out _sourceAsList, true);
            }

            if (_isActive && _source != null)
            {
                if (replaceSource)
                {
                    Utils.subscribeSource(
                        out _sourceAsIHasTickTackVersion,
                        _sourceAsList,
                        ref _lastProcessedSourceTickTackVersion,
                        ref _sourceAsINotifyPropertyChanged,
                        (ISourceIndexerPropertyTracker)this,
                        _source,
                        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();
            }
        }
예제 #3
0
        private void processSource(bool replaceSource)
        {
            if (_sourceReadAndSubscribed)
            {
                if (replaceSource)
                {
                    Utils.unsubscribeSource(
                        _source,
                        ref _sourceAsINotifyPropertyChanged,
                        this,
                        handleSourceCollectionChanged);
                }

                _sourceCopy = null;

                _sourceReadAndSubscribed = false;
            }

            if (replaceSource)
            {
                Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                                    out _sourceAsList, true);
            }


            if (_source != null && _isActive)
            {
                if (replaceSource)
                {
                    Utils.subscribeSource(
                        out _sourceAsIHasTickTackVersion,
                        _sourceAsList,
                        ref _lastProcessedSourceTickTackVersion,
                        ref _sourceAsINotifyPropertyChanged,
                        (ISourceIndexerPropertyTracker)this,
                        _source,
                        handleSourceCollectionChanged);
                }

                _sourceCopy = new List <TSourceItem>(_sourceAsList);
                recalculateValue();

                _sourceReadAndSubscribed = true;
            }
            else
            {
                setDefaultValue();
            }
        }
예제 #4
0
        private void processSource(bool replaceSource)
        {
            int originalCount = _items.Count;

            if (_sourceReadAndSubscribed)
            {
                if (replaceSource)
                {
                    Utils.unsubscribeSource(
                        _source,
                        ref _sourceAsINotifyPropertyChanged,
                        this,
                        handleSourceCollectionChanged);
                }

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

                _sourceReadAndSubscribed = false;
            }

            if (replaceSource)
            {
                Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                                    out _sourceAsList, true);
            }

            if (_sourceAsList != null && _isActive)
            {
                if (replaceSource)
                {
                    Utils.subscribeSource(
                        out _sourceAsIHasTickTackVersion,
                        _sourceAsList,
                        ref _lastProcessedSourceTickTackVersion,
                        ref _sourceAsINotifyPropertyChanged,
                        (ISourceIndexerPropertyTracker)this,
                        _source,
                        handleSourceCollectionChanged);
                }

                int count = _sourceAsList.Count;

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

                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);
                }

                if (_newItemsProcessor != null)
                {
                    processNewItems(sourceCopy);
                }

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

            reset();
        }
        private void processSource(bool replaceSource)
        {
            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);

                if (replaceSource)
                {
                    Utils.unsubscribeSource(
                        _source,
                        ref _sourceAsINotifyPropertyChanged,
                        this,
                        handleSourceCollectionChanged);
                }

                _sourceReadAndSubscribed = false;
            }

            if (replaceSource)
            {
                Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                                    out _sourcesAsList, true);
            }

            if (_source != null && _isActive)
            {
                if (replaceSource)
                {
                    Utils.subscribeSource(
                        out _sourceAsIHasTickTackVersion,
                        _sourcesAsList,
                        ref _lastProcessedSourcesTickTackVersion,
                        ref _sourceAsINotifyPropertyChanged,
                        (ISourceIndexerPropertyTracker)this,
                        _source,
                        handleSourceCollectionChanged);
                }

                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);
                }

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

            reset();
        }
        private void doProcessSource(object sender, EventArgs e, bool replaceSource)
        {
            if (_sourceReadAndSubscribed)
            {
                _sourceReadAndSubscribed = false;

                if (replaceSource)
                {
                    Utils.unsubscribeSource(
                        _source,
                        ref _sourceAsINotifyPropertyChanged,
                        this,
                        handleSourceCollectionChanged);
                }
            }

            if (replaceSource)
            {
                Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this,
                                    out _sourceAsList, true);
            }

            if (_sourceAsList != null && _isActive)
            {
                if (replaceSource)
                {
                    Utils.subscribeSource(
                        out _sourceAsIHasTickTackVersion,
                        _sourceAsList,
                        ref _lastProcessedSourceTickTackVersion,
                        ref _sourceAsINotifyPropertyChanged,
                        (ISourceIndexerPropertyTracker)this,
                        _source,
                        handleSourceCollectionChanged);
                }

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

                void resetAction()
                {
                    int originalCount = _items.Count;

                    _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);

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

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