Beispiel #1
0
        public async Task InsertAsync(int index, LeafInfo leafInfo)
        {
            var page = await GetPageAsync();

            var leafInfos = await GetMutableLeafInfosAsync();

            if (index > 0)
            {
                Guard.Assert(
                    leafInfos[index - 1].Version < leafInfo.Version,
                    "The version added to a page must have a higher version than the item before it.");
            }

            if (index < leafInfos.Count)
            {
                Guard.Assert(
                    leafInfos[index].Version > leafInfo.Version,
                    "The version added to a page must have a lower version than the item after it.");
            }

            // Add to the real page, for future serialization.
            page.Items.Insert(index, leafInfo.LeafItem);

            // Add to the leaf info list, for bookeeping.
            leafInfos.Insert(index, leafInfo);

            Count++;
            UpdateBounds(page, leafInfos);
        }
Beispiel #2
0
        private async Task InsertAsync(
            Context context,
            PageInfo pageInfo,
            int index,
            CatalogCommitItem entry)
        {
            if (entry.IsPackageDelete)
            {
                // No matching version was found for this delete. No more work is necessary.
                _logger.LogInformation(
                    "Version {Version} does not exist. The delete from commit {CommitId} will have no affect.",
                    entry.PackageIdentity.Version.ToNormalizedString(),
                    entry.CommitId);
            }
            else
            {
                // Insert the new registration leaf item.
                _logger.LogInformation(
                    "Version {Version} will be added by commit {CommitId}.",
                    entry.PackageIdentity.Version.ToNormalizedString(),
                    entry.CommitId);
                var leafInfo = LeafInfo.New(entry.PackageIdentity.Version);
                await pageInfo.InsertAsync(index, leafInfo);

                context.ModifiedLeaves.Add(leafInfo);
                context.ModifiedPages.Add(pageInfo);
            }
        }
Beispiel #3
0
        private static void Initialize(PageInfo pageInfo, RegistrationPage page)
        {
            // Ensure the page is sorted in ascending order by version.
            var leafInfos = page
                            .Items
                            .Select(x => LeafInfo.Existing(x))
                            .OrderBy(x => x.Version)
                            .ToList();

            page.Items.Clear();
            page.Items.AddRange(leafInfos.Select(x => x.LeafItem));

            // Update the bookkeeping with the latest information. The leaf items themselves are the "true" for the
            // count, lower bound, and upper bound properties not whatever might be set on the page item.
            pageInfo._page      = page;
            pageInfo._leafInfos = leafInfos;
            pageInfo.Count      = page.Items.Count;
            pageInfo.Lower      = leafInfos.FirstOrDefault()?.Version;
            pageInfo.Upper      = leafInfos.LastOrDefault()?.Version;
        }