Exemple #1
0
        /// <summary>
        /// Stores an AuditLog object for the ongoing transaction
        /// </summary>
        public static IAuditLog Logg <T>(IDwarf obj, AuditLogTypes auditLogType, params AuditLogEventTrace[] auditUpdateEvents)
        {
            var type = DwarfHelper.DeProxyfy(obj);

            if (type.Implements <IAuditLogless>() || type.Implements <IAuditLog>())
            {
                return(null);
            }

            var al = new AuditLog
            {
                ClassType    = type.Name,
                AuditLogType = auditLogType,
                UserName     = DwarfContext <T> .GetConfiguration().UserService.CurrentUser != null ? DwarfContext <T> .GetConfiguration().UserService.CurrentUser.UserName : string.Empty,
                TimeStamp    = DateTime.Now,
                ObjectValue  = obj.ToString(),
            };

            if (!type.Implements <ICompositeId>())
            {
                al.ObjectId = obj.Id.ToString();
            }
            else
            {
                foreach (var ep in DwarfHelper.GetPKProperties(type))
                {
                    al.ObjectId += string.Format("[{0}: {1}]", ep.Name, ep.GetValue(obj));
                }
            }

            if (auditLogType != AuditLogTypes.Created)
            {
                al.AuditDetails = "<?xml version=\"1.0\"?><Properties>";

                foreach (var auditUpdateEvent in auditUpdateEvents)
                {
                    al.AuditDetails += auditUpdateEvent.ToXml().ToString();
                }

                al.AuditDetails += "</Properties>";
            }

            DwarfContext <T> .GetDatabase().Insert <T, AuditLog>(al);

            return(al);
        }