Ejemplo n.º 1
0
 public override IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
 {
     var model = new ContentPartSettings();
     updateModel.TryUpdateModel(model, "ContentPartSettings", null, null);
     builder.Attachable(model.Attachable);
     yield return DefinitionTemplate(model);
 }
 public static void AlterPartDefinition(this IContentDefinitionManager manager, string name, Action<ContentPartDefinitionBuilder> alteration)
 {
     var partDefinition = manager.GetPartDefinition(name) ?? new ContentPartDefinition(name);
     var builder = new ContentPartDefinitionBuilder(partDefinition);
     alteration(builder);
     manager.StorePartDefinition(builder.Build());
 }
        public void Merge(XElement source, ContentPartDefinitionBuilder builder) {
            builder.Named(XmlConvert.DecodeName(source.Name.LocalName));
            foreach (var setting in _settingsReader.Map(source)) {
                builder.WithSetting(setting.Key, setting.Value);
            }

            foreach (var iter in source.Elements()) {
                var fieldElement = iter;
                var fieldParameters = XmlConvert.DecodeName(fieldElement.Name.LocalName).Split(new[] { '.' }, 2);
                var fieldName = fieldParameters.FirstOrDefault();
                var fieldType = fieldParameters.Skip(1).FirstOrDefault();
                if (fieldName == "remove") {
                    var nameAttribute = fieldElement.Attribute("name");
                    if (nameAttribute != null) {
                        builder.RemoveField(nameAttribute.Value);
                    }
                }
                else {
                    builder.WithField(
                        fieldName,
                        fieldBuilder => {
                            fieldBuilder.OfType(fieldType);
                            foreach (var setting in _settingsReader.Map(fieldElement)) {
                                fieldBuilder.WithSetting(setting.Key, setting.Value);
                            }
                        });
                }
            }
        }
 public static ContentPartDefinitionBuilder WithLocation(this ContentPartDefinitionBuilder obj, IDictionary <string, ContentLocation> settings)
 {
     foreach (var entry in GetSettingEntries(settings))
     {
         obj = obj.WithSetting(entry.Key, entry.Value);
     }
     return(obj);
 }
Ejemplo n.º 5
0
 public override IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel)
 {
     var model = new ContentPartSettings();
     updateModel.TryUpdateModelAsync(model, "ContentPartSettings").Wait();
     builder.Attachable(model.Attachable);
     builder.WithDescription(model.Description);
     yield return DefinitionTemplate(model);
 }
Ejemplo n.º 6
0
        public override IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) {
            if (builder.Name != "BodyPart")
                yield break;

            var model = new BodyPartSettings();
            updateModel.TryUpdateModel(model, "BodyPartSettings", null, null);
            builder.WithSetting("BodyPartSettings.FlavorDefault", !string.IsNullOrWhiteSpace(model.FlavorDefault) ? model.FlavorDefault : null);
            yield return DefinitionTemplate(model);
        }
