Ejemplo n.º 1
0
 public static void AlterTypeDefinition(this IContentDefinitionManager manager, string name, Action<ContentTypeDefinitionBuilder> alteration)
 {
     var typeDefinition = manager.GetTypeDefinition(name) ?? new ContentTypeDefinition(name, name.CamelFriendly());
     var builder = new ContentTypeDefinitionBuilder(typeDefinition);
     alteration(builder);
     manager.StoreTypeDefinition(builder.Build());
 }
        /// <summary>
        /// Merges a given content type definition provided in a XML format into a content type definition builder.
        /// </summary>
        /// <param name="element">The XML content type definition.</param>
        /// <param name="contentTypeDefinitionBuilder">The content type definition builder.</param>
        public void Merge(XElement element, ContentTypeDefinitionBuilder contentTypeDefinitionBuilder)
        {
            Argument.ThrowIfNull(element, "element");
            Argument.ThrowIfNull(contentTypeDefinitionBuilder, "contentTypeDefinitionBuilder");

            // Merge name
            contentTypeDefinitionBuilder.Named(XmlConvert.DecodeName(element.Name.LocalName));

            // Merge display name
            if (element.Attribute("DisplayName") != null) {
                contentTypeDefinitionBuilder.DisplayedAs(element.Attribute("DisplayName").Value);
            }

            // Merge settings
            foreach (var setting in _settingsFormatter.Map(element)) {
                contentTypeDefinitionBuilder.WithSetting(setting.Key, setting.Value);
            }

            // Merge parts
            foreach (var iter in element.Elements()) {
                var partElement = iter;
                var partName = XmlConvert.DecodeName(partElement.Name.LocalName);
                if (partName == "remove") {
                    var nameAttribute = partElement.Attribute("name");
                    if (nameAttribute != null) {
                        contentTypeDefinitionBuilder.RemovePart(nameAttribute.Value);
                    }
                }
                else {
                    contentTypeDefinitionBuilder.WithPart(
                        partName,
                        partBuilder => {
                            foreach (var setting in _settingsFormatter.Map(partElement)) {
                                partBuilder.WithSetting(setting.Key, setting.Value);
                            }
                        });
                }
            }
        }
 public static ContentTypeDefinition Import(this IContentDefinitionReader reader, XElement source)
 {
     var target = new ContentTypeDefinitionBuilder();
     reader.Merge(source, target);
     return target.Build();
 }
Ejemplo n.º 4
0
        public virtual ContentItem New(string contentType)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
            if (contentTypeDefinition == null) {
                contentTypeDefinition = new ContentTypeDefinitionBuilder().Named(contentType).Build();
            }

            // create a new kernel for the model instance
            var context = new ActivatingContentContext {
                ContentType = contentTypeDefinition.Name,
                Definition = contentTypeDefinition,
                Builder = new ContentItemBuilder(contentTypeDefinition)
            };

            // invoke handlers to weld aspects onto kernel
            Handlers.Invoke(handler => handler.Activating(context));

            var context2 = new ActivatedContentContext {
                ContentType = contentType,
                ContentItem = context.Builder.Build()
            };

            // back-reference for convenience (e.g. getting metadata when in a view)
            context2.ContentItem.ContentManager = this;

            Handlers.Invoke(handler => handler.Activated(context2));

            var context3 = new InitializingContentContext {
                ContentType = context2.ContentType,
                ContentItem = context2.ContentItem,
            };

            Handlers.Invoke(handler => handler.Initializing(context3));
            Handlers.Invoke(handler => handler.Initialized(context3));

            // composite result is returned
            return context3.ContentItem;
        }