private static void SetPageItemsDownloaded(IEnumerable <Objects.LatestPageIndexItem> items, string languageCode) { string fileName = string.Format("AgilityPageIndex_{0}.bin", languageCode); string pageIndexFilePath = Path.Combine(BaseCache.GetLocalContentFilePath(), fileName); lock (_pageIndexLock) { Objects.LatestPageIndex index = GetLatestPageItemIndex(languageCode); if (index == null) { return; } Objects.LatestPageIndexItem indexItem = null; foreach (var item in items) { if (index.Index.TryGetValue(item.PageID, out indexItem)) { indexItem.Downloaded = item.Downloaded; } } BaseCache.WriteFile(index, pageIndexFilePath); AgilityContext.HttpContext.Items[fileName] = index; } }
private static Objects.LatestContentItemIndex GetLatestContentItemIndex(string languageCode) { string fileName = string.Format("AgilityContentIndex_{0}.bin", languageCode); string contentIndexFilePath = Path.Combine(BaseCache.GetLocalContentFilePath(), fileName); Objects.LatestContentItemIndex index = AgilityContext.HttpContext.Items[fileName] as Objects.LatestContentItemIndex; if (index == null) { lock (_contentIndexLock) { index = AgilityContext.HttpContext.Items[fileName] as Objects.LatestContentItemIndex; if (index == null) { index = BaseCache.ReadFile <Objects.LatestContentItemIndex>(contentIndexFilePath); if (index == null) { index = new Objects.LatestContentItemIndex(); } int maxVersionID = index.MaxVersionID; var indexDelta = ServerAPI.GetLatestContentItemIndex(maxVersionID, languageCode); if (indexDelta != null) { foreach (var item in indexDelta) { if (item.MaxVersionID > index.MaxVersionID) { index.MaxVersionID = item.MaxVersionID; } index.Index[item.ReferenceName] = new Objects.LatestContentIndexItem() { MaxVersionID = item.MaxVersionID, ReferenceName = item.ReferenceName, Downloaded = false }; } BaseCache.WriteFile(index, contentIndexFilePath); AgilityContext.HttpContext.Items[fileName] = index; } } } } return(index); }
private static Objects.LatestIndex GetLatestContentDefinitionIndex() { string fileName = "AgilityContentDefinitionIndex.bin"; string indexFilePath = Path.Combine(BaseCache.GetLocalContentFilePath(), fileName); Objects.LatestIndex index = AgilityContext.HttpContext.Items[fileName] as Objects.LatestIndex; if (index == null) { lock (_contentDefIndexLock) { index = AgilityContext.HttpContext.Items[fileName] as Objects.LatestIndex; if (index == null) { index = BaseCache.ReadFile <Objects.LatestIndex>(indexFilePath); if (index == null) { index = new Objects.LatestIndex(); } DateTime maxModDate = index.MaxModDate; var indexDelta = ServerAPI.GetLatestContentDefinitionIndex(maxModDate); if (indexDelta != null) { foreach (var item in indexDelta) { if (item.ModifiedOn > index.MaxModDate) { index.MaxModDate = item.ModifiedOn; } index.Index[item.ID] = new Objects.LatestIndexItem() { ID = item.ID, ModifiedOnStr = item.ModifiedOnStr, Downloaded = false }; } BaseCache.WriteFile(index, indexFilePath); AgilityContext.HttpContext.Items[fileName] = index; } } } } return(index); }
public static void WriteFile(object item, string filepath, DateTime overrideLastModifiedDate) { BaseCache.WriteFile(item, filepath, overrideLastModifiedDate); }