Esempio n. 1
0
        // Token: 0x060006B3 RID: 1715 RVA: 0x0002A258 File Offset: 0x00028458
        protected int GetActionIdFromActionType(AuditActionType actionType)
        {
            if (AuditingDAL.log.IsDebugEnabled)
            {
                AuditingDAL.log.DebugFormat("GetActionIdFromActionType for {0}", actionType);
            }
            int    result = -1;
            object obj    = this.locker;

            lock (obj)
            {
                if (this.actionTypes.TryGetValue(actionType, out result))
                {
                    return(result);
                }
            }
            if (this.LoadKeys())
            {
                obj = this.locker;
                lock (obj)
                {
                    if (this.actionTypes.TryGetValue(actionType, out result))
                    {
                        return(result);
                    }
                }
            }
            throw new ArgumentException(string.Format("ActionType {0} was not found in dictionary.", actionType));
        }
Esempio n. 2
0
        public void CreateAuditTrail(AuditActionType Action, int KeyFieldID, Object OldObject, Object NewObject)
        {
            // get the differance
            CompareLogic compObjects = new CompareLogic();

            compObjects.Config.MaxDifferences = 99;
            ComparisonResult  compResult = compObjects.Compare(OldObject, NewObject);
            List <AuditDelta> DeltaList  = new List <AuditDelta>();

            foreach (var change in compResult.Differences)
            {
                AuditDelta delta = new AuditDelta();
                if (change.PropertyName.Substring(0, 1) == ".")
                {
                    delta.FieldName = change.PropertyName.Substring(1, change.PropertyName.Length - 1);
                }
                delta.ValueBefore = change.Object1Value;
                delta.ValueAfter  = change.Object2Value;
                DeltaList.Add(delta);
            }
            AuditTable audit = new AuditTable();

            audit.AuditActionTypeENUM = (int)Action;
            audit.DataModel           = this.GetType().Name;
            audit.DateTimeStamp       = DateTime.Now;
            audit.KeyFieldID          = KeyFieldID;
            audit.ValueBefore         = JsonConvert.SerializeObject(OldObject); // if use xml instead of json, can use xml annotation to describe field names etc better
            audit.ValueAfter          = JsonConvert.SerializeObject(NewObject);
            audit.Changes             = JsonConvert.SerializeObject(DeltaList);
            AuditTestEntities ent = new AuditTestEntities();

            ent.AuditTable.Add(audit);
            ent.SaveChanges();
        }
Esempio n. 3
0
 // Token: 0x0600003F RID: 63 RVA: 0x00003C18 File Offset: 0x00001E18
 public IAuditing2 GetAuditingInstancesOfActionType(AuditActionType actionType)
 {
     if (!this.init)
     {
         throw new InvalidOperationException("Object has not been initialized yet. Call Start method before using.");
     }
     Func <AuditActionType, bool> < > 9__0;
     foreach (KeyValuePair <string, IEnumerable <IAuditing2> > keyValuePair in this.cacheTypeInstancesReadOnly)
     {
         foreach (IAuditing2 auditing in keyValuePair.Value)
         {
             if (auditing != null)
             {
                 IEnumerable <AuditActionType> supportedActionTypes = auditing.SupportedActionTypes;
                 Func <AuditActionType, bool>  predicate;
                 if ((predicate = < > 9__0) == null)
                 {
                     predicate = (< > 9__0 = ((AuditActionType supportedType) => supportedType == actionType));
                 }
                 if (supportedActionTypes.Any(predicate))
                 {
                     return(auditing);
                 }
             }
         }
     }
     return(null);
 }
 public IAuditing2 GetAuditingInstancesOfActionType(AuditActionType actionType)
 {
     if (!this.init)
     {
         throw new InvalidOperationException("Object has not been initialized yet. Call Start method before using.");
     }
     using (Dictionary <string, IEnumerable <IAuditing2> > .Enumerator enumerator1 = this.cacheTypeInstancesReadOnly.GetEnumerator())
     {
         while (enumerator1.MoveNext())
         {
             using (IEnumerator <IAuditing2> enumerator2 = enumerator1.Current.Value.GetEnumerator())
             {
                 while (((IEnumerator)enumerator2).MoveNext())
                 {
                     IAuditing2 current = enumerator2.Current;
                     if (current != null && ((IAuditing)current).get_SupportedActionTypes().Any <AuditActionType>((Func <AuditActionType, bool>)(supportedType => AuditActionType.op_Equality(supportedType, actionType))))
                     {
                         return(current);
                     }
                 }
             }
         }
     }
     return((IAuditing2)null);
 }
