Exemple #1
0
        public void ReadingElementSetsName()
        {
            var builder = new ContentTypeDefinitionBuilder();

            _reader.Merge(new XElement("foo"), builder);
            var type = builder.Build();

            Assert.That(type.Name, Is.EqualTo("foo"));
        }
Exemple #2
0
        public static ContentTypeDefinition Import(this IContentDefinitionReader reader, XElement source)
        {
            var target = new ContentTypeDefinitionBuilder();

            reader.Merge(source, target);
            return(target.Build());
        }
Exemple #3
0
        /*
         * <Metadata>
         *  <Types>
         *   <Blog creatable="true">
         *    <Body format="abodyformat"/>
         *   </Blog>
         *  </Types>
         *  <Parts>
         *  </Parts>
         * </Metadata>
         */
        // Set type settings and attach parts to types.
        // Create dynamic parts.
        public void ExecuteRecipeStep(RecipeContext recipeContext)
        {
            if (!String.Equals(recipeContext.RecipeStep.Name, "Metadata", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            foreach (var metadataElement in recipeContext.RecipeStep.Step.Elements())
            {
                switch (metadataElement.Name.LocalName)
                {
                case "Types":
                    foreach (var element in metadataElement.Elements())
                    {
                        var typeElement = element;
                        var typeName    = XmlConvert.DecodeName(element.Name.LocalName);

                        _contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext {
                            ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName
                        });
                        _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration));
                        _contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext {
                            ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName)
                        });
                    }
                    break;

                case "Parts":
                    // create dynamic part.
                    foreach (var element in metadataElement.Elements())
                    {
                        var partElement = element;
                        var partName    = XmlConvert.DecodeName(element.Name.LocalName);

                        _contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext {
                            ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName
                        });
                        _contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration));
                        _contentDefinitonEventHandlers.ContentPartImported(new ContentPartImportedContext {
                            ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName)
                        });
                    }
                    break;

                default:
                    Logger.Error("Unrecognized element {0} encountered in step Metadata. Skipping.", metadataElement.Name.LocalName);
                    break;
                }
            }

            recipeContext.Executed = true;
        }
        /*
         * <ContentDefinition>
         *  <Types>
         *   <Blog creatable="true">
         *    <Body format="abodyformat"/>
         *   </Blog>
         *  </Types>
         *  <Parts>
         *  </Parts>
         * </ContentDefinition>
         */
        // Set type settings and attach parts to types.
        // Create dynamic parts.
        public override void Execute(RecipeExecutionContext context)
        {
            foreach (var metadataElement in context.RecipeStep.Step.Elements())
            {
                Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName);
                switch (metadataElement.Name.LocalName)
                {
                case "Types":
                    foreach (var element in metadataElement.Elements())
                    {
                        var typeElement = element;
                        var typeName    = XmlConvert.DecodeName(element.Name.LocalName);

                        Logger.Information("Importing content type '{0}'.", typeName);
                        try {
                            _contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext {
                                ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName
                            });
                            _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration));
                            _contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext {
                                ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName)
                            });
                        }
                        catch (Exception ex) {
                            Logger.Error(ex, "Error while importing content type '{0}'.", typeName);
                            throw;
                        }
                    }
                    break;

                case "Parts":
                    foreach (var element in metadataElement.Elements())
                    {
                        var partElement = element;
                        var partName    = XmlConvert.DecodeName(element.Name.LocalName);

                        Logger.Information("Importing content part '{0}'.", partName);
                        try {
                            _contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext {
                                ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName
                            });
                            _contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration));
                            _contentDefinitonEventHandlers.ContentPartImported(new ContentPartImportedContext {
                                ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName)
                            });
                        }
                        catch (Exception ex) {
                            Logger.Error(ex, "Error while importing content part '{0}'.", partName);
                            throw;
                        }
                    }
                    break;

                default:
                    Logger.Warning("Unrecognized element '{0}' encountered; skipping", metadataElement.Name.LocalName);
                    break;
                }
            }
        }
        public ActionResult Index(MetadataIndexViewModel model)
        {
            var root = XElement.Parse(model.ExportText);

            foreach (var element in root.Elements("Types").Elements())
            {
                var typeElement = element;
                var typeName    = XmlConvert.DecodeName(element.Name.LocalName);
                _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration));
            }
            foreach (var element in root.Elements("Parts").Elements())
            {
                var partElement = element;
                var partName    = XmlConvert.DecodeName(element.Name.LocalName);
                _contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration));
            }
            return(RedirectToAction("Index"));
        }