コード例 #1
0
        private static Objects.LatestIndex GetLatestMediaGalleryIndex()
        {
            string fileName      = "AgilityMediaGalleryIndex.bin";
            string indexFilePath = Path.Combine(BaseCache.GetLocalContentFilePath(), fileName);

            Objects.LatestIndex index = AgilityContext.HttpContext.Items[fileName] as Objects.LatestIndex;
            if (index == null)
            {
                lock (_mediaGalleryIndexLock)
                {
                    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.GetLatestMediaGalleryIndex(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);
        }