Esempio n. 5
0
        protected int GetActionIdFromActionType(AuditActionType actionType)
        {
            if (AuditingDAL.log.get_IsDebugEnabled())
            {
                AuditingDAL.log.DebugFormat("GetActionIdFromActionType for {0}", (object)actionType);
            }
            int num = -1;

            lock (this.locker)
            {
                if (this.actionTypes.TryGetValue(actionType, out num))
                {
                    return(num);
                }
            }
            if (this.LoadKeys())
            {
                lock (this.locker)
                {
                    if (this.actionTypes.TryGetValue(actionType, out num))
                    {
                        return(num);
                    }
                }
            }
            throw new ArgumentException(string.Format("ActionType {0} was not found in dictionary.", (object)actionType));
        }
Esempio n. 6
0
 /// <summary>
 /// Create an Audit entity to store the current state of this entity
 /// This happens during a change (aka action)
 /// </summary>
 /// <param name="userId">the user requesting the action</param>
 /// <param name="timestamp">date/time of action</param>
 /// <param name="action">the type of action</param>
 /// <returns>an Audit entity</returns>
 public Audit ToAuditEntity(long userId, long timestamp, AuditActionType action)
 {
     return(new Audit
     {
         UserId = userId,
         EntityId = Id,
         Action = action,
         Timestamp = timestamp,
         SerializedEntity = Serialization.Serialize(this)
     });
 }
