Ejemplo n.º 1
0
 protected bool Equals(ChangeStatistics other)
 {
     return(_index == other._index &&
            _adds == other._adds &&
            _updates == other._updates && _removes == other._removes && _evaluates == other._evaluates &&
            _count == other._count && _timestamp.Equals(other._timestamp));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Accumulates update statistics.
        /// </summary>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="source">The source.</param>
        /// <returns>An observable which emits the change summary.</returns>
        /// <exception cref="System.ArgumentNullException">source.</exception>
        public static IObservable <ChangeSummary> CollectUpdateStats <TSource, TKey>(this IObservable <IChangeSet <TSource, TKey> > source)
            where TKey : notnull
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(source.Scan(
                       ChangeSummary.Empty,
                       (seed, next) =>
            {
                int index = seed.Overall.Index + 1;
                int adds = seed.Overall.Adds + next.Adds;
                int updates = seed.Overall.Updates + next.Updates;
                int removes = seed.Overall.Removes + next.Removes;
                int evaluates = seed.Overall.Refreshes + next.Refreshes;
                int moves = seed.Overall.Moves + next.Moves;
                int total = seed.Overall.Count + next.Count;

                var latest = new ChangeStatistics(index, next.Adds, next.Updates, next.Removes, next.Refreshes, next.Moves, next.Count);
                var overall = new ChangeStatistics(index, adds, updates, removes, evaluates, moves, total);
                return new ChangeSummary(index, latest, overall);
            }));
        }