Esempio n. 1
0
        private List <ContentType> GetImportAttributeSets(IEnumerable <XElement> xAttributeSets)
        {
            var importAttributeSets = new List <ContentType>();

            // Loop through AttributeSets
            foreach (var attributeSet in xAttributeSets)
            {
                var attributes = new List <IAttributeDefinition>();
                //ImpAttribDefinition titleAttribute = null;// = new ImpAttribute();
                var attsetElem = attributeSet.Element(XmlConstants.Attributes);
                if (attsetElem != null)
                {
                    foreach (var xElementAttribute in attsetElem.Elements(XmlConstants.Attribute))
                    {
                        var attribute = new AttributeDefinition(AppId,
                                                                xElementAttribute.Attribute(XmlConstants.Static).Value,
                                                                null,
                                                                xElementAttribute.Attribute(XmlConstants.EntityTypeAttribute).Value,
                                                                null, null, null
                                                                );
                        attribute.AddItems(GetImportEntities(xElementAttribute.Elements(XmlConstants.Entity), Constants.MetadataForAttribute));
                        attributes.Add(attribute);

                        // Set Title Attribute
                        if (Boolean.Parse(xElementAttribute.Attribute(XmlConstants.IsTitle).Value))
                        {
                            attribute.IsTitle = true;
                            //titleAttribute = attribute;
                        }
                    }
                }
                // check if it's normal (not a ghost) but still missing a title
                if (attributes.Any() && !attributes.Any(a => a.IsTitle))
                {
                    (attributes.First() as AttributeDefinition).IsTitle = true;
                }

                // Add AttributeSet
                var ct = new ContentType(AppId, attributeSet.Attribute(XmlConstants.Name).Value)
                {
                    Attributes = attributes,
                    OnSaveUseParentStaticName = attributeSet.Attributes(XmlConstants.AttributeSetParentDef).Any() ? attributeSet.Attribute(XmlConstants.AttributeSetParentDef).Value : "",
                    OnSaveSortAttributes      = attributeSet.Attributes(XmlConstants.SortAttributes).Any() && bool.Parse(attributeSet.Attribute(XmlConstants.SortAttributes).Value)
                };
                ct.SetImportParameters(
                    scope: attributeSet.Attributes(XmlConstants.Scope).Any()
                                    ? attributeSet.Attribute(XmlConstants.Scope).Value
                                    : _environment.FallbackContentTypeScope,
                    staticName: attributeSet.Attribute(XmlConstants.Static).Value,
                    description: attributeSet.Attribute(XmlConstants.Description).Value,
                    alwaysShareDef: AllowSystemChanges && attributeSet.Attributes(XmlConstants.AlwaysShareConfig).Any() &&
                    Boolean.Parse(attributeSet.Attribute(XmlConstants.AlwaysShareConfig).Value)
                    );
                importAttributeSets.Add(ct);
            }

            return(importAttributeSets);
        }