private void LoadChangeLoggingConfiguration(EntityConfiguration config) { return; /* todo: check ABP audit logging and uncomment/remove * var propertiesNeedToLogChangesFor = config.EntityType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(prop => prop.GetCustomAttributes(typeof(LogChangesAttribute), true).Length > 0).ToList(); // BindingFlags.DeclaredOnly - removed to log changes for inherited properties * * if (!propertiesNeedToLogChangesFor.Any()) * { * config.HasPropertiesNeedToLogChangesFor = false; * } * else * { * config.HasPropertiesNeedToLogChangesFor = true; * if (string.IsNullOrEmpty(config.TypeShortAlias)) * throw new ConfigurationException(string.Format("Properties have been marked for Audit on entity '{0}' but a TypeShortAlias which is required for auditing has not been assigned for the entity. Tip: Apply the Entity attribute to the entity class to assign the TypeShortAlias.", config.EntityType.FullName)); * * foreach (var prop in propertiesNeedToLogChangesFor) * { * foreach (var attribute in prop.GetCustomAttributes(typeof(LogChangesAttribute), true).Cast<LogChangesAttribute>()) * { * // Ensuring that the LogChanges attribute is not applied to Collections/Lists. * if (ReflectionHelper.IsCollectionType(prop.PropertyType)) * { * throw new ConfigurationException(string.Format("Property '{0}' on entity '{1}' cannot be marked with LogChange Attribute as logging of changes to a collection is not supported.", prop.Name, config.EntityType.FullName)); * } * * var changeLogConfig = config.ChangeLogConfigurations.FirstOrDefault(o => o.Namespace == attribute.Namespace); * * if (changeLogConfig == null) * { * changeLogConfig = new EntityConfiguration.PropertySetChangeLoggingConfiguration(); * changeLogConfig.Namespace = attribute.Namespace; * config.ChangeLogConfigurations.Add(changeLogConfig); * } * * if (changeLogConfig.AuditedProperties.FirstOrDefault(propLoggingConfig => propLoggingConfig == prop.Name) != null) * { * throw new ConfigurationException(string.Format("Property '{0}' on entity '{1}' cannot have more than one LogChange Attribute.", prop.Name, config.EntityType.FullName)); * } * else * { * changeLogConfig.AuditedProperties.Add(prop.Name); * } * } * } * } */ }
/// inheritedDoc public EntityConfiguration Get(Type entityType) { var underlyingEntityType = entityType.StripCastleProxyType(); if (!_entityConfigurations.TryGetValue(underlyingEntityType, out var config)) { config = new EntityConfiguration(underlyingEntityType); lock (_entityConfigurations) { if (!_entityConfigurations.TryGetValue(underlyingEntityType, out _)) { _entityConfigurations.Add(underlyingEntityType, config); } } } return(config); }
private void LoadEntityConfiguration(EntityConfiguration config) { var entityAtt = config.EntityType.GetUniqueAttribute <EntityAttribute>(); // Defaulting the values. config.ControllerName = config.EntityType.Name; config.DetailsActionName = "Details"; config.CreateActionName = "Create"; config.EditActionName = "Edit"; config.InactivateActionName = "Inactivate"; config.DeleteActionName = "Delete"; if (entityAtt != null) { config.FriendlyName = string.IsNullOrEmpty(entityAtt.FriendlyName) ? config.EntityType.Name // Fall back to type name when friendly name is not specified : entityAtt.FriendlyName; /* todo: review CRUD functionality and uncomment/remove * config.ControllerName = !string.IsNullOrWhiteSpace(entityAtt.ControllerName) ? entityAtt.ControllerName : config.ControllerName; * config.DetailsActionName = !string.IsNullOrWhiteSpace(entityAtt.DetailsActionName) ? entityAtt.DetailsActionName : config.DetailsActionName; * config.CreateActionName = !string.IsNullOrWhiteSpace(entityAtt.CreateActionName) ? entityAtt.CreateActionName : config.CreateActionName; * config.EditActionName = !string.IsNullOrWhiteSpace(entityAtt.EditActionName) ? entityAtt.EditActionName : config.EditActionName; * config.InactivateActionName = !string.IsNullOrWhiteSpace(entityAtt.InactivateActionName) ? entityAtt.InactivateActionName : config.InactivateActionName; * config.DeleteActionName = !string.IsNullOrWhiteSpace(entityAtt.DeleteActionName) ? entityAtt.DeleteActionName : config.DeleteActionName; * config.DrillToView = entityAtt.DrillToView; */ } /* * config.CreatedUserPropertyInfo = ReflectionHelper.FindPropertyWithUniqueAttribute(config.EntityType, typeof(CreatedUserAttribute), typeof(string)); * config.CreatedTimestampPropertyInfo = ReflectionHelper.FindPropertyWithUniqueAttribute(config.EntityType, typeof(CreatedTimestampAttribute), typeof(DateTime?)); * config.LastUpdatedUserPropertyInfo = ReflectionHelper.FindPropertyWithUniqueAttribute(config.EntityType, typeof(LastUpdatedUserAttribute), typeof(string)); * config.LastUpdatedTimestampPropertyInfo = ReflectionHelper.FindPropertyWithUniqueAttribute(config.EntityType, typeof(LastUpdatedTimestampAttribute), typeof(DateTime?)); * config.DefaultSortOrderPropertyInfo = ReflectionHelper.FindPropertyWithUniqueAttribute(config.EntityType, typeof(SearchOrderAttribute), typeof(DateTime?)); */ config.TypeShortAlias = GetTypeShortAlias(config.EntityType); LoadChangeLoggingConfiguration(config); config.DisplayNamePropertyInfo = GetDisplayNamePropertyInfo(config.EntityType); }
public void LoadConfiguration([NotNull] EntityConfiguration config) { LoadEntityConfiguration(config); // Loading property configuration. var ownProps = config.EntityType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance).ToList(); var props = config.EntityType.GetProperties().ToList(); var propsWithoutDuplicates = props.GroupBy(p => p.Name, (name, duplicates) => duplicates .Select(dp => new { IsOwn = ownProps.Contains(dp), Prop = dp }) .OrderByDescending(dp => dp.IsOwn ? 1 : 0) .Select(dp => dp.Prop) .FirstOrDefault() ).ToList(); if (propsWithoutDuplicates.Count < props.Count) { var duplicates = props.Where(p => !propsWithoutDuplicates.Contains(p)).ToList(); props = propsWithoutDuplicates; } foreach (var prop in props) { try { var propConfig = new PropertyConfiguration(config.EntityType); LoadPropertyConfiguration(prop, propConfig); config.Properties.Add(prop.Name, propConfig); } catch { throw; } } }