Пример #1
0
        public Task AddLogEntry <T>(AuditLogTypes type, T logData, CancellationToken token)
        {
            var datetime = DateTime.UtcNow;
            var logEntry = new AuditLogEntry <T>(logData, type, datetime);

            return(_client.IndexAsync(new IndexRequest <AuditLogEntry <T> >(
                                          logEntry, BuildIndexName(datetime)), token));
        }
Пример #2
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);
        }
Пример #3
0
        private void CreateAuditLog(AuditLogTypes auditLogType, IEnumerable <AuditLogEventTrace> propertyTraces)
        {
            if (DbContextHelper <T> .DbContext.IsAuditLoggingSuspended || DwarfContext <T> .GetConfiguration().AuditLogService == null)
            {
                return;
            }

            if (auditLogType == AuditLogTypes.Updated)
            {
                var traces = propertyTraces.Union(CreateTraceEventsForManyToMany()).ToArray();

                if (traces.Length > 0)
                {
                    DwarfContext <T> .GetConfiguration().AuditLogService.Logg(this, auditLogType, traces);
                }
            }
            else if (auditLogType == AuditLogTypes.Created)
            {
                DwarfContext <T> .GetConfiguration().AuditLogService.Logg(this, auditLogType);
            }
        }
Пример #4
0
        public string GetAuditLogTypeString(AuditLogTypes logType)
        {
            switch (logType)
            {
            case AuditLogTypes.DepartmentSettingsChanged:
                return("Department Settings Changed");

            case AuditLogTypes.UserAdded:
                return("User Added");

            case AuditLogTypes.UserRemoved:
                return("User Removed");

            case AuditLogTypes.GroupAdded:
                return("Group Added");

            case AuditLogTypes.GroupRemoved:
                return("Group Removed");

            case AuditLogTypes.GroupChanged:
                return("Group Changed");

            case AuditLogTypes.UnitAdded:
                return("Unit Added");

            case AuditLogTypes.UnitRemoved:
                return("Unit Removed");

            case AuditLogTypes.UnitChanged:
                return("Unit Changed");

            case AuditLogTypes.ProfileUpdated:
                return("Profile Updated");

            case AuditLogTypes.PermissionsChanged:
                return("Permissions Changed");
            }

            return("");
        }
Пример #5
0
 /// <summary>
 /// Stores an AuditLog object for the ongoing transaction
 /// </summary>
 public static IAuditLog Logg <T>(IDwarf obj, AuditLogTypes auditLogType)
 {
     return(Logg <T>(obj, auditLogType, new AuditLogEventTrace[] { }));
 }
Пример #6
0
 /// <summary>
 /// See base
 /// </summary>
 public IAuditLog Logg(IDwarf obj, AuditLogTypes auditLogType, params AuditLogEventTrace[] auditLogEventTraces)
 {
     return(AuditLog.Logg <T>(obj, auditLogType, auditLogEventTraces));
 }
Пример #7
0
 /// <summary>
 /// See base
 /// </summary>
 public IAuditLog Logg(IDwarf obj, AuditLogTypes auditLogType)
 {
     return(AuditLog.Logg <T>(obj, auditLogType));
 }