public ContentEditorModelToRevision(AbstractFluentMappingEngine engine) : base(engine) { MappingContext .CreateUsing(x => new Revision <TypedEntity>() { Item = MappingContext.Engine.Map <TContentModel, TypedEntity>(x), //TODO: Is this correctly mapped ?? MetaData = new RevisionData(x.RevisionId, FixedStatusTypes.Draft) }); }
public EntitySnapshotToContentEditorModel(AbstractFluentMappingEngine engine) : base(engine) { MappingContext .CreateUsing(x => MappingContext.Engine.Map <Revision <TypedEntity>, TContentModel>(x.Revision)) .AfterMap( (source, dest) => { dest.UtcPublishedDate = source.PublishedDate(); }); }
/// <summary> /// Creates a map with the specified mapper & metadata /// </summary> /// <typeparam name="TS"></typeparam> /// <typeparam name="TT"></typeparam> /// <param name="engine"></param> /// <param name="mapper"></param> /// <param name="metadata"></param> /// <returns></returns> public static IMappingExpression <TS, TT> CreateMap <TS, TT>(this AbstractFluentMappingEngine engine, ITypeMapper <TS, TT> mapper, TypeMapperMetadata metadata) { engine.AddMap(mapper, metadata); //create enumerable type map for the types automatically if they aren't already IEnumerable engine.CreateEnumerableMap <TS, TT>(); var expression = new MappingExpression <TS, TT>(mapper.MappingContext); return(expression); }
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 RevisionToContentEditorModel(AbstractFluentMappingEngine engine) : base(engine) { MappingContext .CreateUsing(x => { var output = MappingContext.Engine.Map<TypedEntity, TContentModel>(x.Item); output.RevisionId = x.MetaData.Id; return output; }); }
/// <summary> /// Creates a new mapper with the specified mapper and default metadata with the permitInheritance flag /// </summary> /// <typeparam name="TS"></typeparam> /// <typeparam name="TT"></typeparam> /// <param name="engine"></param> /// <param name="mapper"></param> /// <param name="permitInheritance"></param> /// <returns></returns> public static IMappingExpression <TS, TT> CreateMap <TS, TT>(this AbstractFluentMappingEngine engine, ITypeMapper <TS, TT> mapper, bool permitInheritance) { var metadata = new TypeMapperMetadata(typeof(TS), typeof(TT), permitInheritance); engine.AddMap(mapper, metadata); //create enumerable type map for the types automatically if they aren't already IEnumerable engine.CreateEnumerableMap <TS, TT>(); var expression = new MappingExpression <TS, TT>(mapper.MappingContext); return(expression); }
/// <summary> /// Creates a new map with the specified metadata and default mapper /// </summary> /// <typeparam name="TS"></typeparam> /// <typeparam name="TT"></typeparam> /// <param name="engine"></param> /// <param name="metadata"></param> /// <returns></returns> public static IMappingExpression <TS, TT> CreateMap <TS, TT>(this AbstractFluentMappingEngine engine, TypeMapperMetadata metadata) { //first we need to check if it's enumerable, if so we need to create an Enumerable injector mapper if (typeof(TS).IsEnumerable() && typeof(TT).IsEnumerable()) { var mapper = new EnumerableTypeMapper <TS, TT>(engine); return(engine.CreateMap(mapper, metadata)); } else { var mapper = new TypeMapper <TS, TT>(engine); return(engine.CreateMap(mapper, metadata)); } }
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 DataTypeToAttributeType(AbstractFluentMappingEngine engine, Action <TInput, AttributeType> additionalAfterMap = null) : base(engine) { MappingContext .CreateUsing(x => { var typeRegistry = AttributeTypeRegistry.Current; if (typeRegistry != null) { var existing = typeRegistry.TryGetAttributeType(x.Name).Result; if (existing != null) { return(existing); } } return(new AttributeType() { Id = x.Id }); }) // Ignore the Id. In the CreateUsing, we either return the AttributeType from the registry with its inferred Id, // or we set the Id there from the source. .ForMember(x => x.Id, opt => opt.Ignore()) .ForMember(x => x.UtcCreated, opt => opt.MapUsing <UtcCreatedMapper>()) .ForMember(x => x.UtcModified, opt => opt.MapUsing <UtcModifiedMapper>()) .AfterMap((source, dest) => { if (string.IsNullOrEmpty(dest.Alias)) { dest.Alias = source.Name.ToRebelAlias(); } //TODO: Detect serialization type from DataType dest.SerializationType = new LongStringSerializationType(); if (additionalAfterMap != null) { additionalAfterMap(source, dest); } }); }
public DocumentTypeToNewContentModel(AbstractFluentMappingEngine engine, Action <DocumentTypeEditorModel, TTarget> additionalAfterMap = null) : base(engine) { //set all of the member expressions MappingContext .ForMember(x => x.DocumentTypeName, opt => opt.MapFrom(x => x.Name)) .ForMember(x => x.DocumentTypeId, opt => opt.MapFrom(x => x.Id)) .ForMember(x => x.Id, opt => opt.Ignore()) .ForMember(x => x.ActiveTabIndex, opt => opt.Ignore()) .ForMember(x => x.UpdatedBy, opt => opt.Ignore()) .ForMember(x => x.CreatedBy, opt => opt.Ignore()) .ForMember(x => x.UtcCreated, opt => opt.Ignore()) .ForMember(x => x.UtcModified, opt => opt.Ignore()) .ForMember(x => x.ParentId, opt => opt.Ignore()) .ForMember(x => x.Name, opt => opt.Ignore()) .ForMember(x => x.Properties, opt => opt.MapFrom(x => x.Properties)) .ForMember(x => x.NoticeBoard, x => x.Ignore()) .ForMember(x => x.UIElements, x => x.Ignore()) .AfterMap((source, dest) => { dest.DocumentTypeId = source.Id; dest.DocumentTypeName = source.Name; dest.DocumentTypeAlias = source.Alias; dest.Tabs = MappingContext.Engine.Map <HashSet <Tab>, HashSet <Tab> >(source.DefinedTabs); //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 contentAwarePropEditor = (IContentAwarePropertyEditor)p.DocTypeProperty.DataType.InternalPropertyEditor; contentAwarePropEditor.SetDocumentType(source); } if (additionalAfterMap != null) { additionalAfterMap(source, dest); } }); }
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); } }); }
/// <summary> /// Maps a type to itself. This is used to clone an object. /// </summary> /// <typeparam name = "TSource"></typeparam> /// <returns></returns> public static IMappingExpression <TSource, TSource> SelfMap <TSource>(this AbstractFluentMappingEngine engine) { return(engine.CreateMap <TSource, TSource>()); }
/// <summary> /// Maps a type to itself. This is used to clone an object. /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="engine"></param> /// <param name="permitInheritance"></param> /// <returns></returns> public static IMappingExpression <TSource, TSource> SelfMap <TSource>(this AbstractFluentMappingEngine engine, bool permitInheritance) { return(engine.CreateMap <TSource, TSource>(permitInheritance)); }
public TypeMapper(AbstractFluentMappingEngine engine) : base(engine) { }
/// <summary> /// Creates a new map with the default mapper and metadata /// </summary> /// <typeparam name="TS">The type of the S.</typeparam> /// <typeparam name="TT">The type of the T.</typeparam> /// <param name="engine">The engine.</param> /// <returns></returns> public static IMappingExpression <TS, TT> CreateMap <TS, TT>(this AbstractFluentMappingEngine engine) { return(engine.CreateMap <TS, TT>(new TypeMapperMetadata(typeof(TS), typeof(TT), false))); }
public EntitySchemaToSchemaEditorModel( AbstractFluentMappingEngine engine, Func <EntitySchema, TEditorModel> createWith, Action <EntitySchema, TEditorModel> additionalAfterMap = null) : base(engine) { MappingContext .CreateUsing(createWith) .MapMemberFrom(x => x.Thumbnail, x => x.GetXmlConfigProperty("thumb")) .MapMemberFrom(x => x.AllowedChildIds, x => x.GetXmlPropertyAsList <HiveId>("allowed-children")) .MapMemberFrom(x => x.Icon, x => x.GetXmlConfigProperty("icon")) .MapMemberFrom(x => x.Thumbnail, x => x.GetXmlConfigProperty("thumb")) .MapMemberFrom(x => x.DefinedTabs, x => MappingContext.Engine.Map <IEnumerable <AttributeGroup>, HashSet <Tab> >(x.AttributeGroups.ToArray())) .MapMemberFrom(x => x.Description, x => x.GetXmlConfigProperty("description")) .MapMemberFrom(x => x.IsAbstract, x => x.GetXmlConfigProperty("is-abstract") != null && bool.Parse(x.GetXmlConfigProperty("is-abstract"))) .AfterMap((from, to) => { // Commented out the below as working on multi-inheritance and the blow assumes one parent only (MB - 2011-11-15) //var firstParentFound = //from.RelationProxies.GetParentRelations(FixedRelationTypes.DefaultRelationType). // FirstOrDefault(); //if (firstParentFound != null && !firstParentFound.Item.SourceId.IsNullValueOrEmpty()) // to.ParentId = firstParentFound.Item.SourceId; //first, map the properties from the attribute definition (but not the special fields) to.Properties.Clear(); from.AttributeDefinitions //.Where(x => !FixedAttributeDefinitionAliases.AllAliases.Contains(x.Alias)) .ForEach(y => to.Properties.Add( MappingContext.Engine.Map <AttributeDefinition, DocumentTypeProperty>(y))); //set the available tabs select list to.AvailableTabs = new List <SelectListItem>( to.DefinedTabs.Where(x => !x.Id.IsNullValueOrEmpty()).OrderBy(x => x.SortOrder) .Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() })) .ToArray(); //set the inherit from list to.InheritFromIds = from.RelationProxies.GetParentRelations(FixedRelationTypes.DefaultRelationType).Select( x => x.Item.SourceId); var merged = from as CompositeEntitySchema; if (merged != null) { to.InheritedProperties.Clear(); merged.InheritedAttributeDefinitions .ForEach(y => to.InheritedProperties.Add(MappingContext.Engine.Map <AttributeDefinition, DocumentTypeProperty>(y))); to.InheritedTabs = MappingContext.Engine.Map <IEnumerable <AttributeGroup>, HashSet <Tab> >( merged.InheritedAttributeGroups.ToArray()); } if (additionalAfterMap != null) { additionalAfterMap(from, to); } }); }
public SearchResultToTypedEntity(ExamineHelper helper, AbstractFluentMappingEngine engine) : base(engine) { _helper = helper; }
/// <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 TypedEntityToContentProperties(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }
public FooBarMapper(AbstractFluentMappingEngine engine) : base(engine) { }
protected StandardMemberMapper(AbstractFluentMappingEngine currentEngine, MapResolverContext context) { CurrentEngine = currentEngine; ResolverContext = context; }
public DocumentTypePropertyToAttributeGroup(AbstractFluentMappingEngine currentEngine, MapResolverContext context, bool returnNullValue = false) : base(currentEngine, context) { _returnNullValue = returnNullValue; }
public AttributeTypeToPropertyEditorId(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }
/// <summary> /// Maps relations for an IRelatableEntity and all entities attached to those relations to index operations /// </summary> /// <param name="entity"></param> /// <param name="operation"></param> /// <param name="engine"></param> internal static void MapRelations <T>(this T entity, NestedHiveIndexOperation operation, AbstractFluentMappingEngine engine) where T : IRelatableEntity { //get the relations foreach (var r in entity.RelationProxies.AllChildRelations().Union(entity.RelationProxies.AllParentRelations())) { var relation = engine.Map <IReadonlyRelation <IRelatableEntity, IRelatableEntity>, NestedHiveIndexOperation>(r.Item); //we need to process the entities attached to the relation and add them to the sub index ops: if (entity.Id != r.Item.SourceId) { if (r.Item.Source != null) { operation.SubIndexOperations.Add(engine.Map <NestedHiveIndexOperation>(r.Item.Source)); } } if (entity.Id != r.Item.DestinationId) { if (r.Item.Destination != null) { operation.SubIndexOperations.Add(engine.Map <NestedHiveIndexOperation>(r.Item.Destination)); } } //now, we need to add the relation itself to the sub index ops: operation.SubIndexOperations.Add(relation); } }
public DocumentTypePropertyToAttributeType(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }
public ContentEditorModelToEntitySchema(AbstractFluentMappingEngine currentEngine, MapResolverContext context) : base(currentEngine, context) { }