コード例 #1
0
        private static int CheckContentIndex(int latestVersionID, string referenceName, string languageCode)
        {
            Objects.LatestContentItemIndex index = GetLatestContentItemIndex(languageCode);

            //return true to indicate that we need to check again...
            if (!string.IsNullOrEmpty(referenceName))
            {
                //checking for a specific content reference name
                Objects.LatestContentIndexItem indexItem = null;
                if (index.Index.TryGetValue(referenceName, out indexItem))
                {
                    //found it in the index... check it
                    if (latestVersionID < indexItem.MaxVersionID)
                    {
                        return(indexItem.MaxVersionID);
                    }
                }
                else
                {
                    //not in the index, there are not items in this view anymore, only need to check latest if latestVersionID is not 0 (zero)
                    return(latestVersionID);
                }
            }
            else
            {
                //if we don't have a piece of content to check for
                if (latestVersionID < index.MaxVersionID)
                {
                    return(index.MaxVersionID);
                }
            }

            return(0);
        }
コード例 #2
0
        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);
        }