Esempio n. 7
0
        private void InsertNewLog(IUnitOfWork uow, Row row, Row oldRow, AuditActionType auditActionType)
        {
            try
            {
                using (var auditLogConnection = SqlConnections.NewFor <AuditLogRow>())
                {
                    var fld = AuditLogRow.Fields;

                    var entityId = (row as IIdRow).IdField[row] ?? 0;

                    var lastVersion = auditLogConnection.TryFirst <AuditLogRow>(q => q
                                                                                .Select(fld.VersionNo, fld.NewEntity)
                                                                                .Where(fld.EntityTableName == row.Table && fld.EntityId == entityId)
                                                                                .OrderBy(fld.Id, desc: true));

                    //we don't want to serialize id field
                    var pkField = (oldRow as IIdRow)?.IdField as Field;
                    if (!(pkField is null))
                    {
                        oldRow.ClearAssignment(pkField);
                    }

                    var oldrowJson = JsonConvert.SerializeObject(oldRow);
                    var rowJson    = JsonConvert.SerializeObject(row);

                    if (auditActionType == AuditActionType.Delete || lastVersion?.NewEntity != rowJson)
                    {
                        int versionNo = (lastVersion?.VersionNo ?? 0) + 1;

                        var auditLogRow = new AuditLogRow
                        {
                            VersionNo       = versionNo,
                            UserId          = int.Parse(Authorization.UserId),
                            ActionType      = auditActionType,
                            ActionDate      = DateTime.Now,
                            EntityTableName = row.Table,
                            EntityId        = entityId,
                            OldEntity       = oldrowJson,
                            NewEntity       = rowJson,
                            IpAddress       = HttpContext.Current.Request.UserHostAddress,
                            SessionId       = HttpContext.Current.Session.SessionID
                        };

                        auditLogConnection.Insert <AuditLogRow>(auditLogRow);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug("_Ext.AuditLog Failed.", ex, row.GetType());
            }
        }
Esempio n. 8
0
        private void InsertNewLog(Row row, Row oldRow, AuditActionType auditActionType)
        {
            try
            {
                // Open database (or create if doesn't exist)

                var constr = ConfigurationManager.ConnectionStrings["LogLiteDB"].ConnectionString;
                if (String.IsNullOrWhiteSpace(constr))
                {
                    return;
                }
                using (var db = new LiteDatabase(constr))
                {
                    var collectionName = row.Table.Replace('.', '_');
                    var collections    = db.GetCollection <VersionInfo>(collectionName);

                    var entityId         = (row as IIdRow).IdField[row] ?? 0;
                    var previousVersions = collections.Find(x => x.EntityId == entityId);

                    var lastVersion = previousVersions?.OrderBy(o => o.VersionNo).LastOrDefault();

                    //var jsonSerializerSettings = new JsonSerializerSettings
                    //{
                    //    ContractResolver = new DynamicContractResolver("IDate", "IUser", "EDate", "EUser")
                    //};

                    var rowJson    = JsonConvert.SerializeObject(row);    //, jsonSerializerSettings);
                    var oldrowJson = JsonConvert.SerializeObject(oldRow); //, jsonSerializerSettings);

                    if (auditActionType == AuditActionType.Delete || lastVersion?.Entity != rowJson)
                    {
                        int versionNo = previousVersions?.Count() ?? 0;

                        var versionInfo = new VersionInfo
                        {
                            VersionNo       = versionNo,
                            VersionDate     = DateTime.Now,
                            UserId          = Authorization.UserId,
                            AuditActionType = auditActionType,
                            ChangeViaUrl    = GetPageUrl(),
                            EntityId        = entityId,
                            OldEntity       = oldrowJson,
                            Entity          = rowJson
                        };

                        collections.Insert(versionInfo);
                    }
                }
            }
            catch { }
        }
        private void InsertNewLog(IUnitOfWork uow, Row row, Row oldRow, AuditActionType auditActionType)
        {
            try
            {
                using (var auditLogConnection = SqlConnections.NewFor <AuditLogRow>())
                {
                    var fld = AuditLogRow.Fields;

                    var entityId = (row as IIdRow).IdField[row] ?? 0;

                    var lastVersion = auditLogConnection.TryFirst <AuditLogRow>(q => q
                                                                                .Select(fld.VersionNo, fld.NewEntity)
                                                                                .Where(fld.EntityTableName == row.Table && fld.EntityId == entityId)
                                                                                .OrderBy(fld.Id, desc: true));

                    //var jsonSerializerSettings = new JsonSerializerSettings
                    //{
                    //    ContractResolver = new DynamicContractResolver("IDate", "IUser", "EDate", "EUser")
                    //};

                    var rowJson    = JsonConvert.SerializeObject(row);    //, jsonSerializerSettings);
                    var oldrowJson = JsonConvert.SerializeObject(oldRow); //, jsonSerializerSettings);

                    if (auditActionType == AuditActionType.Delete || lastVersion?.NewEntity != rowJson)
                    {
                        int versionNo = (lastVersion?.VersionNo ?? 0) + 1;

                        var auditLogRow = new AuditLogRow
                        {
                            VersionNo       = versionNo,
                            UserId          = int.Parse(Authorization.UserId),
                            ActionType      = auditActionType,
                            ActionDate      = DateTime.Now,
                            EntityTableName = row.Table,
                            EntityId        = entityId,
                            OldEntity       = oldrowJson,
                            NewEntity       = rowJson,
                            IpAddress       = HttpContext.Current.Request.UserHostAddress,
                            SessionId       = HttpContext.Current.Session.SessionID
                        };

                        auditLogConnection.Insert <AuditLogRow>(auditLogRow);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug("_Ext.AuditLog Failed.", ex, row.GetType());
            }
        }
Esempio n. 10
0
        public void AuditObjectModification(object entity, object id, AuditActionType auditActionType)
        {
            if (entity is Audit) return;

            var audit = new Audit
            {
                AuditDate = DateTime.UtcNow.ToPacificTime(),
                ObjectName = entity.GetType().Name,
                ObjectId = id == null ? null : id.ToString(),
                Username = string.IsNullOrEmpty(Principal.Identity.Name) ? "NoUser" : Principal.Identity.Name
            };

            audit.SetActionCode(auditActionType);

            AuditRepository.EnsurePersistent(audit, false /*Do not force save*/, false /*Do not flush changes since we are in the middle of other actions*/);
        }
Esempio n. 11
0
        public void AuditObjectModification(object entity, object id, AuditActionType auditActionType)
        {
            if (entity is Audit)
            {
                return;
            }

            var audit = new Audit
            {
                AuditDate  = DateTime.UtcNow.ToPacificTime(),
                ObjectName = entity.GetType().Name,
                ObjectId   = id == null ? null : id.ToString(),
                Username   = string.IsNullOrEmpty(Principal.Identity.Name) ? "NoUser" : Principal.Identity.Name
            };

            audit.SetActionCode(auditActionType);

            AuditRepository.EnsurePersistent(audit, false /*Do not force save*/, false /*Do not flush changes since we are in the middle of other actions*/);
        }
Esempio n. 12
0
        public virtual void SetActionCode(AuditActionType auditActionType)
        {
            switch (auditActionType)
            {
            case AuditActionType.Create:
                AuditAction = "C";
                break;

            case AuditActionType.Update:
                AuditAction = "U";
                break;

            case AuditActionType.Delete:
                AuditAction = "D";
                break;

            default:
                throw new ArgumentOutOfRangeException("auditActionType");
            }
        }
        } // constructor

        /// <summary>
        /// Create a new Audit, comparing two objects of any class type.
        /// </summary>
        /// <param name="auditActionType"></param>
        /// <param name="keyFieldID"></param>
        /// <param name="oldObject"></param>
        /// <param name="newObject"></param>
        public bool CreateAuditTrail(int auditActionType, string keyFieldID, Object oldObject, Object newObject, bool boolCompareChildren = false)
        {
            // get the differance
            var compareLogic = new CompareLogic();

            compareLogic.Config.MaxDifferences  = Int32.MaxValue;
            compareLogic.Config.CompareChildren = boolCompareChildren;

            // This generates the deltas:
            ComparisonResult compResult = compareLogic.Compare(oldObject, newObject);

            var changes = new List <AuditDelta>();

            // remove "." in front of field/property names and add deltas to our list:
            foreach (var change in compResult.Differences)
            {
                var delta = new AuditDelta();
                delta.FieldName = change.PropertyName.Substring(0, 1) != "."
                    ? change.PropertyName
                    : change.PropertyName.Substring(1, change.PropertyName.Length - 1);
                delta.ValueBefore = change.Object1Value;
                delta.ValueAfter  = change.Object2Value;
                changes.Add(delta);
            }

            // Set values to save:
            Action = auditActionType;
            AuditActionTypeName = AuditActionType.GetTypeName(auditActionType);
            KeyFieldID          = keyFieldID;
            var split = oldObject.GetType().ToString().Split('.');

            DataModel = split[split.Length - 1];
            Deltas    = JsonConvert.SerializeObject(changes);//compResult.DifferencesString;//

            // Save to database after creating the audit trail

            return(compResult.AreEqual);
        } // CreateAuditTrail
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WorkspaceAuditGridModel" /> class.
 /// </summary>
 /// <param name="id">id.</param>
 /// <param name="objectName">objectName.</param>
 /// <param name="objectUrl">objectUrl.</param>
 /// <param name="objectType">objectType.</param>
 /// <param name="initiatedBy">initiatedBy.</param>
 /// <param name="initiatedByDisplayName">initiatedByDisplayName.</param>
 /// <param name="activity">activity.</param>
 /// <param name="actionTime">actionTime.</param>
 /// <param name="status">status.</param>
 public WorkspaceAuditGridModel(Guid id = default(Guid), string objectName = default(string), string objectUrl = default(string), AuditObjectType objectType = default(AuditObjectType), string initiatedBy = default(string), string initiatedByDisplayName = default(string), AuditActionType activity = default(AuditActionType), DateTime actionTime = default(DateTime), AutoImportPhase status = default(AutoImportPhase))
 {
     this.Id                     = id;
     this.ObjectName             = objectName;
     this.ObjectUrl              = objectUrl;
     this.ObjectType             = objectType;
     this.InitiatedBy            = initiatedBy;
     this.InitiatedByDisplayName = initiatedByDisplayName;
     this.Activity               = activity;
     this.ActionTime             = actionTime;
     this.Status                 = status;
 }
Esempio n. 15
0
        /// <inheritdoc/>
        public async Task AddAuditEntryForRequest(HttpRequest request, BaseResponse response, AuditActionType type)
        {
            await this._databaseContext.AuditingActions.AddAsync(new AuditingActions
            {
                Result = response.Ok() ? AuditActionResult.Passed : AuditActionResult.Failed,
                Source = request.HttpContext.Connection.RemoteIpAddress?.ToString(),
                Type   = type,
            }).ConfigureAwait(false);

            await this._databaseContext.SaveChangesAsync().ConfigureAwait(false);
        }