Example #1
0
        private void RemoveCacheEntryTree(ContentPathCacheEntry cacheEntry)
        {
            foreach (var childEntry in cacheEntry.Children.ToList())
            {
                RemoveCacheEntryTree(childEntry);
            }

            ContentPathCacheEntries.Remove(cacheEntry);
        }
Example #2
0
        private ContentPathCacheEntry CreateCacheEntry(int contentId, Type contentType, ContentPath path, ContentPathCacheEntry parent, int sortOrder)
        {
            var cacheEntry = new ContentPathCacheEntry
            {
                ContentId   = contentId,
                ContentType = contentType.FullName,
                Parent      = parent,
                SortOrder   = sortOrder,
            };

            SetPath(cacheEntry, path);

            ContentPathCacheEntries.Add(cacheEntry);

            return(cacheEntry);
        }
Example #3
0
        private void UpdatePathRecursive(string oldPathPrefix, string newPathPrefix, ContentPathCacheEntry cacheEntry)
        {
            if (!cacheEntry.Path.StartsWith(oldPathPrefix))
            {
                throw new ArgumentException(string.Format("Cache entry path '{0}' does not start with '{1}'.", cacheEntry.Path, oldPathPrefix));
            }

            var newPath = newPathPrefix + cacheEntry.Path.Substring(oldPathPrefix.Length);

            SetPath(cacheEntry, newPath);

            foreach (var childCacheEntry in cacheEntry.Children)
            {
                UpdatePathRecursive(oldPathPrefix, newPathPrefix, childCacheEntry);
            }
        }
        private void UpdatePathRecursive(string oldPathPrefix, string newPathPrefix, ContentPathCacheEntry cacheEntry)
        {
            if (!cacheEntry.Path.StartsWith(oldPathPrefix))
            {
                throw new ArgumentException(string.Format("Cache entry path '{0}' does not start with '{1}'.", cacheEntry.Path, oldPathPrefix));
            }

            var newPath = newPathPrefix + cacheEntry.Path.Substring(oldPathPrefix.Length);

            SetPath(cacheEntry, newPath);

            foreach (var childCacheEntry in cacheEntry.Children)
            {
                UpdatePathRecursive(oldPathPrefix, newPathPrefix, childCacheEntry);
            }
        }
 private void SetPath(ContentPathCacheEntry cacheEntry, ContentPath path)
 {
     SetPath(cacheEntry, path.ToString());
 }
        private void RemoveCacheEntryTree(ContentPathCacheEntry cacheEntry)
        {
            foreach (var childEntry in cacheEntry.Children.ToList())
            {
                RemoveCacheEntryTree(childEntry);
            }

            ContentPathCacheEntries.Remove(cacheEntry);
        }
        private void RebuildPathCache(IEnumerable<IContent> contents, ContentPath parentPath, ContentPathCacheEntry parentEntry)
        {
            var cachedContents = contents.ToList();
            if (cachedContents.Count == 0)
            {
                return;
            }

            foreach (var item in cachedContents.Select((c, i) => new { Content = c, Index = i }))
            {
                var content = item.Content;

                var path = parentPath != null
                    ? parentPath.Append(content.Alias)
                    : ContentPath.Root;

                var actualContentType = ObjectContext.GetObjectType(content.GetType());

                var collectionProperties = _collectionPropertiesByType.GetOrAdd(actualContentType, t => t
                    .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                    .Select(p => new { Property = p, CollectionType = p.PropertyType.GetImplementationOf(typeof(IEnumerable<>)) })
                    .Where(p => p.CollectionType != null)
                    .Select(p => new { Property = p.Property, ChildType = p.CollectionType.GetGenericArguments().First() })
                    .Where(p => typeof(IContent).IsAssignableFrom(p.ChildType))
                    .Select(p => p.Property)
                    .ToList());

                var cacheEntry = CreateCacheEntry(content.Id, actualContentType, path, parentEntry, item.Index);

                foreach (var collectionProperty in collectionProperties)
                {
                    var children = (IEnumerable<IContent>)collectionProperty.GetValue(content, null);
                    RebuildPathCache(children, path, cacheEntry);
                }
            }
        }
        private ContentPathCacheEntry CreateCacheEntry(int contentId, Type contentType, ContentPath path, ContentPathCacheEntry parent, int sortOrder)
        {
            var cacheEntry = new ContentPathCacheEntry
            {
                ContentId = contentId,
                ContentType = contentType.FullName,
                Parent = parent,
                SortOrder = sortOrder,
            };

            SetPath(cacheEntry, path);

            ContentPathCacheEntries.Add(cacheEntry);

            return cacheEntry;
        }
 private static void SetPath(ContentPathCacheEntry cacheEntry, string pathString)
 {
     cacheEntry.Path = pathString;
     cacheEntry.Hash = KnuthHash.CalculateHash(pathString);
 }
Example #10
0
 private static void SetPath(ContentPathCacheEntry cacheEntry, string pathString)
 {
     cacheEntry.Path = pathString;
     cacheEntry.Hash = KnuthHash.CalculateHash(pathString);
 }
Example #11
0
 private void SetPath(ContentPathCacheEntry cacheEntry, ContentPath path)
 {
     SetPath(cacheEntry, path.ToString());
 }
Example #12
0
        private void RebuildPathCache(IEnumerable <IContent> contents, ContentPath parentPath, ContentPathCacheEntry parentEntry)
        {
            var cachedContents = contents.ToList();

            if (cachedContents.Count == 0)
            {
                return;
            }

            foreach (var item in cachedContents.Select((c, i) => new { Content = c, Index = i }))
            {
                var content = item.Content;

                var path = parentPath != null
                                        ? parentPath.Append(content.Alias)
                                        : ContentPath.Root;

                var actualContentType = ObjectContext.GetObjectType(content.GetType());

                var collectionProperties = _collectionPropertiesByType.GetOrAdd(actualContentType, t => t
                                                                                .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                                                                .Select(p => new { Property = p, CollectionType = p.PropertyType.GetImplementationOf(typeof(IEnumerable <>)) })
                                                                                .Where(p => p.CollectionType != null)
                                                                                .Select(p => new { Property = p.Property, ChildType = p.CollectionType.GetGenericArguments().First() })
                                                                                .Where(p => typeof(IContent).IsAssignableFrom(p.ChildType))
                                                                                .Select(p => p.Property)
                                                                                .ToList());

                var cacheEntry = CreateCacheEntry(content.Id, actualContentType, path, parentEntry, item.Index);

                foreach (var collectionProperty in collectionProperties)
                {
                    var children = (IEnumerable <IContent>)collectionProperty.GetValue(content, null);
                    RebuildPathCache(children, path, cacheEntry);
                }
            }
        }