Ejemplo n.º 7
0
        public override IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) {
            if (builder.Name != "ContainerPart")
                yield break;

            var model = new ContainerPartSettings();
            updateModel.TryUpdateModel(model, "ContainerPartSettings", null, null);
            builder.WithSetting("ContainerPartSettings.PageSizeDefault", model.PageSizeDefault.ToString());
            builder.WithSetting("ContainerPartSettings.PaginatedDefault", model.PaginatedDefault.ToString());
            yield return DefinitionTemplate(model);
        }
        public void ShouldReturnProviderByName() {
            var part1Definition = new ContentPartDefinitionBuilder()
                .WithField("Hello", fb => fb.OfType("Text").WithSetting("Storage", "TestProvName"))
                .Build();
            var part2Definition = new ContentPartDefinitionBuilder()
                .WithField("World", fb => fb.OfType("Text").WithSetting("Storage", "Infoset"))
                .Build();

            var provider1 = _selector.GetProvider(part1Definition.Fields.Single());
            var provider2 = _selector.GetProvider(part2Definition.Fields.Single());

            Assert.That(provider1.ProviderName, Is.EqualTo("TestProvName"));
            Assert.That(provider2.ProviderName, Is.EqualTo("Infoset"));
        }
        /// <summary>
        /// Merges a given content part definition provided in a XML format into a content part definition builder.
        /// </summary>
        /// <param name="element">The XML content type definition.</param>
        /// <param name="contentPartDefinitionBuilder">The content part definition builder.</param>
        public void Merge(XElement element, ContentPartDefinitionBuilder contentPartDefinitionBuilder) {
            Argument.ThrowIfNull(element, "element");
            Argument.ThrowIfNull(contentPartDefinitionBuilder, "contentPartDefinitionBuilder");

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

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

            // Merge fields
            foreach (var iter in element.Elements()) {
                var fieldElement = iter;
                var fieldParameters = XmlConvert.DecodeName(fieldElement.Name.LocalName).Split(new[] { '.' }, 2);
                var fieldName = fieldParameters.FirstOrDefault();
                var fieldType = fieldParameters.Skip(1).FirstOrDefault();
                if (fieldName == "remove") {
                    var nameAttribute = fieldElement.Attribute("name");
                    if (nameAttribute != null) {
                        contentPartDefinitionBuilder.RemoveField(nameAttribute.Value);
                    }
                }
                else {
                    contentPartDefinitionBuilder.WithField(
                        fieldName,
                        fieldBuilder => {
                            fieldBuilder.OfType(fieldType);
                            foreach (var setting in _settingsFormatter.Map(fieldElement)) {
                                fieldBuilder.WithSetting(setting.Key, setting.Value);
                            }
                        });
                }
            }
        }
        public void ShouldReturnInfosetWhenNullEmptyMissingOrInvalid() {
            var part1Definition = new ContentPartDefinitionBuilder()
                .WithField("Hello", fb => fb.OfType("Text").WithSetting("Storage", null))
                .Build();
            var part2Definition = new ContentPartDefinitionBuilder()
                .WithField("World", fb => fb.OfType("Text").WithSetting("Storage", ""))
                .Build();
            var part3Definition = new ContentPartDefinitionBuilder()
                .WithField("World", fb => fb.OfType("Text"))
                .Build();
            var part4Definition = new ContentPartDefinitionBuilder()
                .WithField("World", fb => fb.OfType("Text").WithSetting("Storage", "NoSuchName"))
                .Build();

            var provider1 = _selector.GetProvider(part1Definition.Fields.Single());
            var provider2 = _selector.GetProvider(part2Definition.Fields.Single());
            var provider3 = _selector.GetProvider(part3Definition.Fields.Single());
            var provider4 = _selector.GetProvider(part4Definition.Fields.Single());

            Assert.That(provider1.ProviderName, Is.EqualTo("Infoset"));
            Assert.That(provider2.ProviderName, Is.EqualTo("Infoset"));
            Assert.That(provider3.ProviderName, Is.EqualTo("Infoset"));
            Assert.That(provider4.ProviderName, Is.EqualTo("Infoset"));
        }
        public override void PartEditorUpdated(ContentPartDefinitionBuilder builder) {
            var contentPartDefinition = builder.Build();
            var newPartSettings = contentPartDefinition.Settings;

            if (newPartSettings.ContainsKey(_contentPartSettingsDescriptionName)) {
                var oldDescription = _oldPartSettings.Get(_contentPartSettingsDescriptionName);
                var newDescription = newPartSettings.Get(_contentPartSettingsDescriptionName);
                if (oldDescription != newDescription) {
                    var eventData = new Dictionary<string, object> {
                        {"ContentPartName", builder.Name},
                        {"OldDescription", oldDescription},
                        {"NewDescription", newDescription}
                    };
                    RecordContentPartAuditTrail(ContentPartAuditTrailEventProvider.DescriptionChanged, eventData, builder.Name);
                }
            }

            // Description change should not be re-recorded as general settings change.
            var remainingOldPartSettings = new SettingsDictionary(_oldPartSettings.Where(item => item.Key != _contentPartSettingsDescriptionName).ToDictionary(item => item.Key, item => item.Value));
            var remainingNewPartSettings = new SettingsDictionary(newPartSettings.Where(item => item.Key != _contentPartSettingsDescriptionName).ToDictionary(item => item.Key, item => item.Value));

            if (!AreEqual(remainingNewPartSettings, remainingOldPartSettings)) {
                var eventData = new Dictionary<string, object> {
                    {"ContentPartName", builder.Name},
                    {"OldSettings", ToXml(remainingOldPartSettings)},
                    {"NewSettings", ToXml(remainingNewPartSettings)}
                };
                RecordContentPartAuditTrail(ContentPartAuditTrailEventProvider.PartSettingsUpdated, eventData, builder.Name);
            }
        }
 public override void PartEditorUpdating(ContentPartDefinitionBuilder builder) {
     var contentPart = _contentDefinitionService.GetPart(builder.Name);
     _oldPartSettings = contentPart.Settings;
 }