Ejemplo n.º 1
0
        /// <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")));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This method is called before the entity is saved and allows any final changes to the
 /// entity before it is stored in the database. Any Guid references that are not standard
 /// properties must also be updated, such as the Actions string of a WorkflowActionForm.
 /// </summary>
 /// <param name="entity">The in-memory entity that is about to be saved.</param>
 /// <param name="encodedEntity">The encoded information that was used to reconstruct the entity.</param>
 /// <param name="data">Custom data that was previously returned by ProcessExportedEntity.</param>
 /// <param name="helper">The helper in charge of the import process.</param>
 protected virtual void ProcessImportedEntity(T entity, EncodedEntity encodedEntity, object data, EntityDecoder helper)
 {
 }
Ejemplo n.º 3
0
 /// <summary>
 /// This method is called before the entity is saved and allows any final changes to the
 /// entity before it is stored in the database. Any Guid references that are not standard
 /// properties must also be updated, such as the Actions string of a WorkflowActionForm.
 /// </summary>
 /// <param name="entity">The in-memory entity that is about to be saved.</param>
 /// <param name="encodedEntity">The encoded information that was used to reconstruct the entity.</param>
 /// <param name="data">Custom data that was previously returned by ProcessExportedEntity.</param>
 /// <param name="helper">The helper in charge of the import process.</param>
 public void ProcessImportedEntity(IEntity entity, EncodedEntity encodedEntity, object data, EntityDecoder helper)
 {
     ProcessImportedEntity(( T )entity, encodedEntity, data, helper);
 }