Beispiel #1
0
        /// <summary>
        /// Add an entry to the catalog.
        /// </summary>
        private async Task AddCatalogCommits(IEnumerable <JObject> newPageCommits, string lastUpdatedPropertyName)
        {
            // Add catalog page entry
            var catalogIndexJson = await RootIndexFile.GetJson(_context.Log, _context.Token);

            catalogIndexJson["commitId"]        = _context.CommitId.ToString().ToLowerInvariant();
            catalogIndexJson["commitTimeStamp"] = DateTimeOffset.UtcNow.GetDateString();

            var pages = JsonUtility.GetItems(catalogIndexJson);

            var currentPageUri  = GetCurrentPage(catalogIndexJson);
            var currentPageFile = _context.Source.Get(currentPageUri);

            var pageCommits = new List <JObject>();

            var currentPageJson = await currentPageFile.GetJsonOrNull(_context.Log, _context.Token);

            if (currentPageJson != null)
            {
                pageCommits = JsonUtility.GetItems(currentPageJson);
            }
            else
            {
                var newPageEntry = CatalogUtility.CreateCatalogIndexPageEntry(currentPageUri, _context.CommitId);

                var pageArray = (JArray)catalogIndexJson["items"];
                pageArray.Add(newPageEntry);

                // Update pages
                pages = JsonUtility.GetItems(catalogIndexJson);
            }

            // Add all commits, this might go over the max catalog page size.
            // This could be improved to create new pages once over the limit if needed.
            pageCommits.AddRange(newPageCommits);

            // Write catalog page
            var pageJson = await CatalogUtility.CreateCatalogPageAsync(RootIndexFile.EntityUri, currentPageUri, pageCommits, _context.CommitId);

            await currentPageFile.Write(pageJson, _context.Log, _context.Token);

            // Update index
            CatalogUtility.UpdatePageIndex(catalogIndexJson, pageJson, _context.CommitId);

            catalogIndexJson[lastUpdatedPropertyName] = DateTimeOffset.UtcNow.GetDateString();

            catalogIndexJson = JsonLDTokenComparer.Format(catalogIndexJson);

            await RootIndexFile.Write(catalogIndexJson, _context.Log, _context.Token);
        }
Beispiel #2
0
        /// <summary>
        /// Add an entry to the catalog.
        /// </summary>
        private async Task AddCatalogEntry(JObject pageCommit, string lastUpdatedPropertyName)
        {
            // Add catalog page entry
            var catalogIndexJson = await RootIndexFile.GetJson(_context.Log, _context.Token);

            catalogIndexJson["commitId"]        = _context.CommitId.ToString().ToLowerInvariant();
            catalogIndexJson["commitTimeStamp"] = DateTimeOffset.UtcNow.GetDateString();

            var pages = JsonUtility.GetItems(catalogIndexJson);

            var currentPageUri  = GetCurrentPage(catalogIndexJson);
            var currentPageFile = _context.Source.Get(currentPageUri);

            var pageCommits = new List <JObject>();

            var currentPageJson = await currentPageFile.GetJsonOrNull(_context.Log, _context.Token);

            if (currentPageJson != null)
            {
                pageCommits = JsonUtility.GetItems(currentPageJson);
            }
            else
            {
                var newPageEntry = CatalogUtility.CreateCatalogIndexPageEntry(currentPageUri, _context.CommitId);

                var pageArray = (JArray)catalogIndexJson["items"];
                pageArray.Add(newPageEntry);

                // Update pages
                pages = JsonUtility.GetItems(catalogIndexJson);
            }

            pageCommits.Add(pageCommit);

            // Write catalog page
            var pageJson = await CatalogUtility.CreateCatalogPageAsync(RootIndexFile.EntityUri, currentPageUri, pageCommits, _context.CommitId);

            await currentPageFile.Write(pageJson, _context.Log, _context.Token);

            // Update index
            CatalogUtility.UpdatePageIndex(catalogIndexJson, pageJson, _context.CommitId);

            catalogIndexJson[lastUpdatedPropertyName] = DateTimeOffset.UtcNow.GetDateString();

            catalogIndexJson = JsonLDTokenComparer.Format(catalogIndexJson);

            await RootIndexFile.Write(catalogIndexJson, _context.Log, _context.Token);
        }