コード例 #1
0
 public ActiveListBase(IActiveList <TSource> source, Func <TResultItem, TResult> resultSelector, IActiveValue <TParameter> parameter, IEnumerable <string> sourcerPropertiesToWatch = null, IEnumerable <string> parameterPropertiesToWatch = null)
     : base(source, parameter, sourcerPropertiesToWatch, parameterPropertiesToWatch)
 {
     ResultList = CreateResultList(resultSelector);
     ResultList.CollectionChanged += (s, e) => NotifyOfCollectionChange(e);
     ResultList.PropertyChanged   += (s, e) => NotifyOfPropertyChange(e);
 }
コード例 #2
0
        private ActiveMinOrDefault(IActiveList <TSource> source, IActiveValue <TParameter> parameter, Func <TSource, TValue> selector, IEnumerable <string> sourcePropertiesToWatch, IEnumerable <string> parameterPropertiesToWatch)
            : base(source, parameter, selector, sourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _comparer = Comparer <TValue> .Default;

            Initialize();
        }
コード例 #3
0
        public ActiveWhereBase(IActiveList <TSource> source, Func <TSource, bool> predicate, Func <TSource, TResult> resultSelector, IActiveValue <TParameter> parameter, IEnumerable <string> sourcePropertiesToWatch, IEnumerable <string> parameterPropertiesToWatch)
            : base(source, resultSelector, parameter, sourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _predicate = predicate ?? throw new ArgumentNullException(nameof(predicate));

            _indexList = new QuickList <int>();
        }
コード例 #4
0
        public static IActiveValue <bool> ActiveSequenceEqual <TSource>(this IActiveList <TSource> source, IEnumerable <TSource> otherSource)
        {
            var comparer = EqualityComparer <TSource> .Default;

            return(new ActiveSequenceEqual <TSource, object>(source, otherSource.ToReadOnlyList(), (o1, o2)
                                                             => comparer.Equals(o1, o2), null));
        }
コード例 #5
0
 public ActiveMultiListBase(IActiveList <TSource> source, IActiveValue <TParameter> parameter, IEnumerable <string> sourcePropertiesToWatch = null, IEnumerable <string> otherSourcePropertiesToWatch = null, IEnumerable <string> parameterPropertiesToWatch = null)
     : base(source, parameter, sourcePropertiesToWatch, otherSourcePropertiesToWatch, parameterPropertiesToWatch)
 {
     ResultList = new ObservableList <TResult>();
     ResultList.CollectionChanged += (s, e) => NotifyOfCollectionChange(e);
     ResultList.PropertyChanged   += (s, e) => NotifyOfPropertyChange(e);
 }
