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();
            }
        }
Ejemplo n.º 2
0
        public Concatenating(
            INotifyCollectionChanged sources) : base(calculateCapacity(sources))
        {
            int capacity = Utils.getCapacity(sources);

            _itemInfos            = new List <ItemInfo>(capacity);
            _sourceRangePositions = new RangePositions <ItemInfo>(_itemInfos);

            _sources = sources;
            initializeFromSources();
        }
Ejemplo n.º 3
0
        //public IOrdering<TSourceItem> Parent => null;
        //#endregion

        void IOrderingInternal <TSourceItem> .AddThenOrdering(IThenOrdering <TSourceItem> thenOrdering)
        {
            _thenOrderingsCount++;
            _thenOrderings = _thenOrderings ?? new List <IThenOrderingInternal <TSourceItem> >(4);
            _thenOrderings.Add((IThenOrderingInternal <TSourceItem>)thenOrdering);

            if (_thenOrderingsCount == 1)
            {
                _equalOrderingValueRangePositions = new RangePositions <RangePosition>(
                    new List <RangePosition>(
                        _sourceScalar != null
                                                        ? Utils.getCapacity(_sourceScalar)
                                                        : Utils.getCapacity(_source)));

                int           equalOrderingValueItemsCount = 0;
                RangePosition rangePosition = null;

                int count = Count;
                for (int orderedIndex = 0; orderedIndex < count; orderedIndex++)
                {
                    if (orderedIndex > 0)
                    {
                        int previousOrderedIndex = orderedIndex - 1;
                        if (_comparer.Compare(
                                getOrderingValue(_orderedItemInfos[orderedIndex].ItemInfo, this[orderedIndex]),
                                getOrderingValue(_orderedItemInfos[previousOrderedIndex].ItemInfo, this[previousOrderedIndex])) == 0)
                        {
                            equalOrderingValueItemsCount++;
                            _orderedItemInfos[orderedIndex].RangePosition = rangePosition;
                        }
                        else
                        {
                            // ReSharper disable once PossibleNullReferenceException
                            rangePosition.Length = equalOrderingValueItemsCount;
                            rangePosition        = _equalOrderingValueRangePositions.Add(1);
                            _orderedItemInfos[orderedIndex].RangePosition = rangePosition;
                            equalOrderingValueItemsCount = 1;
                        }
                    }
                    else
                    {
                        rangePosition = _equalOrderingValueRangePositions.Add(1);
                        equalOrderingValueItemsCount = 1;
                        _orderedItemInfos[orderedIndex].RangePosition = rangePosition;
                    }
                }

                if (count > 0)
                {
                    // ReSharper disable once PossibleNullReferenceException
                    rangePosition.Length = equalOrderingValueItemsCount;
                }
            }
        }
Ejemplo n.º 4
0
        public Concatenating(
            IReadScalar <INotifyCollectionChanged> sourcesScalar) : base(calculateCapacity(sourcesScalar.Value))
        {
            int capacity = Utils.getCapacity(sourcesScalar);

            _itemInfos            = new List <ItemInfo>(capacity);
            _sourceRangePositions = new RangePositions <ItemInfo>(_itemInfos);

            _sourcesScalar = sourcesScalar;
            _sourcesScalarPropertyChangedEventHandler     = handleSourcesScalarValueChanged;
            _sourcesScalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_sourcesScalarPropertyChangedEventHandler);
            _sourcesScalar.PropertyChanged += _sourcesScalarWeakPropertyChangedEventHandler.Handle;
            initializeFromSources();
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 6
0
        private void initializeFromSources()
        {
            int originalCount = _items.Count;

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

                int capacity = _sourcesScalar != null?Utils.getCapacity(_sourcesScalar) : Utils.getCapacity(_sources);

                _itemInfos            = new List <ItemInfo>(capacity);
                _sourceRangePositions = new RangePositions <ItemInfo>(_itemInfos);

                _sources.CollectionChanged -= _sourcesWeakNotifyCollectionChangedEventHandler.Handle;
                _sourcesNotifyCollectionChangedEventHandler     = null;
                _sourcesWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_sourcesAsINotifyPropertyChanged != null)
            {
                _sourcesAsINotifyPropertyChanged.PropertyChanged -=
                    _sourcesWeakPropertyChangedEventHandler.Handle;

                _sourcesAsINotifyPropertyChanged        = null;
                _sourcesPropertyChangedEventHandler     = null;
                _sourcesWeakPropertyChangedEventHandler = null;
            }

            if (_sourcesScalar != null)
            {
                _sources = _sourcesScalar.Value;
            }
            _sourcesAsList = (IList)_sources;

            if (_sources != null)
            {
                _sourcesAsIHasChangeMarker = _sourcesAsList as IHasChangeMarker;

                if (_sourcesAsIHasChangeMarker != null)
                {
                    _lastProcessedSourcesChangeMarker = _sourcesAsIHasChangeMarker.ChangeMarker;
                }
                else
                {
                    _sourcesAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourcesAsList;

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

                    _sourcesWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_sourcesPropertyChangedEventHandler);

                    _sourcesAsINotifyPropertyChanged.PropertyChanged +=
                        _sourcesWeakPropertyChangedEventHandler.Handle;
                }


                int plainIndex = 0;
                int count      = _sourcesAsList.Count;
                for (int index = 0; index < count; index++)
                {
                    object sourceItemObject = _sourcesAsList[index];
                    IReadScalar <object> sourceItemScalar = sourceItemObject as IReadScalar <object>;
                    IList    sourceItem      = sourceItemScalar != null ? (IList)sourceItemScalar.Value : (IList)sourceItemObject;
                    int      sourceItemCount = sourceItem?.Count ?? 0;
                    ItemInfo itemInfo        = _sourceRangePositions.Add(sourceItemCount);
                    registerSourceItem(sourceItemObject, itemInfo);

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

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

                _sourcesNotifyCollectionChangedEventHandler     = handleSourcesCollectionChanged;
                _sourcesWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourcesNotifyCollectionChangedEventHandler);

                _sources.CollectionChanged += _sourcesWeakNotifyCollectionChangedEventHandler.Handle;
            }
            else
            {
                _items.Clear();
            }

            reset();
        }
Ejemplo n.º 7
0
 private StringsConcatenating(int capacity)
 {
     _resultRangePositions = new RangePositions <RangePosition>(new List <RangePosition>(capacity * 2));
 }
Ejemplo n.º 8
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);
            }
        }
 private StringsConcatenating(int capacity)
 {
     _resultRangePositions = new RangePositions <RangePosition>(new List <RangePosition>(capacity * 2));
     _thisAsSourceCollectionChangeProcessor = this;
     _deferredQueuesCount = 2;
 }