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(); } }
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(); } }
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 processSource(bool replaceSource) { int originalCount = _items.Count; if (_sourceReadAndSubscribed) { Utils.disposeExpressionItemInfos(_itemInfos, _predicateExpressionCallCount, this); Utils.removeDownstreamConsumedComputing(_itemInfos, this); _filteredPositions = new Positions <Position>(new List <Position>(_initialCapacity)); Utils.disposeSource( _sourceScalar, _source, out _itemInfos, out _sourcePositions, _sourceAsList, handleSourceCollectionChanged, replaceSource); _sourceReadAndSubscribed = false; } if (replaceSource) { Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this, out _sourceAsList, false); } if (_source != null && _isActive) { if (replaceSource) { Utils.subscribeSource( _source, ref _sourceAsList, ref _rootSourceWrapper, ref _lastProcessedSourceTickTackVersion, handleSourceCollectionChanged); } Position nextItemPosition = _filteredPositions.Add(); int count = _sourceAsList.Count; TSourceItem[] sourceCopy = new TSourceItem[count]; _sourceAsList.CopyTo(sourceCopy, 0); int insertingIndex = 0; int sourceIndex; for (sourceIndex = 0; sourceIndex < count; sourceIndex++) { TSourceItem sourceItem = sourceCopy[sourceIndex]; Position currentFilteredItemPosition = null; FilteringItemInfo itemInfo = registerSourceItem(sourceItem, sourceIndex, null, null); if (_thisAsFiltering.applyPredicate(sourceItem, itemInfo.PredicateFunc)) { 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); } _sourceReadAndSubscribed = true; } else { _items.Clear(); } reset(); }
private void processSource(bool replaceSource) { int originalCount = _items.Count; if (_sourceReadAndSubscribed) { Utils.disposeExpressionItemInfos(_itemInfos, _selectorExpressionCallCount, this); Utils.removeDownstreamConsumedComputing(_itemInfos, this); Utils.disposeSource( _sourceScalar, _source, out _itemInfos, out _sourcePositions, _sourceAsList, handleSourceCollectionChanged, replaceSource); _sourceReadAndSubscribed = false; } if (replaceSource) { Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this, out _sourceAsList, false); } if (_source != null && _isActive) { if (replaceSource) { Utils.subscribeSource( _source, ref _sourceAsList, ref _rootSourceWrapper, ref _lastProcessedSourceTickTackVersion, handleSourceCollectionChanged); } int count = _sourceAsList.Count; TSourceItem[] sourceCopy = new TSourceItem[count]; _sourceAsList.CopyTo(sourceCopy, 0); int sourceIndex; for (sourceIndex = 0; sourceIndex < count; sourceIndex++) { ItemInfo itemInfo = registerSourceItem(sourceCopy[sourceIndex], sourceIndex); if (originalCount > sourceIndex) { _items[sourceIndex] = applySelector(itemInfo, sourceCopy[sourceIndex]); } else { _items.Insert(sourceIndex, applySelector(itemInfo, sourceCopy[sourceIndex])); } } for (int index = originalCount - 1; index >= sourceIndex; index--) { _items.RemoveAt(index); } _sourceReadAndSubscribed = true; } else { _items.Clear(); } reset(); }
private void processSource(bool replaceSource) { if (_sourceReadAndSubscribed) { Utils.disposeExpressionItemInfos(_itemInfos, _predicateExpressionCallCount, this); Utils.removeDownstreamConsumedComputing(_itemInfos, this); Utils.disposeSource( _sourceScalar, _source, out _itemInfos, out _sourcePositions, _sourceAsList, handleSourceCollectionChanged, replaceSource); _sourceReadAndSubscribed = false; } _predicatePassedCount = 0; if (replaceSource) { Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this, out _sourceAsList, false); } if (_isActive) { if (_source != null) { if (replaceSource) { Utils.subscribeSource( _source, ref _sourceAsList, ref _rootSourceWrapper, ref _lastProcessedSourceTickTackVersion, handleSourceCollectionChanged); } int count = _sourceAsList.Count; for (int sourceIndex = 0; sourceIndex < count; sourceIndex++) { TSourceItem sourceItem = _sourceAsList[sourceIndex]; ItemInfo itemInfo = registerSourceItem(sourceItem, sourceIndex); if (applyPredicate(sourceItem, itemInfo.PredicateFunc)) { _predicatePassedCount++; itemInfo.PredicateResult = true; } } _sourceReadAndSubscribed = true; } calculateValue(); } else { setDefaultValue(); } }
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); } }