public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context)
        {
            var compoundElements = _CompoundElementService.Value.GetAll().ToArray();

            return compoundElements.Select(compoundElement => {
                return new ElementDescriptor(typeof(Compound),
                    compoundElement.ElementTypeName,
                    T(compoundElement.As<ITitleAspect>().Title),
                    T(compoundElement.ElementDescription),
                    compoundElement.ElementCategory)
                {
                    CreatingDisplay = creatingDisplayContext => CreatingDisplay(creatingDisplayContext),
                    UpdateEditor = null,
                    EnableEditorDialog = false,
                    Editor = editorContext => Editor(editorContext),
                    Displaying = elementDisplayingContext => Displaying(elementDisplayingContext),
                    
                    StateBag = new Dictionary<string, object> {
                        { "ContentItemId", compoundElement.Id },
                        { "ContentItemVersionId", compoundElement.ContentItem.VersionRecord.Id },
                        { "LayoutData",  compoundElement.As<LayoutPart>().LayoutData }
                    }
                };
            });
        }
        public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
            if (_isHarvesting)
                return Enumerable.Empty<ElementDescriptor>();

            _isHarvesting = true;
            var blueprints = _elementBlueprintService.Value.GetBlueprints().ToArray();

            var query =
                from blueprint in blueprints
                let describeContext = new DescribeElementsContext {Content = context.Content, CacheVaryParam = "Blueprints"}
                let baseElementDescriptor = _elementManager.Value.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName)
                let baseElement = _elementManager.Value.ActivateElement(baseElementDescriptor)
                select new ElementDescriptor(
                    baseElement.Descriptor.ElementType,
                    blueprint.ElementTypeName,
                    T(blueprint.ElementDisplayName),
                    T(!String.IsNullOrWhiteSpace(blueprint.ElementDescription) ? blueprint.ElementDescription : blueprint.ElementDisplayName),
                    GetCategory(blueprint)) {
                        EnableEditorDialog = false,
                        IsSystemElement = false,
                        CreatingDisplay = creatingDisplayContext => CreatingDisplay(creatingDisplayContext, blueprint),
                        Display = displayContext => Displaying(displayContext, baseElement),
                        StateBag = new Dictionary<string, object> {
                            {"Blueprint", true},
                            {"ElementTypeName", baseElement.Descriptor.TypeName}
                        }
                    };

            var descriptors = query.ToArray();
            _isHarvesting = false;
            return descriptors;
        }
예제 #3
0
        private IEnumerable<ContentPartDefinition> GetContentParts(HarvestElementsContext context) {
            var contentTypeDefinition = context.Content != null
                ? _contentDefinitionManager.Value.GetTypeDefinition(context.Content.ContentItem.ContentType)
                : default(ContentTypeDefinition);

            var parts = contentTypeDefinition != null
                ? contentTypeDefinition.Parts.Select(x => x.PartDefinition)
                : _contentDefinitionManager.Value.ListPartDefinitions();

            return parts.Where(p => p.Settings.GetModel<ContentPartLayoutSettings>().Placeable);
        }
        private IEnumerable<Tuple<ContentPartDefinition, ContentPartFieldDefinition>> GetContentFieldTuples(HarvestElementsContext context) {
            var contentTypeDefinition = context.Content != null 
                ? _contentDefinitionManager.Value.GetTypeDefinition(context.Content.ContentItem.ContentType) 
                : default(ContentTypeDefinition);

            var parts = contentTypeDefinition != null
                ? contentTypeDefinition.Parts.Select(x => x.PartDefinition) 
                : _contentDefinitionManager.Value.ListPartDefinitions();

            var fields = parts.SelectMany(part => part.Fields.Select(field => Tuple.Create(part, field)));
    
            // TODO: Each module should be able to tell which fields are supported as droppable elements.
            var blackList = new string[0];

            return fields.Where(t => blackList.All(x => t.Item2.FieldDefinition.Name != x));
        }
        public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
            var elementType = typeof(Elements.ContentField);
            var contentFieldElement = _elementFactory.Value.Activate(elementType);
            var tuples = GetContentFieldTuples(context);

            foreach (var tuple in tuples) {
                var part = tuple.Item1;
                var field = tuple.Item2;
                var name = String.Format("{0}.{1}", part.Name, field.Name);
                var displayName = field.DisplayName;
                yield return new ElementDescriptor(elementType, name, T(displayName), T(field.DisplayName), contentFieldElement.Category) {
                    Display = displayContext => Displaying(displayContext),
                    ToolboxIcon = "\uf1b2"
                };
            }
        }
        public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
            var currentThemeName = _siteThemeService.Value.GetCurrentThemeName();
            var shapeTable = _shapeTableLocator.Value.Lookup(currentThemeName);
            var shapeDescriptors = shapeTable.Bindings.Where(x => !String.Equals(x.Key, "Elements_Snippet", StringComparison.OrdinalIgnoreCase) && x.Key.EndsWith(SnippetShapeSuffix, StringComparison.OrdinalIgnoreCase)).ToDictionary(x => x.Key, x => x.Value.ShapeDescriptor);
            var elementType = typeof (Snippet);
            var snippetElement = _elementFactory.Value.Activate(elementType);

            foreach (var shapeDescriptor in shapeDescriptors) {
                var shapeType = shapeDescriptor.Value.ShapeType;
                var elementName = GetDisplayName(shapeDescriptor.Value.BindingSource);
                var closureDescriptor = shapeDescriptor;
                yield return new ElementDescriptor(elementType, shapeType, T(elementName), T("An element that renders the {0} shape.", shapeType), snippetElement.Category) {
                    Displaying = displayContext => Displaying(displayContext, closureDescriptor.Value),
                    ToolboxIcon = "\uf10c"
                };
            }
        }
        public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
            var drivers = _elementManager.Value.GetDrivers();
            var elementTypes = drivers
                .Select(x => x.GetType().BaseType.GenericTypeArguments[0])
                .Where(x => !x.IsAbstract && !x.IsInterface)
                .Distinct()
                .ToArray();

            return elementTypes.Select(elementType => {
                var element = _factory.Value.Activate(elementType);
                return new ElementDescriptor(elementType, element.Type, element.DisplayText, element.Description, element.Category) {
                    GetDrivers = () => _elementManager.Value.GetDrivers(element),
                    IsSystemElement = element.IsSystemElement,
                    EnableEditorDialog = element.HasEditor,
                    ToolboxIcon = element.ToolboxIcon
                };
            });
        }
