protected override void OnAlterShape(ShapeDisplayingContext context)
        {
            var eventData   = (IDictionary <string, object>)context.Shape.EventData;
            var oldSettings = _settingsFormatter.Map(XmlHelper.Parse((string)eventData["OldSettings"]));
            var newSettings = _settingsFormatter.Map(XmlHelper.Parse((string)eventData["NewSettings"]));
            var diff        = oldSettings.GetDiff(newSettings);

            context.Shape.OldSettings = oldSettings;
            context.Shape.NewSettings = newSettings;
            context.Shape.Diff        = diff;
        }
        private void Apply(ContentTypeDefinition model, ContentTypeDefinitionRecord record)
        {
            record.DisplayName = model.DisplayName;
            record.Settings    = Compose(_settingsFormatter.Map(model.Settings));

            var toRemove = record.ContentTypePartDefinitionRecords
                           .Where(partDefinitionRecord => model.Parts.All(part => partDefinitionRecord.ContentPartDefinitionRecord.Name != part.PartDefinition.Name))
                           .ToList();

            foreach (var remove in toRemove)
            {
                record.ContentTypePartDefinitionRecords.Remove(remove);
            }

            foreach (var part in model.Parts)
            {
                var partName       = part.PartDefinition.Name;
                var typePartRecord = record.ContentTypePartDefinitionRecords.SingleOrDefault(r => r.ContentPartDefinitionRecord.Name == partName);
                if (typePartRecord == null)
                {
                    typePartRecord = new ContentTypePartDefinitionRecord {
                        ContentPartDefinitionRecord = Acquire(part.PartDefinition)
                    };
                    record.ContentTypePartDefinitionRecords.Add(typePartRecord);
                }
                Apply(part, typePartRecord);
            }
        }
        /// <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, nameof(element));
            Argument.ThrowIfNull(contentTypeDefinitionBuilder, nameof(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);
                        }
                    });
                }
            }
        }
        /// <summary>
        /// Builds a new XML element with a given name and a settings dictionary.
        /// </summary>
        /// <param name="name">The name of the element to be mapped to XML.</param>
        /// <param name="settings">The settings dictionary to be used as the element's attributes.</param>
        /// <returns>The new XML element.</returns>
        private XElement NewElement(string name, SettingsDictionary settings)
        {
            XElement element = _settingsFormatter.Map(settings);

            element.Name = XmlConvert.EncodeLocalName(name);

            return(element);
        }
        private void UpdateEntity(EntityMetadataPart previousEntity, EntityMetadataPart entity)
        {
            _contentDefinitionManager.AlterTypeDefinition(entity.Name, builder =>
                                                          builder.DisplayedAs(entity.DisplayName));

            foreach (var fieldMetadataRecord in previousEntity.FieldMetadataRecords)
            {
                var exist = entity.FieldMetadataRecords.Any(x => x.OriginalId == fieldMetadataRecord.Id);
                if (!exist)
                {
                    var record = fieldMetadataRecord;
                    _contentDefinitionManager.AlterPartDefinition(entity.Name,
                                                                  typeBuilder => typeBuilder.RemoveField(record.Name));
                    _schemaUpdateService.DropColumn(entity.Name, fieldMetadataRecord.Name);
                    _fieldEvents.OnDeleting(entity.Name, fieldMetadataRecord.Name);
                }
            }

            var needUpdateFields = new List <FieldMetadataRecord>();

            foreach (var fieldMetadataRecord in entity.FieldMetadataRecords)
            {
                if (fieldMetadataRecord.OriginalId != 0)
                {
                    needUpdateFields.Add(fieldMetadataRecord);
                }
                else
                {
                    AddField(entity.Name, fieldMetadataRecord);
                    _schemaUpdateService.CreateColumn(entity.Name, fieldMetadataRecord.Name, fieldMetadataRecord.ContentFieldDefinitionRecord.Name);
                }
            }

            foreach (var fieldMetadataRecord in needUpdateFields)
            {
                var record   = fieldMetadataRecord;
                var settings = _settingsFormatter.Map(Parse(record.Settings));
                _contentDefinitionManager.AlterPartDefinition(entity.Name, builder =>
                                                              builder.WithField(record.Name, fieldBuilder => {
                    fieldBuilder.WithDisplayName(settings["DisplayName"]);
                    _contentDefinitionEditorEvents.UpdateFieldSettings(fieldBuilder, settings);
                }));
                record.Settings = _settingsFormatter.Map(settings).ToString();
            }
            _entityEvents.OnUpdating(entity.Name);
        }
 public static string ToXml(this SettingsDictionary settings, ISettingsFormatter settingsFormatter)
 {
     return(settingsFormatter.Map(settings).ToString(SaveOptions.DisableFormatting));
 }
 public static string ToXml(this SettingsDictionary settings, ISettingsFormatter settingsFormatter) {
     return settingsFormatter.Map(settings).ToString(SaveOptions.DisableFormatting);
 }
Esempio n. 8
0
 public SettingsDictionary ParseSetting(string setting)
 {
     return(string.IsNullOrWhiteSpace(setting)
         ? null
         : _settingsFormatter.Map(XElement.Parse(setting)));
 }