public bool OnPreUpdate(PreUpdateEvent e) { var auditable = e.Entity as IAuditableEntity; if (auditable == null) return false; var logger = ServiceLocator.TryGetInstance<IAuditableEntityLogger>(); if (logger != null) { var changedPropertiesIdx = e.Persister.FindDirty(e.State, e.OldState, e.Entity, e.Session.GetSessionImplementation()); foreach (var idx in changedPropertiesIdx) { var tableName = e.Persister.EntityName; var propertyName = e.Persister.PropertyNames[idx]; var oldValue = e.OldState[idx]; var newValue = e.State[idx]; logger.Log(tableName, propertyName, oldValue, newValue); } } var name = (ApplicationContext.User != null && !string.IsNullOrEmpty(ApplicationContext.User.Identity.Name)) ? ApplicationContext.User.Identity.Name : "Unknown"; var date = DateTime.UtcNow; Set(e.Persister, e.State, "UpdatedBy", name); Set(e.Persister, e.State, "UpdatedAt", date); auditable.UpdatedBy = name; auditable.UpdatedAt = date; return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { if (@event.Entity is Log) throw new InvalidOperationException("You cannot modify logs, they are immutable!"); var sb = new StringBuilder("Updating " + @event.Persister.EntityName + " " + @event.Id) .AppendLine(); for (int i = 0; i < @event.OldState.Length; i++) { if(@event.Persister.PropertyTypes[i] .IsEqual(@event.OldState[i], @event.State[i], @event.Session.EntityMode)) continue; sb.Append("\t") .Append(@event.Persister.PropertyNames[i]) .Append(": ") .Append(@event.OldState[i]) .Append(" -> ") .Append(@event.State[i]) .AppendLine(); } using(var child = @event.Session.GetSession(EntityMode.Poco)) { child.Save(new Log { EntityId = (int) @event.Id, Entity = @event.Persister.EntityName, Changes = sb.ToString() }); child.Flush(); } return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { SetAuditFields(@event.Entity as IAuditableEntity, "Update"); CommitAuditInfo(@event.Persister, @event.State, "EditDate"); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var auditable = @event.Entity as IAuditableEntity; if (auditable == null) { return false; } string userUniqueId = string.Empty; var user = ApplicationContext.User; if (user != null) { var identity = ApplicationContext.User.Identity as ICoreIdentity; if (identity != null) { userUniqueId = identity.Id; } } DateTime updatedAt = DateTime.Now; this.Set(@event.Persister, @event.State, "UpdatedBy", userUniqueId); this.Set(@event.Persister, @event.State, "UpdatedAt", updatedAt); auditable.UpdatedBy = userUniqueId; auditable.UpdatedAt = updatedAt; return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { if (@event.Entity == null || @event.Session.EntityMode != EntityMode.Poco) return false; /*simple validation*/ if (@event.Entity as Person != null) { var person = (Person) @event.Entity; if (person.Partner != null && person.Partner.Id != Guid.Empty) Log.Info("Person does not have a partner"); } if (@event.Entity as Cat != null) { var cat = (Cat)@event.Entity; { Log.Info(string.Format("Cat {0} has Master Id {1}", cat.Name, cat.Master.Id)); } } if (@event.Entity as Toy != null) { var toy = (Toy)@event.Entity; { Child xChild; using(var newSession = @event.Session.SessionFactory.OpenSession()) { xChild = newSession.Get<Child>(toy.Owner.Id); } Log.Info(string.Format("Toy {0} has Owner {1}", toy.Name,xChild.Name)); } } return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { using (var childSession = @event.Session.GetSession(EntityMode.Poco)) { for (var i = 0; i < @event.Persister.PropertyNames.Length; i++) { if(@event.Persister.VersionProperty == i) continue; var propName = @event.Persister.PropertyNames[i]; IType propertyType = @event.Persister.PropertyTypes[i]; var same = propertyType.IsEqual(@event.OldState[i], @event.State[i], EntityMode.Poco); if (same) continue; var changeEvent = new ChangeEvent { EntityName = @event.Persister.EntityName, EntityId = (int)@event.Id, NewValue = (@event.State[i] ?? "null").ToString(), OldValue = (@event.OldState[i] ?? "null").ToString(), PropertyName = propName }; childSession.Save(changeEvent); } childSession.Flush(); } return false; }
public bool OnPreUpdate(PreUpdateEvent e) { var auditable = e.Entity as IAuditable; if (auditable == null) return false; var time = DateTime.UtcNow; SetState(e.Persister, e.State, "Updated", time); auditable.Updated = time; return false; }
public bool OnPreUpdate(PreUpdateEvent updateEvent) { var rootFinder = updateEvent.Entity as ICanFindMyAggregateRoot; if (rootFinder == null) return false; updateEvent.Session.Lock(rootFinder.MyRoot, LockMode.Force); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var c = @event.Entity as IAuditInfo; if (c == null) return false; c.UpdatedBy = sUsernameProvider.Username; Set(@event.Persister, @event.State, "UpdatedBy", c.UpdatedBy); c.UpdatedOn = DateTime.Now; Set(@event.Persister, @event.State, "UpdatedOn", c.UpdatedOn); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var entity = @event.Entity as EntityBase; if (entity == null) return false; entity.IsDeleted = false; entity.UpdatedAt = DateTime.Now; Set(@event.Persister, @event.State, "UpdatedAt", entity.UpdatedAt); return false; }
/// <summary> /// 엔티티를 Update 하기 전에, 엔티티의 UpdateTimestamp 속성 값을 현재 시각으로 설정합니다. /// </summary> /// <param name="event"></param> /// <returns></returns> public bool OnPreUpdate(PreUpdateEvent @event) { if(IsDebugEnabled) log.Debug("엔티티에 대해 PreUpdateEvent를 수행합니다..."); var entity = @event.Entity as IUpdateTimestampedEntity; if(entity != null) entity.UpdateTimestamp = GetCurrentTime(); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var auditableEntity = @event.Entity as IEntityWithAuditing; if (auditableEntity == null) return false; auditableEntity.AuditingInfo.UpdatedBy = "Someone else"; auditableEntity.AuditingInfo.UpdatedOn = DateTime.Now; Set(@event.Persister, @event.State, "AuditingInfo", auditableEntity.AuditingInfo); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var auditable = @event.Entity as IAuditableEntity; if (auditable == null) { return false; } string userUniqueId = string.Empty; var user = ApplicationContext.User; if (user != null) { var identity = ApplicationContext.User.Identity as ICoreIdentity; if (identity != null) { userUniqueId = identity.Id; } } DateTime updatedAt = DateTime.Now; var auditTrailFactory = ServiceLocator.TryGetInstance<IAuditTrailFactory>(); if (auditTrailFactory != null && auditTrailFactory.IsEntityRegistered(@event.Persister.EntityName)) { string tableName = @event.Persister.EntityName; int[] changedPropertiesIdx = @event.Persister.FindDirty(@event.State, @event.OldState, @event.Entity, @event.Session.GetSessionImplementation()); Guid changeSetUniqueId = GuidExtensions.NewCombGuid(); foreach (int idx in changedPropertiesIdx) { string propertyName = @event.Persister.PropertyNames[idx]; object oldValue = @event.OldState[idx]; object newValue = @event.State[idx]; IEntityAuditTrail auditTrail = auditTrailFactory.CreateAuditTrail(changeSetUniqueId, tableName, @event.Id.ToString(), propertyName, oldValue, newValue, userUniqueId, updatedAt); @event.Session.Save(auditTrail); } } this._Set(@event.Persister, @event.State, "UpdatedBy", userUniqueId); this._Set(@event.Persister, @event.State, "UpdatedAt", updatedAt); auditable.UpdatedBy = userUniqueId; auditable.UpdatedAt = updatedAt; return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { IModel owner = @event.Entity as IModel; if (owner == null || @event.Session.EntityMode != EntityMode.Poco) { return false; } Validate(owner); return false; }
/// <summary> /// Return true if the operation should be vetoed /// </summary> /// <param name="event"/> public bool OnPreUpdate(PreUpdateEvent @event) { var audit = @event.Entity as Entity; if (audit == null) return false; var time = DateTime.Now; Set(@event.Persister, @event.State, "ModifiedOn", time); audit.ModifiedOn = time; return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { IAuditableModel auditableModel = @event.Entity as IAuditableModel; if (auditableModel == null) return false; auditableModel.UpdatedBy = System.Threading.Thread.CurrentPrincipal.Identity.Name; auditableModel.UpdatedTime = DateTime.Now; Set(@event.Persister, @event.State, "UpdatedTime", auditableModel.UpdatedTime); Set(@event.Persister, @event.State, "UpdatedBy", auditableModel.UpdatedBy); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var timestamped = (@event.Entity as ITimestamped); if (!isValidEntity(timestamped)) return false; if (timestamped.Timestamp == null) timestamped.Timestamp = new Timestamp(); timestamped.Timestamp.Modify(); updateState(@event.Persister, @event.State, "Timestamp", timestamped.Timestamp); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var editedEntity = @event.Entity as IAuditableEntity; if (editedEntity == null) return false; var datAndtime = DateTime.UtcNow; PersistAuditInfo(@event.Persister, @event.State, "EditDate", datAndtime); editedEntity.EditDate = datAndtime; return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var entity = @event.Entity as Entity; if (entity == null) { return false; } Set(@event.Persister, @event.State, @"UpdatedBy", _actor); entity.UpdatedBy = _actor; return false; }
/// <inheritdoc/> public bool OnPreUpdate(PreUpdateEvent @event) { var audit = @event.Entity as IAuditEntity; if (audit == null) return false; var time = DateTime.Now; Set(@event.Persister, @event.State, "Updated", time); Set(@event.Persister, @event.State, "UpdatedBy", CurrentUser); audit.Updated = time; audit.UpdatedBy = CurrentUser; return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { GetAuditProperties(@event.Entity); if (_auditProperties.IsEmpty()) return false; try { var sessionID = new Guid(ConfigurationManager.AppSettings["SessionID"]); var sessionSerice = Locator.Resolve<ISessionService>(); var user = sessionSerice.GetUserAccount(sessionID); SetAuditProperties(@event, @event.Persister, @event.State, user, DateTime.Now); return false; } catch (Exception) { return false; } }
public bool OnPreUpdate(PreUpdateEvent @event) { var baseEntity = @event.Entity as BaseEntity; if (baseEntity != null) { baseEntity.LastEditor = "Leoli_Update_Event"; baseEntity.LastTime = DateTime.Now; this.Set(@event.Persister, @event.State, "LastEditor", baseEntity.LastEditor); this.Set(@event.Persister, @event.State, "LastTime", baseEntity.LastTime); //or //@event.State.SetValue("Leoli_Update_Event", Array.IndexOf(@event.Persister.PropertyNames, "LastEditor")); //@event.State.SetValue(baseEntity.LastTime, Array.IndexOf(@event.Persister.PropertyNames, "LastTime")); } return false; }
/// <summary> /// Return true if the operation should be vetoed /// </summary> /// <param name="event"/> public bool OnPreUpdate(PreUpdateEvent @event) { var entity = @event.Entity as ICreatedAndUpdatedProperty; if (entity == null) return false; var time = DateTime.Now; Set(@event.Persister, @event.State, "Updated", time); entity.Updated = time; if (entity.Created == DateTime.MinValue) entity.Created = time; return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var entity = @event.Entity as Entity; if (entity == null) return false; DateTime time = DateTime.Now; string name = GetUserId(); Set(@event.Persister, @event.State, "UpdatedAt", time); Set(@event.Persister, @event.State, "UpdatedBy", name); entity.UpdatedAt = time; entity.UpdatedBy = name; return false; }
public bool OnPreUpdate(PreUpdateEvent preUpdateEvent) { var audit = preUpdateEvent.Entity as IAuditable; if (audit == null) return false; var time = DateTime.UtcNow; var userid = CurrentUserId(); Set(preUpdateEvent.Persister, preUpdateEvent.State, "ModifiedOnUtc", time); Set(preUpdateEvent.Persister, preUpdateEvent.State, "ModifiedBy", userid); preUpdateEvent.Entity.GetType().GetMethod("ChangeModifiedBy", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(preUpdateEvent.Entity, new object[] { userid }); preUpdateEvent.Entity.GetType().GetMethod("ChangeModifiedOnUtc", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(preUpdateEvent.Entity, new object[] { time }); return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var audit = @event.Entity as IHaveAuditInformation; if (audit == null) return false; var time = DateTime.Now; var name = WindowsIdentity.GetCurrent().Name; Set(@event.Persister, @event.State, "ModifyDate", time); Set(@event.Persister, @event.State, "ModifyUser", name); audit.ModifyDate = time; audit.ModifyUser = name; return false; }
public bool OnPreUpdate(PreUpdateEvent eventItem) { Trip trip = eventItem.Entity as Trip; if (null == trip) { return false; } if (ViolatesTripConstraint(eventItem.Session, trip.Observer.StaffCode, trip.TripNumber, trip.Id)) { throw new Exception("Trip with this staff code/trip number already exists."); } // Mess with Departure/Return dates? return false; }
public bool OnPreUpdate(PreUpdateEvent @event) { var audit = @event.Entity as IHaveAuditInformation; if (audit == null) return false; var time = DateTime.Now; var user = GetUser(); Set(@event.Persister, @event.State, "UpdatedAt", time); Set(@event.Persister, @event.State, "UpdatedBy", user); audit.UpdatedAt = time; audit.UpdatedBy = user; return false; }
public bool OnPreUpdate(PreUpdateEvent e) { if(e.Entity is DomainEntity) { if(e.OldState==null) throw new AuditException(); var dirtyFieldIndexes = e.Persister.FindDirty(e.State, e.OldState, e.Entity, e.Session); if(dirtyFieldIndexes.Length>0) { var entity = e.Entity as DomainEntity; entity.LastUpdatedAt = DateTime.UtcNow; var changeLogs = new List<AuditChangeLog>(); if (e.Entity.GetType().GetInterface(typeof(IAuditable).Name) != null) { foreach (var dirtyFieldIndex in dirtyFieldIndexes) { if (e.OldState[dirtyFieldIndex] == e.State[dirtyFieldIndex]) continue; //insert audit changelog here var changeLog = new AuditChangeLog { EntityType = e.Entity.GetType().Name, EntityIdentifier = entity.Id.ToString(), ActionType = AuditType.Update, PropertyName = e.Persister.PropertyNames[dirtyFieldIndex] }; changeLog.OldPropertyValue = GetPropertyValue(e.OldState[dirtyFieldIndex], changeLog.PropertyName, entity); changeLog.NewPropertyValue = GetPropertyValue(e.State[dirtyFieldIndex], changeLog.PropertyName, entity); changeLogs.Add(changeLog); } IStatelessSession session = e.Session.SessionFactory.OpenStatelessSession(); changeLogs.ForEach(log=>session.Insert(log)); session.Close(); } } } return false; }
public bool OnPreUpdate(PreUpdateEvent event_item) { var audit = event_item.Entity as IAuditable; if (audit == null) { return false; } DateTime? modifiedDate = DateTime.Now; string userIdentity = GetIdentityName(); store(event_item.Persister, event_item.State, "ModifiedDate", modifiedDate); store(event_item.Persister, event_item.State, "ModifiedByUser", userIdentity); audit.ModifiedDate = modifiedDate; audit.ModifiedByUser = userIdentity; return false; }