private void recalculateValue()
        {
            _resultRangePositions.List.Clear();
            _valueStringBuilder.Clear();
            _sourceCount = _sourceAsList.Count;
            string[] sourceCopy = new string[_sourceCount];
            _sourceAsList.CopyTo(sourceCopy, 0);

            for (int sourceIndex = 0; sourceIndex < _sourceCount; sourceIndex++)
            {
                string sourceItem = sourceCopy[sourceIndex];
                _valueStringBuilder.Append(sourceItem);
                // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                _resultRangePositions.Add(sourceItem?.Length ?? 0);

                if (sourceIndex != _sourceCount - 1)
                {
                    _valueStringBuilder.Append(_separator);
                    // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    _resultRangePositions.Add(_separatorLength);
                }
            }

            setValue(_valueStringBuilder.ToString());
        }
Пример #2
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;
                }
            }
        }
Пример #3
0
        private void recalculateValue()
        {
            _resultRangePositions.List.Clear();
            _valueStringBuilder.Clear();
            int count = _sourceAsList.Count;

            for (int sourceIndex = 0; sourceIndex < count; sourceIndex++)
            {
                string sourceItem = _sourceAsList[sourceIndex];
                _valueStringBuilder.Append(sourceItem);
                // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                _resultRangePositions.Add(sourceItem != null ? sourceItem.Length : 0);

                if (sourceIndex != count - 1)
                {
                    _valueStringBuilder.Append(_separator);
                    // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    _resultRangePositions.Add(_separatorLength);
                }
            }

            setValue(_valueStringBuilder.ToString());
        }
Пример #4
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();
        }
        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();
        }
        protected override void initializeFromSource()
		{
			int originalCount = _items.Count;

			if (_sourceInitialized)
			{
				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(_sourcesScalar, _sources),
                    out _itemInfos,
                    out _sourceRangePositions);

				_sources.CollectionChanged -= handleSourcesCollectionChanged;

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

                _sourceInitialized = false;
            }

            Utils.changeSource(ref _sources, _sourcesScalar, _downstreamConsumedComputings, _consumers, this,
                ref _sourcesAsList, true);

			if (_sources != 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];
					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);
                    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);
				}

				_sources.CollectionChanged += handleSourcesCollectionChanged;
                _sourceInitialized = true;
            }
			else
			{
				_items.Clear();
			}

			reset();
		}