public TypedEntityToContentEditorModel( AbstractFluentMappingEngine engine, MapResolverContext resolverContext, Action <TEntity, TContent> additionalAfterMap = null) : base(engine) { _resolverContext = resolverContext; MappingContext .MapMemberFrom(x => x.DocumentTypeAlias, x => x.EntitySchema.Alias) .MapMemberFrom(x => x.DocumentTypeName, x => x.EntitySchema.Name.ToString()) .MapMemberFrom(x => x.DocumentTypeId, x => x.EntitySchema.Id) .MapMemberUsing(x => x.Properties, new TypedEntityToContentProperties <TEntity>(MappingContext.Engine, _resolverContext)) .AfterMap((source, dest) => { if (source == null) { return; } //set the tabs and check if it's a composite schema var compositeSchema = source.EntitySchema as CompositeEntitySchema; IEnumerable <AttributeGroup> attributeGroups = source.EntitySchema.AttributeGroups.ToArray(); if (compositeSchema != null) { attributeGroups = attributeGroups.Concat(compositeSchema.InheritedAttributeGroups); } dest.Tabs = MappingContext.Engine.Map <IEnumerable <AttributeGroup>, HashSet <Tab> >(attributeGroups); var firstParentFound = source.RelationProxies.GetParentRelations(FixedRelationTypes.DefaultRelationType).FirstOrDefault(); if (firstParentFound != null && !firstParentFound.Item.SourceId.IsNullValueOrEmpty()) { dest.ParentId = firstParentFound.Item.SourceId; dest.OrdinalRelativeToParent = firstParentFound.Item.Ordinal; } //now, update the PropertyEditor context for each property with this item foreach (var p in dest.Properties .Where(p => p.DocTypeProperty.DataType.InternalPropertyEditor != null) .Where(p => p.DocTypeProperty.DataType.InternalPropertyEditor is IContentAwarePropertyEditor)) { var contentAwareProp = (IContentAwarePropertyEditor)p.DocTypeProperty.DataType.InternalPropertyEditor; contentAwareProp.SetContentItem(dest); contentAwareProp.SetDocumentType(MappingContext.Engine.Map <EntitySchema, DocumentTypeEditorModel>(source.EntitySchema)); } if (additionalAfterMap != null) { additionalAfterMap(source, dest); } }); }
public MemberToMemberEditorModel(AbstractFluentMappingEngine engine, MapResolverContext resolverContext, Action <TMember, TMemberEditorModel> additionalAfterMap = null) : base(engine, resolverContext, additionalAfterMap) { MappingContext //ignore all custom properties as these need to be mapped by the underlying attributes .ForMember(x => x.Name, opt => opt.Ignore()) .ForMember(x => x.Username, opt => opt.Ignore()) .ForMember(x => x.Password, opt => opt.Ignore()) .ForMember(x => x.ConfirmPassword, opt => opt.Ignore()) .ForMember(x => x.Email, opt => opt.Ignore()) .ForMember(x => x.IsApproved, opt => opt.Ignore()) .ForMember(x => x.LastLoginDate, opt => opt.Ignore()) .ForMember(x => x.LastActivityDate, opt => opt.Ignore()) .ForMember(x => x.LastPasswordChangeDate, opt => opt.Ignore()); }
public MembershipUserToUser( AbstractFluentMappingEngine engine, MapResolverContext resolverContext, Action <MembershipUser, TUser> additionalAfterMap = null) : base(engine) { _resolverContext = resolverContext; //MappingContext //MappingContext // .MapMemberFrom(x => x.DocumentTypeName, x => x.EntitySchema.Name.ToString()) // .MapMemberFrom(x => x.DocumentTypeId, x => x.EntitySchema.Id) // .MapMemberUsing(x => x.Properties, new TypedEntityToContentProperties<TEntity>(MappingContext.Engine, _resolverContext)) // .AfterMap((source, dest) => // { // if (source == null) // return; // //set the tabs and check if it's a composite schema // var compositeSchema = source.EntitySchema as CompositeEntitySchema; // IEnumerable<AttributeGroup> attributeGroups = source.EntitySchema.AttributeGroups.ToArray(); // if (compositeSchema != null) attributeGroups = attributeGroups.Concat(compositeSchema.InheritedAttributeGroups); // dest.Tabs = MappingContext.Engine.Map<IEnumerable<AttributeGroup>, HashSet<Tab>>(attributeGroups); // var firstParentFound = // source.RelationProxies.GetParentRelations(FixedRelationTypes.DefaultRelationType).FirstOrDefault(); // if (firstParentFound != null && !firstParentFound.Item.SourceId.IsNullValueOrEmpty()) // dest.ParentId = firstParentFound.Item.SourceId; // //now, update the PropertyEditor context for each property with this item // foreach (var p in dest.Properties // .Where(p => p.DocTypeProperty.DataType.InternalPropertyEditor != null) // .Where(p => p.DocTypeProperty.DataType.InternalPropertyEditor is IContentAwarePropertyEditor)) // { // var contentAwareProp = (IContentAwarePropertyEditor)p.DocTypeProperty.DataType.InternalPropertyEditor; // contentAwareProp.SetContentItem(dest); // contentAwareProp.SetDocumentType(MappingContext.Engine.Map<EntitySchema, DocumentTypeEditorModel>(source.EntitySchema)); // } // if (additionalAfterMap != null) // { // additionalAfterMap(source, dest); // } // }); }
public UserEditorModelToTypedEntity(AbstractFluentMappingEngine engine, MapResolverContext resolverContext, params string[] ignoreAttributeAliases) : base(engine, resolverContext, ignoreAttributeAliases) { MappingContext //ignore all custom properties (except password) as these need to be mapped by the underlying attributes .IgnoreMember(x => x.LastPasswordChangeDate) .IgnoreMember(x => x.LastActivityDate) .IgnoreMember(x => x.LastLoginDate) .IgnoreMember(x => x.IsApproved) .IgnoreMember(x => x.Email) .IgnoreMember(x => x.Username) .IgnoreMember(x => x.Name) .IgnoreMember(x => x.Applications) .IgnoreMember(x => x.StartMediaHiveId) .IgnoreMember(x => x.StartContentHiveId) .IgnoreMember(x => x.SessionTimeout); }
/// <summary> /// Initializes a new instance of the <see cref="ContentEditorModelToTypedEntity<TContentModel, TTypedEntity>"/> class. /// </summary> /// <param name="engine">The engine.</param> /// <param name="resolverContext">The resolver context.</param> /// <param name="ignoreAttributeAliases">The attribute aliases to ignore during attribute mapping</param> public ContentEditorModelToTypedEntity(AbstractFluentMappingEngine engine, MapResolverContext resolverContext, params string[] ignoreAttributeAliases) : base(engine) { MappingContext .ForMember(x => x.UtcCreated, opt => opt.MapUsing <UtcCreatedMapper>()) .ForMember(x => x.UtcModified, opt => opt.MapUsing <UtcModifiedMapper>()) .IgnoreMember(x => x.RelationProxies) .MapMemberUsing(x => x.EntitySchema, new ContentEditorModelToEntitySchema <TContentModel>(MappingContext.Engine, resolverContext)) .AfterMap((source, dest) => { if (!source.ParentId.IsNullValueOrEmpty()) { // Enlist the specified parent dest.RelationProxies.EnlistParentById(source.ParentId, FixedRelationTypes.DefaultRelationType, source.OrdinalRelativeToParent); } //add or update all properties in the model. //We need to manually create a mapper for this operation in order to keep the object graph consistent //with the correct instances of objects. This mapper will ignore mapping the AttributeDef on the TypedAttribute //so that we can manually assign it from our EntitySchema. var compositeSchema = dest.EntitySchema as CompositeEntitySchema; var propertyMapper = new ContentPropertyToTypedAttribute(MappingContext.Engine, true); foreach (var contentProperty in source.Properties.Where(x => !ignoreAttributeAliases.Contains(x.Alias))) { var typedAttribute = propertyMapper.Map(contentProperty); //now we need to manually assign the same attribute definition instance from our already mapped schema. Func <AttributeDefinition, bool> findAttrib = x => x.Id.Value == contentProperty.DocTypePropertyId.Value; var attDef = dest.EntitySchema.AttributeDefinitions.SingleOrDefault(findAttrib); if (compositeSchema != null && attDef == null) { attDef = compositeSchema.AllAttributeDefinitions.Single(findAttrib); } typedAttribute.AttributeDefinition = attDef; dest.Attributes.SetValueOrAdd(typedAttribute); } //now we need to remove any properties that don't exist in the model, excluding the 'special' internal fields var allAliases = source.Properties.Select(x => x.Alias).ToArray(); var toRemove = dest.Attributes.Where(x => !allAliases.Contains(x.AttributeDefinition.Alias)) .Select(x => x.Id).ToArray(); dest.Attributes.RemoveAll(x => toRemove.Contains(x.Id)); }); }
public DocumentTypePropertyToAttributeDefinition( AbstractFluentMappingEngine engine, MapResolverContext resolverContext, bool mapAttributeGroup = true) : base(engine) { _resolverContext = resolverContext; MappingContext .CreateUsing(x => new AttributeDefinition(x.Alias, x.Name)) .MapMemberFrom(x => x.Ordinal, x => x.SortOrder) .MapMemberUsing(x => x.AttributeType, new DocumentTypePropertyToAttributeType(engine, _resolverContext)) .MapMemberUsing(x => x.AttributeGroup, new DocumentTypePropertyToAttributeGroup(engine, _resolverContext, !mapAttributeGroup)) .ForMember(x => x.UtcModified, opt => opt.MapUsing <UtcModifiedMapper>()) .ForMember(x => x.UtcCreated, opt => opt.MapUsing <UtcCreatedMapper>()) .AfterMap((source, dest) => { if (dest.AttributeType == null) { throw new InvalidOperationException("The DataType property of the DocumentTypeProperty object cannot be null when mapping from DocumentTypeProperty -> AttributeDefinition"); } //This will check if the pre-value editor has overriding field capabilities. //If it does, it will persist these values to the RenderTypeProviderConfigOverride instead of the underlying //data type. if (source.PreValueEditor != null) { var preValueMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => source.PreValueEditor, source.GetType()); //checks if the model contains overrides var hasOverrides = preValueMetadata .Properties .Any(metaProp => metaProp.AdditionalValues.ContainsKey(RebelMetadataAdditionalInfo.AllowDocumentTypePropertyOverride.ToString())); //if this pre-value model has overrides, then persist them if (hasOverrides) { dest.RenderTypeProviderConfigOverride = source.PreValueEditor.GetSerializedValue(); } } }); }
public TypedEntityToContentProperties(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }
public RenderTypesModelMapper(MapResolverContext resolverContext) : base(resolverContext.FrameworkContext) { _resolverContext = resolverContext; }
public ContentEditorModelToEntitySchema(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }
public SchemaEditorModelToEntitySchema(AbstractFluentMappingEngine engine, MapResolverContext resolverContext, Action <TEditorModel, EntitySchema> additionAfterMap = null) : base(engine) { _resolverContext = resolverContext; MappingContext .ForMember(x => x.UtcCreated, opt => opt.MapUsing <UtcCreatedMapper>()) .ForMember(x => x.UtcModified, opt => opt.MapUsing <UtcModifiedMapper>()) .ForMember(x => x.SchemaType, opt => opt.MapFrom(x => FixedSchemaTypes.Content)) .AfterMap((from, to) => { // Commented out the below as working on multi-inheritance and the blow assumes one parent only (MB - 2011-11-15) //if (!from.ParentId.IsNullValueOrEmpty()) //{ // // Enlist the specified parent // // TODO: The ContentEditorModel needs to supply us with the ordinal of the existing relationship, if it exists // // otherwise we're always going to reset the Ordinal to 0 // to.RelationProxies.EnlistParentById(from.ParentId, FixedRelationTypes.DefaultRelationType, 0); //} // AttributeGroups on a schema are a union between manually added groups and those referenced in AttributeDefinitions // so rather than clearing the AttributeGroups and the definitions and remapping, first let's create a list of groups // separately var mappedGroups = engine.Map <IEnumerable <Tab>, IEnumerable <AttributeGroup> >(from.DefinedTabs); var existingOrNewGeneralGroup = to.AttributeGroups.Where(x => x.Alias == FixedGroupDefinitions.GeneralGroupAlias) .SingleOrDefault() ?? FixedGroupDefinitions.GeneralGroup; // Now let's go through the attribute definitions to.AttributeDefinitions.Clear(); to.AttributeGroups.Clear(); var definitionMapper = new DocumentTypePropertyToAttributeDefinition(engine, _resolverContext, false); foreach (var p in from.Properties) { var attrDef = definitionMapper.Map(p); if (p.TabId.IsNullValueOrEmpty()) { attrDef.AttributeGroup = existingOrNewGeneralGroup; } else { var found = mappedGroups.SingleOrDefault(x => x.Id == p.TabId); attrDef.AttributeGroup = found ?? existingOrNewGeneralGroup; } to.TryAddAttributeDefinition(attrDef); } // Now if there are any groups left that aren't linked to attributes add those too var unusedGroups = mappedGroups.Except(to.AttributeGroups).ToArray(); to.AttributeGroups.AddRange(unusedGroups); ////we'll map the attribute groups from defined tabs //to.AttributeDefinitions.Clear(); //to.AttributeGroups.Clear(); //from.DefinedTabs.ForEach(y => // to.AttributeGroups.Add( // engine.Map<Tab, AttributeGroup>(y))); ////see if there is a general group, if not create one //var generalGroup = to.AttributeGroups.Where(x => x.Alias == FixedGroupDefinitions.GeneralGroupAlias).SingleOrDefault(); //if(generalGroup == null) //{ // to.AttributeGroups.Add(FixedGroupDefinitions.GeneralGroup); //} ////Here we need to make sure the same AttributeGroup instances that were just created //// are assigned to the AttributeDefinition, to do this we create a new mapper instance and tell it //// not to map AttributeGroups and instead we'll assign the group manually. //var attDefMapper = new DocumentTypePropertyToAttributeDefinition(engine, _resolverContext, false); //foreach(var p in from.Properties) //{ // var attrDef = attDefMapper.Map(p); // if (p.TabId.IsNullValueOrEmpty()) // { // attrDef.AttributeGroup = generalGroup; // } // else // { // var found = to.AttributeGroups.SingleOrDefault(x => x.Id == p.TabId); // attrDef.AttributeGroup = found ?? generalGroup; // } // to.TryAddAttributeDefinition(attrDef); //} //ensure the 'in built' properties exist to.TryAddAttributeDefinition(new NodeNameAttributeDefinition(existingOrNewGeneralGroup)); to.TryAddAttributeDefinition(new SelectedTemplateAttributeDefinition(existingOrNewGeneralGroup)); to.SetXmlConfigProperty("thumb", from.Thumbnail); //save the description,icon to.SetXmlConfigProperty("description", from.Description); to.SetXmlConfigProperty("icon", from.Icon); //save the allowed children as a list of guids (for now) to.SetXmlConfigProperty("allowed-children", (from.AllowedChildren != null && from.AllowedChildren.Any()) ? from.AllowedChildren .Where(x => x.Selected) .Select(x => x.Value ?? string.Empty).ToArray() : new string[] { }); //save the is abstract/inheritable only setting to.SetXmlConfigProperty("is-abstract", from.IsAbstract); if (additionAfterMap != null) { additionAfterMap(from, to); } }); }
public DocumentTypePropertyToAttributeType(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }
protected StandardMemberMapper(AbstractFluentMappingEngine currentEngine, MapResolverContext context) { CurrentEngine = currentEngine; ResolverContext = context; }
/// <summary> /// Initializes a new instance of the <see cref="ContentEditorModelToTypedEntity<TContentModel, TTypedEntity>"/> class. /// </summary> /// <param name="engine">The engine.</param> /// <param name="resolverContext">The resolver context.</param> /// <param name="ignoreAttributeAliases">The attribute aliases to ignore during attribute mapping</param> public ContentEditorModelToTypedEntity(AbstractFluentMappingEngine engine, MapResolverContext resolverContext, params string[] ignoreAttributeAliases) : base(engine) { MappingContext .ForMember(x => x.UtcCreated, opt => opt.MapUsing <UtcCreatedMapper>()) .ForMember(x => x.UtcModified, opt => opt.MapUsing <UtcModifiedMapper>()) .IgnoreMember(x => x.RelationProxies) .MapMemberUsing(x => x.EntitySchema, new ContentEditorModelToEntitySchema <TContentModel>(MappingContext.Engine, resolverContext)) .AfterMap((source, dest) => { if (!source.ParentId.IsNullValueOrEmpty()) { var ordinalRelativeToParent = 0; using (var uow = resolverContext.Hive.OpenReader <IContentStore>(source.ParentId.ToUri())) { var siblingRelations = uow.Repositories.GetChildRelations(source.ParentId, FixedRelationTypes.DefaultRelationType) .OrderBy(x => x.Ordinal) .ToArray(); var myRelation = siblingRelations.SingleOrDefault(x => x.DestinationId.Value == source.Id.Value); if (myRelation != null) { ordinalRelativeToParent = myRelation.Ordinal; } else if (siblingRelations.Count() > 0) { ordinalRelativeToParent = siblingRelations.Max(x => x.Ordinal) + 1; } } // Enlist the specified parent dest.RelationProxies.EnlistParentById(source.ParentId, FixedRelationTypes.DefaultRelationType, ordinalRelativeToParent); } //add or update all properties in the model. //We need to manually create a mapper for this operation in order to keep the object graph consistent //with the correct instances of objects. This mapper will ignore mapping the AttributeDef on the TypedAttribute //so that we can manually assign it from our EntitySchema. var compositeSchema = dest.EntitySchema as CompositeEntitySchema; var propertyMapper = new ContentPropertyToTypedAttribute(MappingContext.Engine, true); var contentProperties = source.Properties.Where(x => !ignoreAttributeAliases.Contains(x.Alias)).ToArray(); foreach (var contentProperty in contentProperties) { var typedAttribute = propertyMapper.Map(contentProperty); //now we need to manually assign the same attribute definition instance from our already mapped schema. var localProperty = contentProperty; var localPropertyId = localProperty.DocTypePropertyId; if (localPropertyId == HiveId.Empty) { throw new Exception("Catastrophic failure: The content property to be mapped does not have an Id against the document type. Alias: {0}".InvariantFormat(localProperty.Alias)); } Func <AttributeDefinition, bool> findAttrib = x => x.Id.Value == localPropertyId.Value; var attDef = dest.EntitySchema.AttributeDefinitions.SingleOrDefault(findAttrib); if (compositeSchema != null && attDef == null) { attDef = compositeSchema.AllAttributeDefinitions.Single(findAttrib); } typedAttribute.AttributeDefinition = attDef; dest.Attributes.SetValueOrAdd(typedAttribute); } //now we need to remove any properties that don't exist in the model, excluding the 'special' internal fields var allAliases = source.Properties.Select(x => x.Alias).ToArray(); var toRemove = dest.Attributes.Where(x => !allAliases.Contains(x.AttributeDefinition.Alias)) .Select(x => x.Id).ToArray(); dest.Attributes.RemoveAll(x => toRemove.Contains(x.Id)); }); }
public AttributeTypeToPropertyEditorId(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }
public DocumentTypePropertyToAttributeGroup(AbstractFluentMappingEngine currentEngine, MapResolverContext context, bool returnNullValue = false) : base(currentEngine, context) { _returnNullValue = returnNullValue; }