public ActiveListJoinerData(bool isLeftJoiner, ActiveListJoinBehaviour joinBehaviour, TKey key, Func <JoinOption <TLeft>, JoinOption <TRight>, TResult> resultSelector, IEnumerable <string> leftResultSelectorPropertiesToWatch, IEnumerable <string> rightResultSelectorPropertiesToWatch)
        {
            Key = key;

            IsLeftJoiner = isLeftJoiner;

            Joiner = CreateJoiner(joinBehaviour, resultSelector, leftResultSelectorPropertiesToWatch, rightResultSelectorPropertiesToWatch);
        }
        private static ActiveListJoinerToReadOnlyList <int, int, int> CreateHasLeft(ActiveListJoinBehaviour joinBehaviour, out ObservableList <int> right)
        {
            right = new ObservableList <int>();
            var joiner = new ActiveListJoiner <int, int, int>(joinBehaviour, (l, r) => l.GetOrElse(0) + r.GetOrElse(0), null, null);
            var result = new ActiveListJoinerToReadOnlyList <int, int, int>(joiner);

            joiner.SetBoth(1, right);
            return(result);
        }
        private static void TestHasLeftSetRight(ActiveListJoinBehaviour joinBehaviour, int[] initial, int[] result)
        {
            var sut = CreateHasLeft(joinBehaviour, out var right);

            Assert.True(sut.SequenceEqual(initial));

            sut.SetRight(new[] { 20, 200, 2000 });

            Assert.True(sut.SequenceEqual(result));
        }
        private static void TestEmptySetLeft(ActiveListJoinBehaviour joinBehaviour, int[] initial, int[] result)
        {
            var sut = CreateEmpty(joinBehaviour, out var right);

            Assert.True(sut.SequenceEqual(initial));

            sut.SetLeft(3);

            Assert.True(sut.SequenceEqual(result));
        }
        private static void TestHasBothMoveRight(ActiveListJoinBehaviour joinBehaviour, int[] initial, int[] result)
        {
            var sut = CreateHasBoth(joinBehaviour, out var right);

            Assert.True(sut.SequenceEqual(initial));

            right.Move(1, 0);

            Assert.True(sut.SequenceEqual(result));
        }
        public ActiveListJoinerSet(ActiveListJoinBehaviour joinBehaviour, TKey key, IActiveLookup <TKey, TRight> right, Func <JoinOption <TLeft>, JoinOption <TRight>, TResult> resultSelector, IEnumerable <string> leftResultSelectorPropertiesToWatch, IEnumerable <string> rightResultSelectorPropertiesToWatch)
        {
            Key = key;

            _joinBehaviour  = joinBehaviour;
            _right          = right[key];
            _resultSelector = resultSelector;
            _leftResultSelectorPropertiesToWatch  = leftResultSelectorPropertiesToWatch;
            _rightResultSelectorPropertiesToWatch = rightResultSelectorPropertiesToWatch;
        }
Exemple #7
0
        private ActiveJoin(ActiveListJoinBehaviour joinBehaviour, IActiveList <KeyValuePair <TKey, TLeft> > left, IActiveLookup <TKey, TRight> right, IActiveValue <TParameter> parameter, Func <JoinOption <TLeft>, JoinOption <TRight>, TParameter, TResult> resultSelector, IEnumerable <string> leftResultSelectorPropertiesToWatch, IEnumerable <string> rightResultSelectorPropertiesToWatch, IEnumerable <string> resultSelectorParameterPropertiesToWatch)
        {
            _joinBehaviour  = joinBehaviour;
            _parameter      = parameter;
            _resultSelector = resultSelector;

            _leftResultSelectorPropertiesToWatch  = leftResultSelectorPropertiesToWatch;
            _rightResultSelectorPropertiesToWatch = rightResultSelectorPropertiesToWatch;

            if (parameter != null)
            {
                _parameterWatcher = new ValueWatcher <TParameter>(parameter, resultSelectorParameterPropertiesToWatch);
                _parameterWatcher.ValueOrValuePropertyChanged += () => OnParameterChanged();
            }

            _leftJoiners  = new QuickList <ActiveListJoinerData <TLeft, TRight, TResult, TKey> >();
            _rightJoiners = new QuickList <ActiveListJoinerData <TLeft, TRight, TResult, TKey> >();
            _joinerLookup = new Dictionary <TKey, ActiveListJoinerSet <TLeft, TRight, TResult, TKey> >();

            _leftItems = new CollectionWrapper <KeyValuePair <TKey, TLeft> >(left);
            _leftItems.ItemModified += (s, i, v) => OnLeftReplaced(i, v, v);
            _leftItems.ItemAdded    += (s, i, v) => OnLeftAdded(i, v);
            _leftItems.ItemRemoved  += (s, i, v) => OnLeftRemoved(i, v);
            _leftItems.ItemReplaced += (s, i, o, n) => OnLeftReplaced(i, o, n);
            _leftItems.ItemMoved    += (s, o, n, v) => OnLeftMoved(o, n, v);
            _leftItems.ItemsReset   += s => FullReset();

            _rightItems = right;

            _rightGroups = new CollectionWrapper <IActiveGrouping <TKey, TRight> >(right);
            _rightGroups.ItemModified += (s, i, v) => OnRightReplaced(i, v, v);
            _rightGroups.ItemAdded    += (s, i, v) => OnRightAdded(i, v);
            _rightGroups.ItemRemoved  += (s, i, v) => OnRightRemoved(i, v);
            _rightGroups.ItemReplaced += (s, i, o, n) => OnRightReplaced(i, o, n);
            _rightGroups.ItemMoved    += (s, o, n, v) => OnRightMoved(o, n, v);
            _rightGroups.ItemsReset   += s => FullReset();

            _resultList = new ObservableList <TResult>();
            _resultList.PropertyChanged += (s, e) =>
            {
                if (!_fullResetInProgress)
                {
                    NotifyOfPropertyChange(e);
                }
            };
            _resultList.CollectionChanged += (s, e) =>
            {
                if (!_fullResetInProgress)
                {
                    NotifyOfCollectionChange(e);
                }
            };

            FullReset();
        }
