/// <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, "element"); Argument.ThrowIfNull(contentTypeDefinitionBuilder, "contentTypeDefinitionBuilder"); // Merge name contentTypeDefinitionBuilder.Named(XmlConvert.DecodeName(element.Name.LocalName)); // 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); } }); } } }
public void Merge(XElement source, ContentTypeDefinitionBuilder 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 partElement = iter; var partName = XmlConvert.DecodeName(partElement.Name.LocalName); if (partName == "remove") { var nameAttribute = partElement.Attribute("name"); if (nameAttribute != null) { builder.RemovePart(nameAttribute.Value); } } else { builder.WithPart( partName, partBuilder => { foreach (var setting in _settingsReader.Map(partElement)) { partBuilder.WithSetting(setting.Key, setting.Value); } }); } } }
public virtual ContentItem New(string contentType) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentType); if (contentTypeDefinition == null) { contentTypeDefinition = new ContentTypeDefinitionBuilder().Named(contentType).Build(); } // create a new kernel for the model instance var context = new ActivatingContentContext { ContentType = contentTypeDefinition.Name, Definition = contentTypeDefinition, Builder = new ContentItemBuilder(contentTypeDefinition) }; // invoke handlers to weld aspects onto kernel Handlers.Invoke(handler => handler.Activating(context), _logger); var context2 = new ActivatedContentContext { ContentType = contentType, ContentItem = context.Builder.Build() }; Handlers.Invoke(handler => handler.Activated(context2), _logger); var context3 = new InitializingContentContext { ContentType = context2.ContentType, ContentItem = context2.ContentItem, }; Handlers.Invoke(handler => handler.Initializing(context3), _logger); Handlers.Invoke(handler => handler.Initialized(context3), _logger); // composite result is returned return context3.ContentItem; }
public void ChildElementsAreAddedAsPartsWithSettings() { var builder = new ContentTypeDefinitionBuilder(); _reader.Merge(new XElement("foo", new XElement("bar", new XAttribute("y", "2"))), builder); var type = builder.Build(); Assert.That(type.Parts.Single().PartDefinition.Name, Is.EqualTo("bar")); Assert.That(type.Parts.Single().Settings["y"], Is.EqualTo("2")); }
public static void AlterTypeDefinition(this IContentDefinitionManager manager, string name, Action<ContentTypeDefinitionBuilder> alteration) { var typeDefinition = manager.GetTypeDefinition(name) ?? new ContentTypeDefinition(name); var builder = new ContentTypeDefinitionBuilder(typeDefinition); alteration(builder); manager.StoreTypeDefinition(builder.Build()); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var model = new SecurableContentItemsSettingsViewModel(); updateModel.TryUpdateModel(model, "SecurableContentItemsSettingsViewModel", null, null); builder.WithSetting("ContentPermissionsTypeSettings.SecurableContentItems", model.SecurableContentItems.ToString()); yield return DefinitionTemplate(model); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var model = new ContentTypeSettings(); updateModel.TryUpdateModel(model, "ContentTypeSettings", null, null); builder.Creatable(model.Creatable); builder.Draftable(model.Draftable); yield return DefinitionTemplate(model); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var model = new AssociativyTaxonomiesAdapterTypeSettings(); updateModel.TryUpdateModel(model, "AssociativyTaxonomiesAdapterTypeSettings", null, null); builder.WithSetting("AssociativyTaxonomiesAdapterTypeSettings.GraphNamesSerialized", model.GraphNamesSerialized); yield return DefinitionTemplate(model); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var model = new ExperimentalSettings(); updateModel.TryUpdateModel(model, "ExperimentalSettings", null, null); builder .WithSetting("ExperimentalSettings.ShowDebugLinks", model.ShowDebugLinks ? true.ToString() : null); yield return DefinitionTemplate(model); }
public static IUser Create(string role) { var simulationType = new ContentTypeDefinitionBuilder().Named("User").Build(); var simulation = new ContentItemBuilder(simulationType) .Weld<SimulatedUser>() .Weld<SimulatedUserRoles>() .Build(); simulation.As<SimulatedUserRoles>().Roles = new[] {role}; return simulation.As<IUser>(); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var model = new TypeIndexing(); updateModel.TryUpdateModel(model, "TypeIndexing", null, null); builder.WithSetting("TypeIndexing.Indexes", model.Indexes); CreateIndexingTasks(); yield return DefinitionTemplate(model); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var model = new DynamicTypeSettingsViewModel(); updateModel.TryUpdateModel(model, "DynamicTypeSettingsViewModel", null, null); builder.WithSetting("DynamicTypeSettings.IsDeployed", model.IsDeployed.ToString()); yield return DefinitionTemplate(model); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var settings = builder.Current.Settings; if (settings.ContainsKey("Stereotype") && settings["Stereotype"] == "Media") { var model = new MediaFileNameEditorSettings(); if (updateModel.TryUpdateModel(model, "MediaFileNameEditorSettings", null, null)) { builder.WithSetting("MediaFileNameEditorSettings.ShowFileNameEditor", model.ShowFileNameEditor.ToString()); } } return base.TypeEditorUpdate(builder, updateModel); }
public void ContentTypeNameAndSettingsFromScratch() { var contentTypeDefinition = new ContentTypeDefinitionBuilder() .Named("alpha") .WithSetting("a", "1") .WithSetting("b", "2") .Build(); Assert.That(contentTypeDefinition.Name, Is.EqualTo("alpha")); Assert.That(contentTypeDefinition.Settings.Count(), Is.EqualTo(2)); Assert.That(contentTypeDefinition.Settings["a"], Is.EqualTo("1")); Assert.That(contentTypeDefinition.Settings["b"], Is.EqualTo("2")); }
public void PartsCanBeRemovedByNameWhenImporting() { const string partToBeRemoved = "alpha"; var builder = new ContentTypeDefinitionBuilder(); _reader.Merge(new XElement("foo", new XElement(partToBeRemoved), new XElement("remove", new XAttribute("name", partToBeRemoved)) ), builder); var type = builder.Build(); Assert.That(type.Parts.FirstOrDefault(part => part.PartDefinition.Name == partToBeRemoved), Is.Null); }
public void TypeAndTypePartSettingsAreAttributes() { var alpha = new ContentTypeDefinitionBuilder() .Named("alpha") .WithSetting("x", "1") .WithPart("beta", part => part.WithSetting(" y ", "2")) .Build(); var alphaInfoset = _writer.Export(alpha); Assert.That(alphaInfoset.Attributes("x").Single().Value, Is.EqualTo("1")); Assert.That(alphaInfoset.Elements("beta").Attributes(XmlConvert.EncodeLocalName(" y ")).Single().Value, Is.EqualTo("2")); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var model = new ContentTypeSettingsViewModel(); updateModel.TryUpdateModelAsync(model, "ContentTypeSettingsViewModel").Wait(); builder.Creatable(model.Creatable); builder.Listable(model.Listable); builder.Draftable(model.Draftable); builder.Securable(model.Securable); builder.WithSetting("Stereotype", model.Stereotype); yield return DefinitionTemplate(model); }
public void ContentRebuildWithoutModification() { var contentTypeDefinition1 = new ContentTypeDefinitionBuilder() .Named("alpha") .WithSetting("a", "1") .WithSetting("b", "2") .Build(); var contentTypeDefinition2 = new ContentTypeDefinitionBuilder(contentTypeDefinition1) .Build(); Assert.That(contentTypeDefinition1, Is.Not.SameAs(contentTypeDefinition2)); Assert.That(contentTypeDefinition2.Name, Is.EqualTo("alpha")); Assert.That(contentTypeDefinition2.Settings.Count(), Is.EqualTo(2)); Assert.That(contentTypeDefinition2.Settings["a"], Is.EqualTo("1")); Assert.That(contentTypeDefinition2.Settings["b"], Is.EqualTo("2")); }
public void AddingPartWithSettings() { var contentTypeDefinition = new ContentTypeDefinitionBuilder() .Named("alpha") .WithSetting("a", "1") .WithSetting("b", "2") .WithPart("foo", pb => pb.WithSetting("x", "10").WithSetting("y", "11")) .Build(); Assert.That(contentTypeDefinition.Name, Is.EqualTo("alpha")); Assert.That(contentTypeDefinition.Parts.Count(), Is.EqualTo(1)); Assert.That(contentTypeDefinition.Parts.Single().PartDefinition.Name, Is.EqualTo("foo")); Assert.That(contentTypeDefinition.Parts.Single().Settings.Count(), Is.EqualTo(2)); Assert.That(contentTypeDefinition.Parts.Single().Settings["x"], Is.EqualTo("10")); Assert.That(contentTypeDefinition.Parts.Single().Settings["y"], Is.EqualTo("11")); }
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { var previous = builder.Current.Settings.GetModel<TypeIndexing>(); var model = new TypeIndexing(); updateModel.TryUpdateModel(model, "TypeIndexing", null, null); builder.WithSetting("TypeIndexing.Indexes", model.Indexes); // create indexing tasks only if settings have changed if (Clean(model.Indexes) != Clean(previous.Indexes)) { // if a an index is added, all existing content items need to be re-indexed CreateIndexingTasks(); } yield return DefinitionTemplate(model); }
private ContentPart CreateContentItemPart() { var partDefinition = FooPartDefinition(); var typeDefinition = new ContentTypeDefinitionBuilder() .WithPart(partDefinition, part => { }) .Build(); var contentItem = new ContentItem { VersionRecord = new ContentItemVersionRecord { ContentItemRecord = new ContentItemRecord() } }; var contentPart = new ContentPart { TypePartDefinition = typeDefinition.Parts.Single() }; contentItem.Weld(contentPart); contentItem.Weld(new InfosetPart { Infoset = contentItem.Record.Infoset, VersionInfoset = contentItem.VersionRecord.Infoset }); return contentPart; }
public override void TypeEditorUpdated(ContentTypeDefinitionBuilder builder) { var contentTypeDefinition = builder.Build(); var newDisplayName = contentTypeDefinition.DisplayName; var newSettings = contentTypeDefinition.Settings; if (newDisplayName != _oldContentTypeDisplayName) { var eventData = new Dictionary<string, object> { {"ContentTypeName", builder.Current.Name}, {"OldDisplayName", _oldContentTypeDisplayName}, {"NewDisplayName", newDisplayName} }; RecordContentTypeAuditTrail(ContentTypeAuditTrailEventProvider.TypeDisplayNameUpdated, eventData, contentTypeDefinition.Name); } if (!AreEqual(newSettings, _oldContentTypeSettings)) { var eventData = new Dictionary<string, object> { {"ContentTypeName", builder.Current.Name}, {"OldSettings", ToXml(_oldContentTypeSettings)}, {"NewSettings", ToXml(newSettings)} }; RecordContentTypeAuditTrail(ContentTypeAuditTrailEventProvider.TypeSettingsUpdated, eventData, contentTypeDefinition.Name); } }
public static ContentTypeDefinition Import(this IContentDefinitionReader reader, XElement source) { var target = new ContentTypeDefinitionBuilder(); reader.Merge(source, target); return target.Build(); }
public void CanAlterPartSettingsByNameDuringRebuild() { var contentTypeDefinition1 = new ContentTypeDefinitionBuilder() .Named("alpha") .WithPart("foo", pb => pb.WithSetting("x", "10").WithSetting("y", "11")) .Build(); var contentTypeDefinition2 = new ContentTypeDefinitionBuilder(contentTypeDefinition1) .WithPart("foo", pb => pb.WithSetting("x", "12").WithSetting("z", "13")) .Build(); Assert.That(contentTypeDefinition1.Name, Is.EqualTo("alpha")); Assert.That(contentTypeDefinition1.Parts.Count(), Is.EqualTo(1)); Assert.That(contentTypeDefinition1.Parts.Single().PartDefinition.Name, Is.EqualTo("foo")); Assert.That(contentTypeDefinition1.Parts.Single().Settings.Count(), Is.EqualTo(2)); Assert.That(contentTypeDefinition1.Parts.Single().Settings["x"], Is.EqualTo("10")); Assert.That(contentTypeDefinition1.Parts.Single().Settings["y"], Is.EqualTo("11")); Assert.That(contentTypeDefinition2.Name, Is.EqualTo("alpha")); Assert.That(contentTypeDefinition2.Parts.Count(), Is.EqualTo(1)); Assert.That(contentTypeDefinition2.Parts.Single().PartDefinition.Name, Is.EqualTo("foo")); Assert.That(contentTypeDefinition2.Parts.Single().Settings.Count(), Is.EqualTo(3)); Assert.That(contentTypeDefinition2.Parts.Single().Settings["x"], Is.EqualTo("12")); Assert.That(contentTypeDefinition2.Parts.Single().Settings["y"], Is.EqualTo("11")); Assert.That(contentTypeDefinition2.Parts.Single().Settings["z"], Is.EqualTo("13")); }
public void AttributesAreAppliedAsSettings() { var builder = new ContentTypeDefinitionBuilder(); _reader.Merge(new XElement("foo", new XAttribute("x", "1")), builder); var type = builder.Build(); Assert.That(type.Settings["x"], Is.EqualTo("1")); }
public void ReadingElementSetsName() { var builder = new ContentTypeDefinitionBuilder(); _reader.Merge(new XElement("foo"), builder); var type = builder.Build(); Assert.That(type.Name, Is.EqualTo("foo")); }
public void GetContentTypesShouldReturnAllTypes() { // Register the types and obtain them ContentTypeDefinition alphaType = new ContentTypeDefinitionBuilder() .Named(DefaultAlphaName) .Build(); ContentTypeDefinition betaType = new ContentTypeDefinitionBuilder() .Named(DefaultBetaName) .Build(); ContentTypeDefinition gammaType = new ContentTypeDefinitionBuilder() .Named(DefaultGammaName) .Build(); ContentTypeDefinition deltaType = new ContentTypeDefinitionBuilder() .Named(DefaultDeltaName) .Build(); _contentDefinitionManager.Setup(contentDefinitionManager => contentDefinitionManager.ListTypeDefinitions()) .Returns(new List<ContentTypeDefinition> { alphaType, betaType, gammaType, deltaType }); var types = _manager.GetContentTypeDefinitions(); // Validate that the expected types were obtained Assert.That(types.Count(), Is.EqualTo(4)); Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultAlphaName)); Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultBetaName)); Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultGammaName)); Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultDeltaName)); }
public void ExistingTypeAndPartDefinitionShouldBeUsed() { var alphaType = new ContentTypeDefinitionBuilder() .Named(DefaultAlphaName) .WithSetting("x", "1") .WithPart("foo") .WithPart("FlavoredPart", part => part.WithSetting("spin", "clockwise")) .Build(); _contentDefinitionManager .Setup(x => x.GetTypeDefinition(DefaultAlphaName)) .Returns(alphaType); var contentItem = _manager.New(DefaultAlphaName); Assert.That(contentItem.ContentType, Is.EqualTo(DefaultAlphaName)); Assert.That(contentItem.TypeDefinition, Is.Not.Null); Assert.That(contentItem.TypeDefinition, Is.SameAs(alphaType)); var flavored = contentItem.As<FlavoredPart>(); Assert.That(flavored, Is.Not.Null); Assert.That(flavored.TypePartDefinition, Is.Not.Null); Assert.That(flavored.TypePartDefinition.Settings["spin"], Is.EqualTo("clockwise")); }
public override void TypeEditorUpdating(ContentTypeDefinitionBuilder definition) { var contentType = _contentDefinitionService.GetType(definition.Current.Name); _oldContentTypeDisplayName = contentType.DisplayName; _oldContentTypeSettings = new SettingsDictionary(contentType.Settings); }