예제 #1
0
        /// <summary>
        /// Populates a list of content items of the provided content type
        /// </summary>
        /// <param name="contentTypeAudit"></param>
        /// <param name="includeReferences"></param>
        /// <param name="includeParentDetail"></param>
        public ContentTypeAudit GenerateContentTypeAudit(int contentTypeId,
                                                         bool includeReferences, bool includeParentDetail)
        {
            var contentType = _contentTypeRepository.Load(contentTypeId);

            var contentTypeAudit = new ContentTypeAudit
            {
                ContentTypeId = contentTypeId,
                Name          = contentType.Name,
                Usages        = new List <ContentTypeAudit.ContentItem>()
            };

            var contentModelUsages = _contentModelUsage.ListContentOfContentType(contentType)
                                     .Where(cmu => cmu.ContentLink != ContentReference.WasteBasket &&
                                            !_contentRepository.GetAncestors(cmu.ContentLink).Select(ic => ic.ContentLink).Contains(ContentReference.WasteBasket))
                                     .Select(contentUsage => new
            {
                ContentLink = contentUsage.ContentLink.ToReferenceWithoutVersion(),
                Name        = contentUsage.Name
            })
                                     .Distinct()
                                     .Select(distinctContentUsage => new
            {
                ContentLink = distinctContentUsage.ContentLink,
                Name        = distinctContentUsage.Name,
                ContentItem = _contentRepository.Get <IContent>(distinctContentUsage.ContentLink)
            });

            foreach (var cmu in contentModelUsages)
            {
                var siteDefinition = _siteDefinitionResolver.GetByContent(cmu.ContentLink, true);

                contentTypeAudit.Usages.Add(new ContentTypeAudit.ContentItem
                {
                    Name        = cmu.Name,
                    ContentLink = cmu.ContentLink,
                    SiteId      = siteDefinition?.Id ?? Guid.Empty,
                    Parent      = includeParentDetail && cmu.ContentItem.ParentLink != ContentReference.EmptyReference
                        ? new ContentTypeAudit.ContentItem
                    {
                        Name        = _contentRepository.Get <IContent>(cmu.ContentItem.ParentLink).Name,
                        ContentLink = cmu.ContentItem.ParentLink
                    }
                        : null,
                    PageReferences = includeReferences
                        ? _contentRepository.GetReferencesToContent(cmu.ContentLink, true)
                                     .Select(rtc => new ContentTypeAudit.ContentItem.PageReference
                    {
                        Name        = rtc.OwnerName,
                        ContentLink = rtc.OwnerID,
                        SiteId      = _siteDefinitionResolver.GetByContent(rtc.OwnerID, true)?.Id ?? Guid.Empty
                    }).ToList()
                        : new List <ContentTypeAudit.ContentItem.PageReference>()
                });
            }

            return(contentTypeAudit);
        }
예제 #2
0
        /// <summary>
        /// Gets a list of content items of the provided content type
        /// </summary>
        /// <param name="contentTypeId"></param>
        /// <param name="includeReferences"></param>
        /// <param name="includeParentDetail"></param>
        /// <returns></returns>
        public ContentTypeAudit GetContentTypeAudit(int contentTypeId, bool includeReferences, bool includeParentDetail)
        {
            var contentType      = _contentTypeRepository.Load(contentTypeId);
            var contentTypeAudit = new ContentTypeAudit
            {
                ContentTypeId = contentTypeId,
                Name          = contentType.Name,
                Usages        = new List <ContentTypeAudit.ContentItem>()
            };

            PopulateContentItemsOfType(contentTypeAudit, includeReferences, includeParentDetail);

            return(contentTypeAudit);
        }
예제 #3
0
        /// <summary>
        /// Populates a list of content items of the provided content type
        /// </summary>
        /// <param name="contentTypeAudit"></param>
        /// <param name="includeReferences"></param>
        /// <param name="includeParentDetail"></param>
        public void PopulateContentItemsOfType(ContentTypeAudit contentTypeAudit,
                                               bool includeReferences, bool includeParentDetail)
        {
            var contentType        = _contentTypeRepository.Load(contentTypeAudit.ContentTypeId);
            var contentModelUsages = _contentModelUsage.ListContentOfContentType(contentType)
                                     .Where(cmu => cmu.ContentLink != ContentReference.WasteBasket &&
                                            !_contentRepository.GetAncestors(cmu.ContentLink).Select(ic => ic.ContentLink).Contains(ContentReference.WasteBasket))
                                     .Select(contentUsage => new
            {
                ContentLink = contentUsage.ContentLink.ToReferenceWithoutVersion(),
                Name        = contentUsage.Name
            })
                                     .Distinct()
                                     .Select(distinctContentUsage => new
            {
                ContentLink = distinctContentUsage.ContentLink,
                Name        = distinctContentUsage.Name,
                ContentItem = _contentRepository.Get <IContent>(distinctContentUsage.ContentLink)
            });


            contentTypeAudit.Usages = contentModelUsages.Select(cmu => new ContentTypeAudit.ContentItem
            {
                Name        = cmu.Name,
                ContentLink = cmu.ContentLink,
                SiteId      = _siteDefinitionResolver.GetByContent(cmu.ContentLink, true).Id,
                Parent      = includeParentDetail && cmu.ContentItem.ParentLink != ContentReference.EmptyReference
                    ? new ContentTypeAudit.ContentItem
                {
                    Name        = _contentRepository.Get <IContent>(cmu.ContentItem.ParentLink).Name,
                    ContentLink = cmu.ContentItem.ParentLink
                }
                    : null,
                PageReferences = includeReferences
                    ? _contentRepository.GetReferencesToContent(cmu.ContentLink, true)
                                 .Select(rtc => new ContentTypeAudit.ContentItem.PageReference
                {
                    Name        = rtc.OwnerName,
                    ContentLink = rtc.OwnerID,
                    SiteId      = _siteDefinitionResolver.GetByContent(rtc.OwnerID, true).Id
                }).ToList()
                    : new List <ContentTypeAudit.ContentItem.PageReference>()
            }).ToList();
        }