Ejemplo n.º 1
0
        public DefinitionEditorController(IContentDefinitionService contentDefinitionService, DefinitionEditorService definitionEditorService, IFieldService fieldService, IServiceFactory serviceFactory, ICacheItemWatcher cacheItemWatcher)
        {
            _contentDefinitionService = contentDefinitionService;

            _definitionEditorService = definitionEditorService;

            definitionEditorService.PathSeparator = DefinitionTreeNode.Separator;

            _fieldService = fieldService;

            _contentService = serviceFactory.GetContentService();

            _cacheItemWatcher = cacheItemWatcher;
        }
Ejemplo n.º 2
0
        public static DefinitionTreeNode[] GetObjectsFromPath(Content rootContent, string path, IFieldService fieldService, DefinitionEditorService definitionEditorService, ContentService contentService)
        {
            //запрос корня
            if (string.IsNullOrEmpty(path))
            {
                return new[] { new DefinitionTreeNode(rootContent, string.Empty, null, false, false, contentService) }
            }
            ;

            bool notFoundInDef;

            object foundObject = definitionEditorService.GetObjectFromPath(rootContent, path, out notFoundInDef);

            if (foundObject is Content)
            {
                return(GetContentFields((Content)foundObject, fieldService, path, foundObject == rootContent));
            }

            var contentsFromDef = definitionEditorService.GetContentsFromField((Field)foundObject);

            var nodesFromContentsInDef = contentsFromDef
                                         .Select(x => new DefinitionTreeNode(x, path, null, foundObject is Dictionaries, false, contentService))
                                         .ToArray();

            if (foundObject is ExtensionField)
            {
                var allExtensions = fieldService.ListRelated(fieldService.Read(((Field)foundObject).FieldId).ContentId)
                                    .Where(x => x.Aggregated)
                                    .Select(x => x.Content)
                                    .ToArray();

                return(nodesFromContentsInDef
                       .Concat(allExtensions
                               .Where(x => contentsFromDef.All(y => y.ContentId != x.Id))
                               .Select(x => new DefinitionTreeNode(x, path)))
                       .ToArray());
            }
            else if (foundObject is Dictionaries)
            {
                int[] allContentIds = definitionEditorService.GetAllContentIdsFromTree(rootContent);

                return(nodesFromContentsInDef
                       .Concat(allContentIds
                               .Where(x => contentsFromDef.All(y => y.ContentId != x))
                               .Select(x => new DefinitionTreeNode(contentService.Read(x), path))
                               .OrderBy(x => x.text))
                       .ToArray());
            }
            else
            {
                return(nodesFromContentsInDef);
            }
        }
    }