/// <summary> /// Used to map AttributeTypes when mapping to the EntitySchema /// </summary> /// <param name="attributeType"></param> /// <param name="lookupHelper"></param> /// <param name="masterMapper"></param> /// <param name="attributeTypeCache">A local cache to resolve already resolved AttributeTypes</param> /// <returns></returns> private Model.Attribution.MetaData.AttributeType MapAttributeTypeDefinition( AttributeType attributeType, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper, ICollection <Model.Attribution.MetaData.AttributeType> attributeTypeCache = null) { //check if its already been resolved by alias if (attributeTypeCache != null) { var found = attributeTypeCache.SingleOrDefault(x => (Guid)x.Id.Value == attributeType.Id); if (found != null) { return(found); } } //TODO: //- Remove Ordinal, SerializationType, Status, Dates //- Add PreValue xml //- var mapped = new Model.Attribution.MetaData.AttributeType(); MapAttributeTypeDefinition(attributeType, mapped, lookupHelper, masterMapper); //add the mapped object to the cache if it exists if (attributeTypeCache != null) { attributeTypeCache.Add(mapped); } return(mapped); }
public void MapAttributeTypeDefinition(AttributeType source, Model.Attribution.MetaData.AttributeType destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { destination.Alias = source.Alias; destination.Id = (HiveId)source.Id; destination.Description = source.Description; destination.Name = source.Name; destination.RenderTypeProvider = source.RenderTypeProvider; destination.RenderTypeProviderConfig = source.XmlConfiguration; if (!string.IsNullOrEmpty(source.PersistenceTypeProvider)) { // TODO: Use TypeFinder, but requires TypeFinder to be moved into Framework. Otherwise, add caching var reverseSerializationType = Type.GetType(source.PersistenceTypeProvider, false, false); if (reverseSerializationType != null) { try { var obj = Activator.CreateInstance(reverseSerializationType) as IAttributeSerializationDefinition; destination.SerializationType = obj; } catch (Exception ex) { throw new TypeLoadException(string.Format("Cannot create type '{0}' which is specified for this AttributeType in the database; has the type changed since this item was last saved? Details: '{1}'", source.PersistenceTypeProvider, ex.Message), ex); } } else { throw new TypeLoadException(string.Format("Cannot load type '{0}' which is specified for this AttributeType in the database; either the Assembly has not been loaded into the AppDomain or it's been renamed since this item was last saved.", source.PersistenceTypeProvider)); } } }
public static AttributeType MapAttributeTypeDefinition(Model.Attribution.MetaData.AttributeType attributeType, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { Mandate.ParameterNotNull(attributeType, "AttributeType"); var mapped = GetObjectReference(attributeType.Id, lookupHelper, () => new AttributeType()); MapAttributeTypeDefinition(attributeType, mapped, lookupHelper, masterMapper); return(mapped); }
public static void MapAttributeTypeDefinition(Model.Attribution.MetaData.AttributeType source, AttributeType destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { destination.Id = (Guid)source.Id.Value; destination.Alias = source.Alias ?? StringExtensions.ToUmbracoAlias(source.Name); var attributeSerializationDefinition = source.SerializationType; if (attributeSerializationDefinition == null) { LogHelper.Warn(typeof(ModelToRdbmsMapper), ("source.SerializationType is null for AttributeType Id {0} and Alias {1}"), source.Id, source.Alias); return; } destination.PersistenceTypeProvider = attributeSerializationDefinition.GetType().AssemblyQualifiedName; //sets the values if it is dirty destination.TrySetPropertyFromDirty(toProp => toProp.Alias, source, fromProp => fromProp.Alias, () => source.Alias ?? StringExtensions.ToUmbracoAlias(source.Name)); destination.TrySetPropertyFromDirty(toProp => toProp.Description, source, fromProp => fromProp.Description, () => (string)source.Description); destination.TrySetPropertyFromDirty(toProp => toProp.Name, source, fromProp => fromProp.Name, () => (string)source.Name); destination.TrySetPropertyFromDirty(toProp => toProp.RenderTypeProvider, source, fromProp => fromProp.RenderTypeProvider); destination.TrySetPropertyFromDirty(toProp => toProp.XmlConfiguration, source, fromProp => fromProp.RenderTypeProviderConfig); }