/// <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); }
/// <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); }
/// <summary> /// Returns all pages from the catalog index. /// </summary> public async Task <List <JObject> > GetPagesAsync() { var pageTasks = new List <Task <JObject> >(); var catalogIndexJson = await RootIndexFile.GetJsonOrNull(_context.Log, _context.Token); if (catalogIndexJson != null) { var items = (JArray)catalogIndexJson["items"]; foreach (var item in items) { var itemUrl = item["@id"].ToObject <Uri>(); var itemFile = _context.Source.Get(itemUrl); pageTasks.Add(itemFile.GetJson(_context.Log, _context.Token)); } await Task.WhenAll(pageTasks); } return(pageTasks.Select(e => e.Result).ToList()); }
public Task PreLoadAsync(SleetOperations operations) { return(RootIndexFile.FetchAsync(_context.Log, _context.Token)); }
public Task FetchAsync() { return(RootIndexFile.FetchAsync(_context.Log, _context.Token)); }