/// <summary> /// Adds the object information. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="message">The message.</param> /// <param name="idType">Type of the identifier.</param> /// <param name="lifecycle">The lifecycle.</param> /// <param name="role">The role.</param> /// <param name="type">The type.</param> /// <param name="objectKeyPropertyName">Name of the object key property.</param> /// <param name="objectKeyClassifier">The object key classifier.</param> /// <param name="includeDetail">if set to <c>true</c> [include detail].</param> /// <param name="objects">The objects.</param> protected void AddObjectInfo <T>(AuditData message, AuditableObjectIdType idType, AuditableObjectLifecycle lifecycle, AuditableObjectRole role, AuditableObjectType type, string objectKeyPropertyName, string objectKeyClassifier = null, bool includeDetail = false, T objects = default(T)) { this.AddObjectInfoEx <T>(message, idType, lifecycle, role, type, objectKeyPropertyName, objectKeyClassifier, includeDetail, new List <T>() { objects }); }
/// <summary> /// Creates the base auditable object. /// </summary> /// <param name="idType">Type of the identifier.</param> /// <param name="lifecycleType">Type of the lifecycle.</param> /// <param name="objectId">The object identifier.</param> /// <param name="role">The role.</param> /// <param name="type">The type.</param> /// <returns>Returns the created auditable object instance.</returns> protected AuditableObject CreateBaseAuditableObject(AuditableObjectIdType idType, AuditableObjectLifecycle lifecycleType, string objectId, AuditableObjectRole role, AuditableObjectType type) { return(new AuditableObject { IDTypeCode = idType, LifecycleType = lifecycleType, ObjectId = objectId, Role = role, Type = type }); }
/// <summary> /// Audit internal resources. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="message">The message.</param> /// <param name="idType">Type of the identifier.</param> /// <param name="lifecycle">The lifecycle.</param> /// <param name="role">The role.</param> /// <param name="type">The type.</param> /// <param name="objectKeyPropertyName">Name of the object key property.</param> /// <param name="objectKeyClassifier">The object key classifier.</param> /// <param name="includeDetail">if set to <c>true</c> [include detail].</param> /// <param name="objects">The objects.</param> /// <exception cref="System.ArgumentNullException">objectKeyPropertyName /// or /// message</exception> /// <exception cref="System.ArgumentException">objectKeyPropertyName</exception> protected void AddObjectInfoEx <T>(AuditData message, AuditableObjectIdType idType, AuditableObjectLifecycle lifecycle, AuditableObjectRole role, AuditableObjectType type, string objectKeyPropertyName, string objectKeyClassifier = null, bool includeDetail = false, IEnumerable <T> objects = null) { if (objects == null) { return; } // Validate parameters if (objectKeyPropertyName == null) { throw new ArgumentNullException(nameof(objectKeyPropertyName)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } // Get key property var objectKeyProperty = typeof(T).GetProperty(objectKeyPropertyName); if (objectKeyProperty == null) { throw new ArgumentException("objectKeyPropertyName"); } var idScope = typeof(T).Name; // Audit objects foreach (var obj in objects) { if (obj == null) { continue; } var auditableObject = new AuditableObject { IDTypeCode = idType, LifecycleType = lifecycle, Role = role, Type = type, ObjectId = idType == AuditableObjectIdType.Uri ? objectKeyProperty.GetValue(obj).ToString() : $"{objectKeyProperty.GetValue(obj)}^^^{objectKeyClassifier ?? idScope}" }; if (includeDetail) { string typeName = null; if (obj.GetType().GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Any() && obj.GetType().FullName.Contains("AnonymousType")) { typeName = objectKeyClassifier ?? idScope; } var detail = CreateObjectDataExtension(obj, name: typeName); auditableObject.ObjectData.Add(detail); } message.AuditableObjects.Add(auditableObject); } }