Ejemplo n.º 1
0
        public TableItem(T item, Func <T, int> keyGenerator)
        {
            _deduplicationKey = null;
            _keyGenerator     = keyGenerator;

            _cache  = null;
            Primary = item;
        }
Ejemplo n.º 2
0
        public TableItem(IEnumerable <TableItem <T> > items)
        {
            var first          = true;
            var collectionHash = 1;
            var count          = 0;

            // Make things to be deterministic.
            var orderedItems = items.Where(i => i.PrimaryDocumentId != null).OrderBy(i => i.PrimaryDocumentId.Id).ToList();

            if (orderedItems.Count == 0)
            {
                // There must be at least 1 item in the list
                FatalError.ReportWithoutCrash(new ArgumentException("Contains no items", nameof(items)));
            }
            else if (orderedItems.Count != items.Count())
            {
                // There must be document id for provided items.
                FatalError.ReportWithoutCrash(new ArgumentException("Contains an item with null PrimaryDocumentId", nameof(items)));
            }

            foreach (var item in orderedItems)
            {
                count++;

                if (first)
                {
                    Primary = item.Primary;

                    _deduplicationKey = item.DeduplicationKey;
                    _keyGenerator     = null;

                    first = false;
                }

                collectionHash = Hash.Combine(item.PrimaryDocumentId.Id.GetHashCode(), collectionHash);
            }

            if (count == 1)
            {
                _cache = null;
                return;
            }

            // order of item is important. make sure we maintain it.
            _cache = SharedInfoCache.GetOrAdd(collectionHash, orderedItems, c => new SharedInfoCache(c.Select(i => i.PrimaryDocumentId).ToImmutableArray()));
        }
Ejemplo n.º 3
0
        public TableItem(IEnumerable <TableItem <T> > items)
        {
#if DEBUG
            // If code reached here,
            // There must be at least 1 item in the list
            Contract.ThrowIfFalse(items.Count() > 0);

            // There must be document id
            Contract.ThrowIfTrue(items.Any(i => i.PrimaryDocumentId == null));
#endif

            var first          = true;
            var collectionHash = 1;
            var count          = 0;

            // Make things to be deterministic.
            var ordereditems = items.OrderBy(i => i.PrimaryDocumentId.Id);
            foreach (var item in ordereditems)
            {
                count++;

                if (first)
                {
                    Primary = item.Primary;

                    _deduplicationKey = item.DeduplicationKey;
                    _keyGenerator     = null;

                    first = false;
                }

                collectionHash = Hash.Combine(item.PrimaryDocumentId.Id.GetHashCode(), collectionHash);
            }

            if (count == 1)
            {
                _cache = null;
                return;
            }

            // order of item is important. make sure we maintain it.
            _cache = SharedInfoCache.GetOrAdd(collectionHash, ordereditems, c => new SharedInfoCache(c.Select(i => i.PrimaryDocumentId).ToImmutableArray()));
        }