Example #1
0
        private XElement ExportMetadata(IEnumerable <string> contentTypes)
        {
            var typesElement  = new XElement("Types");
            var partsElement  = new XElement("Parts");
            var typesToExport = _contentDefinitionManager.ListTypeDefinitions()
                                .Where(typeDefinition => contentTypes.Contains(typeDefinition.Name))
                                .ToList();
            var partsToExport = new Dictionary <string, ContentPartDefinition>();

            foreach (var contentTypeDefinition in typesToExport.OrderBy(x => x.Name))
            {
                foreach (var contentPartDefinition in contentTypeDefinition.Parts.OrderBy(x => x.PartDefinition.Name))
                {
                    if (partsToExport.ContainsKey(contentPartDefinition.PartDefinition.Name))
                    {
                        continue;
                    }
                    partsToExport.Add(contentPartDefinition.PartDefinition.Name, contentPartDefinition.PartDefinition);
                }
                typesElement.Add(_contentDefinitionWriter.Export(contentTypeDefinition));
            }

            foreach (var part in partsToExport.Values.OrderBy(x => x.Name))
            {
                partsElement.Add(_contentDefinitionWriter.Export(part));
            }

            return(new XElement("ContentDefinition", typesElement, partsElement));
        }
        public ActionResult Index()
        {
            var model = new MetadataIndexViewModel {
                TypeDefinitions = _contentDefinitionManager.ListTypeDefinitions(),
                PartDefinitions = _contentDefinitionManager.ListPartDefinitions()
            };
            var types = new XElement("Types");

            foreach (var type in model.TypeDefinitions)
            {
                types.Add(_contentDefinitionWriter.Export(type));
            }

            var parts = new XElement("Parts");

            foreach (var part in model.PartDefinitions)
            {
                parts.Add(_contentDefinitionWriter.Export(part));
            }

            var stringWriter = new StringWriter();

            using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
                Indent = true, IndentChars = "  "
            })) {
                if (xmlWriter != null)
                {
                    new XElement("Orchard", types, parts).WriteTo(xmlWriter);
                }
            }
            model.ExportText = stringWriter.ToString();

            return(View(model));
        }
        private XElement ExportMetadata(IEnumerable <string> contentTypes)
        {
            var typesElement  = new XElement("Types");
            var partsElement  = new XElement("Parts");
            var typesToExport = _contentDefinitionManager.ListTypeDefinitions()
                                .Where(typeDefinition => contentTypes.Contains(typeDefinition.Name))
                                .ToList();
            var partsToExport = new List <string>();

            foreach (var contentTypeDefinition in typesToExport)
            {
                foreach (var contentPartDefinition in contentTypeDefinition.Parts)
                {
                    if (partsToExport.Contains(contentPartDefinition.PartDefinition.Name))
                    {
                        continue;
                    }
                    partsToExport.Add(contentPartDefinition.PartDefinition.Name);
                    partsElement.Add(_contentDefinitionWriter.Export(contentPartDefinition.PartDefinition));
                }
                typesElement.Add(_contentDefinitionWriter.Export(contentTypeDefinition));
            }

            return(new XElement("Metadata", typesElement, partsElement));
        }
Example #4
0
 public void ContentTypeImporting(ContentTypeImportingContext context)
 {
     _previousContentTypeXml = context.ContentTypeDefinition != null?_contentDefinitionWriter.Export(context.ContentTypeDefinition) : default(XElement);
 }