예제 #8
0
        public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
            var elementType = typeof(Elements.ContentPart);
            var contentPartElement = _elementFactory.Value.Activate(elementType);
            var contentParts = GetContentParts(context);

            return contentParts.Select(contentPart => {

                var partSettings = contentPart.Settings.TryGetModel<ContentPartSettings>();
                var partDescription = partSettings != null ? partSettings.Description : null;
                var description = T(!String.IsNullOrWhiteSpace(partDescription) ? partDescription : contentPart.Name);
                return new ElementDescriptor(elementType, contentPart.Name, T(contentPart.Name.CamelFriendly()), description, contentPartElement.Category) {
                    Displaying = displayContext => Displaying(displayContext),
                    ToolboxIcon = "\uf1b2",
                    StateBag = new Dictionary<string, object> {
                        {"ElementTypeName", contentPart.Name}
                    }
                };
            });
        }
        public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
            var contentTypeDefinitions = GetPlaceableContentTypeDefinitions();

            return contentTypeDefinitions.Select(contentTypeDefinition => {
                var settings = contentTypeDefinition.Settings;
                var description = settings.ContainsKey("Description") ? settings["Description"] : contentTypeDefinition.DisplayName;
                return new ElementDescriptor(typeof (PlaceableContentItem), contentTypeDefinition.Name, T(contentTypeDefinition.DisplayName), T(description), category: "Content Items") {
                    Displaying = Displaying,
                    Editor = Editor,
                    UpdateEditor = UpdateEditor,
                    ToolboxIcon = "\uf1b2",
                    EnableEditorDialog = true,
                    Removing = RemoveContentItem,
                    Exporting = ExportElement,
                    Importing = ImportElement,
                    StateBag = new Dictionary<string, object> {
                        { "ContentTypeName", contentTypeDefinition.Name }
                    }
                };
            });
        }
예제 #10
0
        public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context)
        {
            var currentThemeName = _siteThemeService.Value.GetCurrentThemeName();
            var shapeTable = _shapeTableLocator.Value.Lookup(currentThemeName);
            var shapeDescriptors = shapeTable.Bindings.Where(x => !String.Equals(x.Key, "Elements_Snippet", StringComparison.OrdinalIgnoreCase) && x.Key.EndsWith(SnippetShapeSuffix, StringComparison.OrdinalIgnoreCase)).ToDictionary(x => x.Key, x => x.Value.ShapeDescriptor);
            var elementType = typeof(Snippet);
            var snippetElement = (Snippet)_elementFactory.Value.Activate(elementType);

            foreach (var shapeDescriptor in shapeDescriptors) {
                var shapeType = shapeDescriptor.Value.ShapeType;
                var elementName = GetDisplayName(shapeDescriptor.Value.BindingSource);
                var closureDescriptor = shapeDescriptor;
                var snippetDescriptor = ParseSnippetDescriptor(shapeDescriptor.Value.BindingSource);
                yield return new ElementDescriptor(elementType, shapeType, new LocalizedString(elementName), new LocalizedString(String.Format("An element that renders the {0} shape.", shapeType)), snippetElement.Category) {
                    Displaying = displayContext => Displaying(displayContext, closureDescriptor.Value, snippetDescriptor),
                    ToolboxIcon = "\uf10c",
                    EnableEditorDialog = snippetDescriptor != null || HasSnippetFields(shapeDescriptor.Value),
                    Editor = ctx => Editor(snippetDescriptor ?? DescribeSnippet(shapeType, snippetElement), ctx),
                    UpdateEditor = ctx => UpdateEditor(snippetDescriptor ?? DescribeSnippet(shapeType, snippetElement), ctx)
                };
            }
        }