/// <summary> /// Restore this reference into the entity object. /// </summary> /// <param name="entity">The entity to restore the reference into.</param> /// <param name="helper">The helper that provides us data access.</param> public void Restore(IEntity entity, EntityDecoder helper) { PropertyInfo property = entity.GetType().GetProperty(Property); object otherEntity = null; if (property == null || Type == ReferenceType.Null) { return; } // // Find the referenced entity based on the reference type. // if (Type == ReferenceType.Guid) { otherEntity = helper.GetExistingEntity(EntityType, helper.FindMappedGuid(new Guid(( string )Data))); } else if (Type == ReferenceType.EntityType) { otherEntity = new EntityTypeService(helper.RockContext).Queryable().Where(e => e.Name == ( string )Data).FirstOrDefault(); } else if (Type == ReferenceType.FieldType) { otherEntity = new FieldTypeService(helper.RockContext).Queryable().Where(f => f.Class == ( string )Data).FirstOrDefault(); } else if (Type == ReferenceType.UserDefined) { otherEntity = helper.GetUserDefinedValue(( string )Data); } else { throw new Exception(string.Format("Don't know how to handle reference type {0}.", Type)); } // // If we found an entity then get its Id number and store that. // if (otherEntity != null) { property.SetValue(entity, EntityCoder.ChangeType(property.PropertyType, otherEntity.GetPropertyValue("Id"))); } }
/// <summary> /// Creates a new entity reference object that is used to reconstruct the /// link between two entities in the database. /// </summary> /// <param name="entity">The entity we are creating a reference to.</param> /// <param name="propertyName">The name of the property in the containing entity.</param> public Reference(IEntity entity, string propertyName) { Type entityType = EntityCoder.GetEntityType(entity); EntityType = entityType.FullName; Property = propertyName; if (entity is EntityType) { Type = ReferenceType.EntityType; Data = (( EntityType )entity).Name; } else if (entity is FieldType) { Type = ReferenceType.FieldType; Data = (( FieldType )entity).Class; } else { Type = ReferenceType.Guid; Data = entity.Guid.ToString(); } }
/// <summary> /// An entity has been exported and can now have any post-processing done to it /// that is needed. For example a processor might remove some properties that shouldn't /// actually have been exported. /// </summary> /// <param name="entity">The source entity that was exported.</param> /// <param name="encodedEntity">The exported data from the entity.</param> /// <param name="helper">The helper that is doing the exporting.</param> /// <returns>An object that will be encoded with the entity and passed to the ProcessImportEntity method later, or null.</returns> public object ProcessExportedEntity(IEntity entity, EncodedEntity encodedEntity, EntityCoder helper) { return(ProcessExportedEntity(( T )entity, encodedEntity, helper)); }
/// <summary> /// Evaluate the list of child entities. This is a list of key value pairs that identify /// the property that the child came from as well as the child entity itself. Implementations /// of this method may add or remove from this list. For example, a WorkflowActionForm has /// it's actions encoded in a single string. This must processed to include any other /// objects that should exist (such as a DefinedValue for the button type). /// </summary> /// <param name="entity">The parent entity of the children.</param> /// <param name="children">The child entities and what properties of the parent they came from.</param> /// <param name="helper">The helper class for this export.</param> protected virtual void EvaluateChildEntities(T entity, List <KeyValuePair <string, IEntity> > children, EntityCoder helper) { }
/// <summary> /// Evaluate the list of child entities. This is a list of key value pairs that identify /// the property that the child came from as well as the child entity itself. Implementations /// of this method may add or remove from this list. For example, a WorkflowActionForm has /// it's actions encoded in a single string. This must processed to include any other /// objects that should exist (such as a DefinedValue for the button type). /// </summary> /// <param name="entity">The parent entity of the children.</param> /// <param name="children">The child entities and what properties of the parent they came from.</param> /// <param name="helper">The helper class for this export.</param> public void EvaluateChildEntities(IEntity entity, List <KeyValuePair <string, IEntity> > children, EntityCoder helper) { EvaluateChildEntities(( T )entity, children, helper); }
/// <summary> /// Evaluate the list of referenced entities. This is a list of key value pairs that identify /// the property that the reference came from as well as the referenced entity itself. Implementations /// of this method may add or remove from this list. For example, an AttributeValue has /// the entity it is referencing in a EntityId column, but there is no general use information for /// what kind of entity it is. The processor can provide that information. /// </summary> /// <param name="entity">The parent entity of the references.</param> /// <param name="references">The referenced entities and what properties of the parent they came from.</param> /// <param name="helper">The helper class for this export.</param> protected virtual void EvaluateReferencedEntities(T entity, List <KeyValuePair <string, IEntity> > references, EntityCoder helper) { }
/// <summary> /// Evaluate the list of referenced entities. This is a list of key value pairs that identify /// the property that the reference came from as well as the referenced entity itself. Implementations /// of this method may add or remove from this list. For example, an AttributeValue has /// the entity it is referencing in a EntityId column, but there is no general use information for /// what kind of entity it is. The processor can provide that information. /// </summary> /// <param name="entity">The parent entity of the references.</param> /// <param name="references">The referenced entities and what properties of the parent they came from.</param> /// <param name="helper">The helper class for this export.</param> public void EvaluateReferencedEntities(IEntity entity, List <KeyValuePair <string, IEntity> > references, EntityCoder helper) { EvaluateReferencedEntities(( T )entity, references, helper); }
/// <summary> /// An entity has been exported and can now have any post-processing done to it /// that is needed. For example a processor might remove some properties that shouldn't /// actually have been exported. /// </summary> /// <param name="entity">The source entity that was exported.</param> /// <param name="encodedEntity">The exported data from the entity.</param> /// <param name="helper">The helper that is doing the exporting.</param> /// <returns>An object that will be encoded with the entity and passed to the ProcessImportEntity method later, or null.</returns> protected virtual object ProcessExportedEntity(T entity, EncodedEntity encodedEntity, EntityCoder helper) { return(null); }