コード例 #6
0
        public static IObservable <ItemAdded <T> > ObserveAddedWithIndex <T>(this IActiveList <T> list)
        {
            var subject = new Subject <ItemAdded <T> >();

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                case NotifyCollectionChangedAction.Replace:
                    subject.OnNext(new ItemAdded <T>((T)e.NewItems[0], e.NewStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Reset:
                    for (int i = 0; i < list.Count; ++i)
                    {
                        subject.OnNext(new ItemAdded <T>(list[i], i));
                    }
                    break;
                }
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }
コード例 #7
0
        private ActiveAverageOrDefault(IActiveList <TSource> source, IActiveValue <TParameter> parameter, Func <TSource, TValue> selector, Func <TValue, TValue, TValue> adder, Func <TValue, TValue, TValue> subtractor, Func <TValue, int, TResult> divider, IEnumerable <string> sourcePropertiesToWatch, IEnumerable <string> parameterPropertiesToWatch)
            : base(source, parameter, selector, adder, subtractor, sourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _divider = divider;

            Initialize();
        }
コード例 #8
0
        public ActiveSetContains(IActiveList <TSource> source, IActiveSet <TSet> set, IActiveValue <TSet> value)
            : base(source, value)
        {
            _set = set;

            Value = _set.Contains(ParameterValue);
        }
コード例 #9
0
        private ActiveSelectMany(IActiveList <TSource> source, Func <TSource, IEnumerable <TResult> > selector, IActiveValue <TParameter> parameter, IEnumerable <string> sourcePropertiesToWatch, IEnumerable <string> parameterPropertiesToWatch)
            : base(source, parameter, sourcePropertiesToWatch, sourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _selector = selector ?? throw new ArgumentNullException(nameof(selector));

            Initialize();
        }
コード例 #10
0
 /// <summary>
 ///Creates a result
 ///@param activeList the active list associated with this result
 ///@param resultList the result list associated with this result
 ///@param frameNumber the frame number for this result.
 ///@param isFinal if true, the result is a final result
 /// <summary>
 public DecoderResult(IAlternateHypothesisManager alternateHypothesisManager,
                      IActiveList activeList, List <IToken> resultList, int frameNumber,
                      Boolean isFinal, Boolean wordTokenFirst)
     : this(activeList, resultList, frameNumber, isFinal)
 {
     this.alternateHypothesisManager = alternateHypothesisManager;
     this.wordTokenFirst             = wordTokenFirst;
 }
コード例 #11
0
 /// <summary>
 ///Creates a result
 ///@param activeList the active list associated with this result
 ///@param resultList the result list associated with this result
 ///@param frameNumber the frame number for this result.
 ///@param isFinal if true, the result is a final result. This means that the last frame in the
 ///       speech segment has been decoded.
 /// <summary>
 public DecoderResult(IActiveList activeList, List <IToken> resultList, int frameNumber, Boolean isFinal)
 {
     this.activeList         = activeList;
     this.resultList         = resultList;
     this.currentFrameNumber = frameNumber;
     this._isFinal           = isFinal;
     logMath = LogMath.getLogMath();
 }
コード例 #12
0
        public ActiveContains(IActiveList <TSource> source, IActiveValue <TSource> value)
            : base(source, null, item => Equals(item, value.Value))
        {
            _value = value;

            PropertyChangedEventManager.AddHandler(_value, SourceChanged, nameof(IActiveValue <TSource> .Value));

            Initialize();
        }
コード例 #13
0
		private ActiveCount(IActiveList<TSource> source, IActiveValue<TParameter> parameter, Func<TSource, bool> predicate, IEnumerable<string> sourcePropertiesToWatch, IEnumerable<string> parameterPropertiesToWatch) 
			: base(source, parameter, sourcePropertiesToWatch, parameterPropertiesToWatch)
		{
			_predicate = predicate;

			_values = new BooleanList();

			Initialize();
		}
コード例 #14
0
        public ActiveOrderBy(IActiveList <TSource> source, Func <TSource, TKey> keySelector, IActiveValue <ListSortDirection> sortDirection, IEnumerable <string> propertiesToWatch)
            : base(source, i => i.Value, sortDirection, propertiesToWatch)
        {
            _keySelector = keySelector;

            _sourceList = new QuickList <ItemSet>();

            Initialize();
        }
コード例 #15
0
        public ActiveElementAtOrDefault(IActiveList <TSource> source, IActiveValue <int> index)
            : base(source)
        {
            _index = index;

            PropertyChangedEventManager.AddHandler(_index, IndexChanged, nameof(IActiveValue <TSource> .Value));

            Initialize();
        }
コード例 #16
0
        public ActiveListPredicateBase(IActiveList <TSource> source, IActiveValue <TParameter> parameter, Func <TSource, bool> predicate, IEnumerable <string> sourcePropertiesToWatch = null, IEnumerable <string> parameterPropertiesToWatch = null)
            : base(source, parameter, sourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _predicate = predicate;

            Value = GetValue(false);

            Initialize();
        }
コード例 #17
0
 public ActiveReverse(IActiveList <TSource> source)
     : base(source)
 {
     if (SourceList is INotifyPropertyChanged)
     {
         PropertyChangedEventManager.AddHandler(SourceList as INotifyPropertyChanged, SourceCountChanged, nameof(IReadOnlyList <TSource> .Count));
     }
     Initialize();
 }
コード例 #18
0
        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;
        }
コード例 #19
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();
        }
コード例 #20
0
        public ActiveSkip(IActiveList <TSource> source, IActiveValue <int> count)
            : base(source)
        {
            _skipCount = count;

            PropertyChangedEventManager.AddHandler(_skipCount, SkipCountChanged, nameof(IActiveValue <int> .Value));

            UpdateSkipCount();

            Initialize();
        }
コード例 #21
0
        private ActiveLookup(IActiveList <TSource> source, Func <TSource, TKey> keySelector, IActiveValue <TParameter> parameter, IEnumerable <string> sourcePropertiesToWatch, IEnumerable <string> parameterPropertiesToWatch)
            : base(source, i => i.Items, parameter, sourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _sourceData  = new QuickList <ItemData>();
            _resultSet   = new Dictionary <TKey, GroupData>();
            _emptyGroups = new Dictionary <TKey, GroupData>();

            _keySelector = keySelector;

            Initialize();
        }
