public static List <AuditEntityConfiguration> GetAllEntityConfigurations() { #if NETFRAMEWORK using (new Profiling.Profiler(nameof(AuditEntityConfiguration), Profiling.AppDevSymbolType.ClassOperation, nameof(AuditEntityConfiguration.GetAllEntityConfigurations))) { #endif var entities = new List <AuditEntityConfiguration>(); foreach (var currentClassType in _auditableTypes) { if (SkipEntity(Common.GetTypeName(currentClassType, false))) { continue; } var newEntity = new AuditEntityConfiguration(); newEntity = new AuditEntityConfiguration { FullName = Common.GetTypeName(currentClassType, true), ShortName = Common.GetTypeName(currentClassType, false), Properties = AuditPropertyConfiguration.GetAuditEntityProperties(currentClassType).ToList() }; entities?.Add(newEntity); } return(entities); #if NETFRAMEWORK } #endif }
public static List <AuditPropertyConfiguration> GetAuditEntityProperties(Type runtimeEntityProperty) { #if NETFRAMEWORK using (new Profiling.Profiler(nameof(AuditPropertyConfiguration), Profiling.AppDevSymbolType.ClassOperation, "GetAuditEntityProperties")) { #endif var repo = ServiceLocator.Current.GetInstance <IRepositoryBuilder>().CreateRetrieveRepository(); List <AuditPropertyConfiguration> properties = new List <AuditPropertyConfiguration>(); AuditPropertyConfiguration newproperty = new AuditPropertyConfiguration(); List <AuditEntityConfiguration> existingEntities = repo.GetAll <AuditEntityConfiguration>(); AuditEntityConfiguration existingEntity = new AuditEntityConfiguration(); foreach (var currentProperty in MambaRuntimeType.FromPropertiesList(runtimeEntityProperty.GetProperties()) ?? Enumerable.Empty <MambaRuntimeType>()) { if ((SkipProperty(currentProperty.Name))) { continue; } newproperty = new AuditPropertyConfiguration(); existingEntity = existingEntities?.FirstOrDefault((a) => a.FullName == Common.GetTypeName(runtimeEntityProperty, true)); newproperty.Name = currentProperty.Name; newproperty.IsComplex = ((Common.IsPropertyPrimitiveOrSimple(currentProperty)) == false); if ((currentProperty.PropertyType.GenericTypeArguments.Length > 0) && (currentProperty.PropertyType.GenericTypeArguments.ToList().FirstOrDefault() != null)) { newproperty.DataType = Common.GetTypeName(currentProperty.PropertyType.GenericTypeArguments.ToList().FirstOrDefault(), true); } else { newproperty.DataType = Common.GetTypeName(currentProperty.PropertyType, true); } if (newproperty?.DataType == "System.String") { newproperty.IsCollection = false; } else { newproperty.IsCollection = Common.IsPropertyCollection(currentProperty); } if (existingEntity != null && existingEntity?.Properties?.FirstOrDefault((x) => x.Name == currentProperty.Name) != null) { newproperty.IsAuditable = (existingEntity?.Properties?.FirstOrDefault((x) => x.Name == currentProperty.Name)?.IsAuditable ?? false); } else { newproperty.IsAuditable = false; } properties?.Add(newproperty); } return(properties); #if NETFRAMEWORK } #endif }
public virtual void UpdateAuditEntityConfiguration(AuditEntityConfiguration newEntityConfiguration, IAuditingRepository repo = null) { repo = repo ?? ServiceLocator.Current.GetInstance <IRepositoryBuilder>().CreateAuditingRepository(); #if NETFRAMEWORK using (new Profiling.Profiler(nameof(AuditEntityConfiguration), Profiling.AppDevSymbolType.ClassOperation, nameof(AuditEntityConfiguration.UpdateAuditEntityConfiguration))) { #endif var newPropertyConfiguration = new AuditPropertyConfiguration(); var newProperties = newEntityConfiguration.Properties; Properties?.ForEach(oldPropertyConfiguration => { newPropertyConfiguration = newProperties? .FirstOrDefault(a => a.Name == oldPropertyConfiguration?.Name); if (newPropertyConfiguration == null) { repo.DeleteAuditPropertyConfiguration(oldPropertyConfiguration); } else { oldPropertyConfiguration?.UpdateAuditPropertyConfiguration(newPropertyConfiguration); newProperties?.RemoveAll(c => c.Name == newPropertyConfiguration.Name); } }); if (newProperties.Any()) { this?.AddProperties(newProperties); } repo.Save(this); #if NETFRAMEWORK } #endif }
/// <summary> /// Returns true if self and the provided entity have the same Id values /// and the Ids are not of the default Id value /// </summary> protected bool HasSameNonDefaultIdAs(AuditEntityConfiguration compareTo) { return(!IsTransient() && !compareTo.IsTransient() && Id.Equals(compareTo.Id)); }
/// <summary> /// Copies the current object to a new instance /// </summary> /// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param> /// <param name="copiedObjects">Objects that should be reused</param> /// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param> /// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param> /// <param name="copy">Optional - An existing [AuditEntityConfiguration] instance to use as the destination.</param> /// <returns>A copy of the object</returns> public virtual AuditEntityConfiguration Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, AuditEntityConfiguration copy = null) { if (copiedObjects == null) { copiedObjects = new Hashtable(); } if (copy == null && copiedObjects.Contains(this)) { return((AuditEntityConfiguration)copiedObjects[this]); } copy = copy ?? new AuditEntityConfiguration(); if (!asNew) { copy.TransientId = TransientId; copy.Id = Id; } copy.FullName = FullName; copy.ShortName = ShortName; if (!copiedObjects.Contains(this)) { copiedObjects.Add(this, copy); } copy.properties = new List <AuditPropertyConfiguration>(); if (deep && properties != null) { foreach (var __item in properties) { if (!copiedObjects.Contains(__item)) { if (asNew && reuseNestedObjects) { copy.AddProperties(__item); } else { copy.AddProperties(__item.Copy(deep, copiedObjects, asNew)); } } else { copy.AddProperties((AuditPropertyConfiguration)copiedObjects[__item]); } } } return(copy); }