Exemplo n.º 1
0
        private void RemoveCacheEntryTree(ContentPathCacheEntry cacheEntry)
        {
            foreach (var childEntry in cacheEntry.Children.ToList())
            {
                RemoveCacheEntryTree(childEntry);
            }

            ContentPathCacheEntries.Remove(cacheEntry);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
 private void SetPath(ContentPathCacheEntry cacheEntry, ContentPath path)
 {
     SetPath(cacheEntry, path.ToString());
 }
Exemplo n.º 6
0
        private void RemoveCacheEntryTree(ContentPathCacheEntry cacheEntry)
        {
            foreach (var childEntry in cacheEntry.Children.ToList())
            {
                RemoveCacheEntryTree(childEntry);
            }

            ContentPathCacheEntries.Remove(cacheEntry);
        }
Exemplo n.º 7
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);
                }
            }
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
 private static void SetPath(ContentPathCacheEntry cacheEntry, string pathString)
 {
     cacheEntry.Path = pathString;
     cacheEntry.Hash = KnuthHash.CalculateHash(pathString);
 }
Exemplo n.º 10
0
 private static void SetPath(ContentPathCacheEntry cacheEntry, string pathString)
 {
     cacheEntry.Path = pathString;
     cacheEntry.Hash = KnuthHash.CalculateHash(pathString);
 }
Exemplo n.º 11
0
 private void SetPath(ContentPathCacheEntry cacheEntry, ContentPath path)
 {
     SetPath(cacheEntry, path.ToString());
 }
Exemplo n.º 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);
                }
            }
        }