Example #1
0
        private void CreateFragment(int level, List<ContentReference> parentIds, IStringFragment fragment,
            ContentInspectorViewModel.XhtmlStringViewModel xhtmlStringViewModel, List<string> visitorGroups)
        {
            if (fragment is PersonalizedContentFragment)
            {
                foreach (var personalizedFragment in (fragment as PersonalizedContentFragment).Fragments)
                {
                    var internalFormat = fragment.InternalFormat;
                    visitorGroups = GetVisitorGroupNames(internalFormat);
                    CreateFragment(level, parentIds, personalizedFragment, xhtmlStringViewModel, visitorGroups);
                }
            }
            else
            {
                var contentFragment = fragment as ContentFragment;
                if (contentFragment != null)
                {
                    var contentItemModel = CreateModel(contentFragment.ContentLink,
                        visitorGroups, contentFragment.ContentGroup, level, new List<ContentReference>(parentIds));

                    xhtmlStringViewModel.Fragments.Add(contentItemModel);
                }
                else
                {
                    xhtmlStringViewModel.Fragments.Add(new ContentInspectorViewModel.XhtmlStringContent()
                    {
                        Value = fragment.GetViewFormat()
                    });
                }
            }
        }
Example #2
0
        public ContentInspectorViewModel CreateModel(ContentReference contentReference, List<string> visitorGroupNames, string contentGroup,
            int level, List<ContentReference> parentIds)
        {
            level++;
            IContent content;
            if (!_contentLoader.TryGet(contentReference, out content))
            {
                return null;
            }
            
            if (!content.QueryDistinctAccess(AccessLevel.Read))
            {
                return null;
            }
            var currentItem = CreateInspectorContentViewModel(content);
            if (parentIds.Contains(contentReference))
            {
                currentItem.HasDuplicateParent = true;
            }
            else
            {
                parentIds.Add(contentReference);
            }
            currentItem.EditUrl = PageEditing.GetEditUrl(content.ContentLink);
            if (content is ImageData)
            {
                currentItem.MainType = MainContentType.Image;
                currentItem.ThumbnailUrl = content.ThumbnailUrl();
            }
            else if (content is BlockData)
                currentItem.MainType = MainContentType.Block;
            else
                currentItem.MainType = MainContentType.Page;

            var model = new ContentInspectorViewModel()
            {
                Content = currentItem,
                VisitorGroupsNames = visitorGroupNames,
                ContentAreaItems = new List<ContentInspectorViewModel.ContentAreaItemViewModel>(),
                ContentGroup = contentGroup,
                ContentReferenceItems = new List<ContentInspectorViewModel.ContentReferenceViewModel>(),
                XhtmlStringItems = new List<ContentInspectorViewModel.XhtmlStringViewModel>()
            };

            var contentType = ServiceLocator.Current.GetInstance<IContentTypeRepository>().Load(content.ContentTypeID);

            if (level >= _maxLevel)
            {
                model.Content.IsMaxLevel = true;
            }
            else if (!currentItem.HasDuplicateParent)
            {
                model.ContentAreaItems = GetContentAreaItems(level, parentIds, contentType, content); ;
            }
            var inspectablePropertes = GetInspectableProperties(contentType);
            foreach (var propertyInfo in inspectablePropertes)
            {
                if (propertyInfo.PropertyType == typeof(ContentReference) ||
                    propertyInfo.PropertyType == typeof(PageReference))
                {
                    GetContentReferenceProperty(level, parentIds, content, propertyInfo, model);
                }
                else if (propertyInfo.PropertyType == typeof(XhtmlString))
                {
                    var property = content.Property[propertyInfo.Name] as PropertyXhtmlString;
                    var fragments = property?.XhtmlString?.Fragments;
                    var xhtmlStringViewModel = new ContentInspectorViewModel.XhtmlStringViewModel();
                    xhtmlStringViewModel.Name = property.TranslateDisplayName();
                    if (fragments != null)
                    {
                        foreach (var fragment in fragments)
                        {
                            CreateFragment(level, parentIds, fragment, xhtmlStringViewModel, null);
                        }
                    }
                    model.XhtmlStringItems.Add(xhtmlStringViewModel);
                }
                else
                {
                    var property = content.Property[propertyInfo.Name];
                    if (property != null)
                    {
                        model.Content.AdditionalProperties.Add(property.TranslateDisplayName(), property.Value);

                    }
                    else
                    {
                        model.Content.AdditionalProperties.Add(propertyInfo.Name, propertyInfo.GetValue(content));
                    }
                }
            }
            return model;
        }