コード例 #22
0
        public static IObservable <ItemRemoved <T> > ObserveRemovedWithIndex <T>(this IActiveList <T> list)
        {
            var subject = new Subject <ItemRemoved <T> >();

            var copy = new List <T>(list.Count + 8);

            foreach (var item in list)
            {
                copy.Add(item);
            }

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    copy.Insert(e.NewStartingIndex, (T)e.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    copy.RemoveAt(e.OldStartingIndex);
                    subject.OnNext(new ItemRemoved <T>((T)e.OldItems[0], e.OldStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Replace:
                    copy[e.NewStartingIndex] = (T)e.NewItems[0];
                    subject.OnNext(new ItemRemoved <T>((T)e.OldItems[0], e.OldStartingIndex));
                    break;

                case NotifyCollectionChangedAction.Move:
                    copy.RemoveAt(e.OldStartingIndex);
                    copy.Insert(e.NewStartingIndex, (T)e.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Reset:
                    for (int i = copy.Count - 1; i >= 0; --i)
                    {
                        subject.OnNext(new ItemRemoved <T>(copy[i], i));
                    }
                    copy.Clear();
                    foreach (var item in list)
                    {
                        copy.Add(item);
                    }
                    break;
                }
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }
コード例 #23
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)
 {
 }
コード例 #24
0
        public ActiveConcat(IActiveList <TSource> source, IEnumerable <TSource> concat)
            : base(source, null)
        {
            if (concat == null)
            {
                throw new ArgumentNullException(nameof(concat));
            }

            AddSourceCollection(0, (concat as IReadOnlyList <TSource>) ?? concat.ToArray());

            Initialize();
        }
コード例 #25
0
        private void Setup(out DataTable table, out IActiveList <DataRow> sut, out CollectionSynchronizationWatcher <DataRow> watcher)
        {
            RandomGenerator.ResetRandomGenerator();

            table = new DataTable();

            table.Rows.Add(table.NewRow());
            table.Rows.Add(table.NewRow());

            sut = table.ToActiveList();

            watcher = new CollectionSynchronizationWatcher <DataRow>(sut);
        }
コード例 #26
0
        private ActiveZip(IActiveList <TSource> source, IReadOnlyList <TOtherSource> otherSource, Func <TSource, TOtherSource, TResult> resultSelector, IActiveValue <TParameter> parameter, IEnumerable <string> sourcePropertiesToWatch, IEnumerable <string> otherSourcePropertiesToWatch, IEnumerable <string> parameterPropertiesToWatch)
            : base(source, parameter, sourcePropertiesToWatch, otherSourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _resultSelector = resultSelector ?? throw new ArgumentNullException(nameof(resultSelector));

            if (otherSource == null)
            {
                throw new ArgumentNullException(nameof(otherSource));
            }

            AddSourceCollection(0, otherSource);

            Initialize();
        }
コード例 #27
0
        public ActiveElementsOrEmpty(IActiveList <TSource> source, IReadOnlyList <int> indexes)
            : base(source, null)
        {
            if (indexes == null)
            {
                throw new ArgumentNullException(nameof(indexes));
            }

            _indexes = new QuickList <Item>();

            Initialize();

            AddSourceCollection(0, indexes);
        }
コード例 #28
0
        public ActiveListListenerBase(IActiveList <TSource> source, IActiveValue <TParameter> parameter, IEnumerable <string> sourcePropertiesToWatch = null, IEnumerable <string> parameterPropertiesToWatch = null)
        {
            _sourceList = new CollectionWrapper <TSource>(source, sourcePropertiesToWatch?.ToArray());
            _sourceList.ItemModified += (s, i, v) => ItemModified(i, v);
            _sourceList.ItemAdded    += (s, i, v) => OnAdded(i, v);
            _sourceList.ItemRemoved  += (s, i, v) => OnRemoved(i, v);
            _sourceList.ItemReplaced += (s, i, o, n) => OnReplaced(i, o, n);
            _sourceList.ItemMoved    += (s, o, n, v) => OnMoved(o, n, v);
            _sourceList.ItemsReset   += s => OnReset(s);

            if (parameter != null)
            {
                _parameterWatcher = new ValueWatcher <TParameter>(parameter, parameterPropertiesToWatch);
                _parameterWatcher.ValueOrValuePropertyChanged += () => OnParameterChanged();
            }
        }
コード例 #29
0
        public ActiveSetBase(IActiveList <TSource> leftSource, IReadOnlyList <TSource> rightSource, Func <TSource, TKey> keySelector, IActiveValue <TParameter> parameter, IEnumerable <string> sourcePropertiesToWatch, IEnumerable <string> parameterPropertiesToWatch)
            : base(leftSource, parameter, sourcePropertiesToWatch, sourcePropertiesToWatch, parameterPropertiesToWatch)
        {
            _keySelector = keySelector ?? throw new ArgumentNullException(nameof(keySelector));

            _leftKeys  = new QuickList <SourcePair>();
            _rightKeys = new QuickList <SourcePair>();

            _cumulativeList = new List <ResultSet>();
            _leftCount      = new Dictionary <TKey, SourceSet>();

            _resultList = new ObservableList <ResultSet>();
            _resultList.CollectionChanged += (s, e) => NotifyOfCollectionChange(RewrapEventArgs(e));
            _resultList.PropertyChanged   += (s, e) => NotifyOfPropertyChange(e);

            if (rightSource != null)
            {
                _rightCount = new Dictionary <TKey, SourceSet>();
                AddSourceCollection(0, rightSource, true);
            }

            Initialize();
        }
コード例 #30
0
        public static IObservable <IReadOnlyList <T> > ObserveAll <T>(this IActiveList <T> list)
        {
            var subject = new Subject <IReadOnlyList <T> >();

            var handler = new EventHandler <NotifyCollectionChangedEventArgs>((o, e) =>
            {
                var count = list.Count;

                var array = new T[count];
                for (int i = 0; i < count; ++i)
                {
                    array[i] = list[i];
                }

                subject.OnNext(array);
            });

            CollectionChangedEventManager.AddHandler(list, handler);

            subject.Subscribe(_ => { }, () => CollectionChangedEventManager.RemoveHandler(list, handler));

            return(subject);
        }