Exemple #8
0
 public ActiveJoin(ActiveListJoinBehaviour joinBehaviour, IActiveList <TLeft> source, IReadOnlyList <TRight> join, IActiveValue <TParameter> parameter, Func <TLeft, TParameter, TKey> leftKeySelector, Func <TRight, TParameter, TKey> rightKeySelector, Func <JoinOption <TLeft>, JoinOption <TRight>, TParameter, TResult> resultSelector, IEnumerable <string> leftKeySelectorPropertiesToWatch, IEnumerable <string> rightKeySelectorPropertiesToWatch, IEnumerable <string> leftResultSelectorPropertiesToWatch, IEnumerable <string> rightResultSelectorPropertiesToWatch, IEnumerable <string> leftKeySelectorParameterPropertiesToWatch, IEnumerable <string> rightKeySelectorParameterPropertiesToWatch, IEnumerable <string> resultSelectorParameterPropertiesToWatch)
     : this(
         joinBehaviour,
         source.ActiveSelect(parameter, (l, p) => new KeyValuePair <TKey, TLeft>(leftKeySelector.Invoke(l, p), l), leftKeySelectorPropertiesToWatch, leftKeySelectorParameterPropertiesToWatch),
         join.ToActiveList().ToActiveLookup(parameter, rightKeySelector, rightKeySelectorPropertiesToWatch, rightKeySelectorParameterPropertiesToWatch),
         parameter,
         resultSelector,
         leftResultSelectorPropertiesToWatch,
         rightResultSelectorPropertiesToWatch,
         resultSelectorParameterPropertiesToWatch)
 {
 }
        private static void TestHasRightReplaceInRight(ActiveListJoinBehaviour joinBehaviour, int[] initial, int[] result)
        {
            var sut = CreateHasRight(joinBehaviour, out var right);

            Assert.True(sut.SequenceEqual(initial));

            right.Replace(0, 20);
            right.Replace(2, 2000);
            right.Replace(1, 200);

            Assert.True(sut.SequenceEqual(result));
        }
        private static void TestHasLeftAddToRight(ActiveListJoinBehaviour joinBehaviour, int[] initial, int[] result)
        {
            var sut = CreateHasLeft(joinBehaviour, out var right);

            Assert.True(sut.SequenceEqual(initial));

            right.Add(0, 20);
            right.Add(1, 2000);
            right.Add(1, 200);

            Assert.True(sut.SequenceEqual(result));
        }
        public ActiveListJoiner(ActiveListJoinBehaviour joinBehaviour, Func <JoinOption <TLeft>, JoinOption <TRight>, TResult> resultSelector, IEnumerable <string> leftResultSelectorPropertiesToWatch, IEnumerable <string> rightResultSelectorPropertiesToWatch)
        {
            _joinBehaviour = joinBehaviour;

            _resultSelector = resultSelector;

            _left        = ActiveValue.Create <TLeft>();
            _leftWatcher = new ValueWatcher <TLeft>(_left, leftResultSelectorPropertiesToWatch);
            _leftWatcher.ValuePropertyChanged += () => OnLeftChanged();

            _rightCollectionWrappper = new CollectionWrapper <TRight>(null, rightResultSelectorPropertiesToWatch?.ToArray());
            _rightCollectionWrappper.ItemModified += (s, i, v) => OnRightReplaced(i, v, v);
            _rightCollectionWrappper.ItemAdded    += (s, i, v) => OnRightAdded(i, v);
            _rightCollectionWrappper.ItemRemoved  += (s, i, v) => OnRightRemoved(i, v);
            _rightCollectionWrappper.ItemReplaced += (s, i, o, n) => OnRightReplaced(i, o, n);
            _rightCollectionWrappper.ItemMoved    += (s, o, n, v) => OnRightMoved(o, n, v);
            _rightCollectionWrappper.ItemsReset   += s => OnRightReset(s);
        }
 private ActiveListJoiner <TLeft, TRight, TResult> CreateJoiner(ActiveListJoinBehaviour joinBehaviour, Func <JoinOption <TLeft>, JoinOption <TRight>, TResult> resultSelector, IEnumerable <string> leftResultSelectorPropertiesToWatch, IEnumerable <string> rightResultSelectorPropertiesToWatch)
 => new ActiveListJoiner <TLeft, TRight, TResult>(joinBehaviour, resultSelector, leftResultSelectorPropertiesToWatch, rightResultSelectorPropertiesToWatch);