public void OnPostInsert(PostInsertEvent @event) { var tipo = @event.Entity.GetType(); var entity = @event.Entity; Dispatch(tipo, typeof(ICreatedDataHook <>), entity); }
public void OnPostInsert(IUnitOfWorkTracked uow, PostInsertEvent insertEvent) { if (insertEvent.Entity is IBusinessObject && (insertEvent.Entity as IBusinessObject).UoW == null) { (insertEvent.Entity as IBusinessObject).UoW = (IUnitOfWork)uow; } }
/// <summary> /// Save <see cref="Audit"/> /// </summary> /// <param name="event"><see cref="PreInsertEvent"/></param> internal static void Save(PostInsertEvent @event) { if ([email protected]().GetInterfaces().Contains(typeof(IAuditable))) { return; } var session = @event.Session.GetSession(EntityMode.Poco); var auditClass = AuditClass.Find(session, @event.Entity.GetType().FullName); if (auditClass == null) { return; } var auditable = (IAuditable)@event.Entity; if (string.IsNullOrWhiteSpace(auditable.AuditDescription)) { auditable.AuditDescription = "{0} inserted".With(auditClass.Description); } Save(session, @event.Id.ToString(), auditable.AuditGroupReference, auditClass, AuditType.Insert(), auditable.AuditDescription, auditable.AuditUser); }
public void OnPostInsert(PostInsertEvent insertEvent) { var entity = insertEvent.Entity as IDomainObject; // Мы умеет трекать только объекты реализующие IDomainObject, иначе далее будем падать на получении Id. if (entity == null || !TrackerMain.NeedTrace(entity)) { return; } //FIXME добавлено чтобы не дублировались записи. Потому что от Nhibernate приходит по 2 события на один объект. Если это удастся починить, то этот код не нужен. if (changes.Any(hce => hce.EntityId == entity.Id && NHibernateProxyHelper.GuessClass(entity).Name == hce.EntityClassName)) { return; } var fields = Enumerable.Range(0, insertEvent.State.Length) .Select(i => FieldChange.CheckChange(i, insertEvent)) .Where(x => x != null) .ToList(); if (fields.Count > 0) { changes.Add(new ChangedEntity(EntityChangeOperation.Create, insertEvent.Entity, fields)); } }
public void OnPostInsert(PostInsertEvent @event) { var domainEntity = @event.Entity as DomainObjectBase; if (domainEntity == null) { return; } DateTime createDateValue = Get <DateTime>(@event.Persister, @event.State, "CreateDate"); if (!createDateValue.Equals(default(DateTime))) { domainEntity.CreateDate = createDateValue; } var aggregateRoot = @event.Entity as AggregateRootWithCompositeKey; if (aggregateRoot != null) { // Assign the server-assigned Id back to the aggregate root entity if (aggregateRoot.Id.Equals(Guid.Empty)) { aggregateRoot.Id = Get <Guid>(@event.Persister, @event.State, "Id"); } } }
public void OnPostInsert(PostInsertEvent @event) { //Из-за бага\фичи в Nh, приходят по 2 одинаковых события. if (lastPostInsertEntity == @event.Entity) { return; } lastPostInsertEntity = @event.Entity; IUnitOfWorkTracked uow = GetUnitOfWork(@event.Session); if (uow == null) { logger.Warn("Пришло событие PostInsertEvent но соответствующий сессии UnitOfWork не найден."); return; } lock (PostInsertListeners) { foreach (var listner in PostInsertListeners) { listner.OnPostInsert(uow, @event); } } uow.EventsTracker.OnPostInsert(uow, @event); }
public void OnPostInsert(IUnitOfWorkTracked uow, PostInsertEvent insertEvent) { foreach (var listner in PostInsertListeners) { listner.OnPostInsert(uow, insertEvent); } }
public async Task OnPostInsertAsync(PostInsertEvent @event, CancellationToken cancellationToken) { if (!(@event.Entity is Entity)) { return; } // This guard is necessary to avoid multiple inserts of the original objects. // Commenting this out is likely to cause one PK violation per run, which seems to be capped to at most 10 attempts. // With the guard, only one PK violation is reported. if (_currentlyLogging) { return; } try { _currentlyLogging = true; var session = @event.Session; // this causes an Autoflush long count = await(session.CreateQuery("select count(o) from Entity o").UniqueResultAsync <long>(cancellationToken)); Console.WriteLine("Total entity count: {0}", count); } finally { _currentlyLogging = false; } }
public virtual void OnPostInsert(PostInsertEvent e) { if (used) { ProcessWork(e.Entity, e.Id, WorkType.Add, e); } }
public void OnPostInsert(PostInsertEvent @event) { if (IsEnabled) { var entity = default(Term); if (@event.TryCatchEntity(ref entity)) { var statelessSession = @event.Persister.Factory.OpenStatelessSession(); using (var tx = statelessSession.BeginTransaction()) { var employeeId = entity.GetSnapshotValue <Guid>("EmployeeId"); var backup = new BackupTerm(entity.Id, employeeId, entity.Start, entity.End, entity.Text, entity.Background, entity.Level); if (entity.Bottom != null) { backup.ParentTermId = entity.Bottom.Id; } statelessSession.Insert(backup); tx.Commit(); } } } }
public static IEnumerable <PropertyEntry> ToPropertyEntry( this PostInsertEvent @event) { return(@event.State .Select((t, i) => @event.Persister.PropertyNames[i]) .Select((name, i) => new NHibernatePropertyEntry(name, false, null, @event.State, i))); }
public void OnPostInsert( PostInsertEvent @event) { var properties = @event.ToPropertyEntry().ToList(); Raise(@event, typeof(AfterAddedEntityDomainEvent <>), @event.Entity, properties); }
/// <summary> /// Called when [post insert]. /// </summary> /// <param name="e">The e.</param> /// <returns></returns> public void OnPostInsert(PostInsertEvent e) { if (IsAuditable(e.Entity)) { InsertDeleteAuditLog((Entity <int>)e.Entity, e.Session, AuditType.Insert); } }
public void OnPostInsert(PostInsertEvent evt) { String entityName = evt.Persister.EntityName; if (verCfg.EntCfg.IsVersioned(entityName)) { AuditSync verSync = verCfg.AuditSyncManager.get(evt.Session); IAuditWorkUnit workUnit = new AddWorkUnit(evt.Session, evt.Persister.EntityName, verCfg, evt.Id, evt.Persister, evt.State); verSync.AddWorkUnit(workUnit); if (workUnit.ContainsWork()) { GenerateBidirectionalCollectionChangeWorkUnits(verSync, evt.Persister, entityName, evt.State, null, evt.Session); } //Simon - TODO - Correct/clarify this: // it appears that the AuditSyncManager's transaction.RegisterSynchronization(verSync); // does not lead to calling the verSync's synchronization methods (Before and AfterCompletion // so I will call this manually. The problem that I found is that AdoTransaction's Commit method // is not called at all. Could this be because of Spring.NET? // When corrected, change also in AuditSync the Flush in BeforeCompletion. //verSync.BeforeCompletion(); } }
public void OnPostInsert(PostInsertEvent @event) { if (@event.Entity is Orders) { Orders order = (Orders)@event.Entity; Console.WriteLine($@"Insert - {order.OrderID}"); } }
public EntityChangeEvent(PostInsertEvent insertEvent) { InsertEvent = insertEvent; UpdateEvent = null; DeleteEvent = null; EntityClass = InsertEvent.Persister.MappedClass; Entity = InsertEvent.Entity; }
public void OnPostInsert(PostInsertEvent e) { if (e.Entity is RequirementHeader header) { var number = e.Session.CreateSQLQuery("SELECT NEXT VALUE FOR Seq_Sequence").UniqueResult().ToString(); header.SequenceNumber = int.Parse(number); } }
public async Task OnPostInsertAsync( PostInsertEvent @event, CancellationToken cancellationToken) { var properties = @event.ToPropertyEntry().ToList(); await RaiseAsync(@event, typeof(AfterAddedEntityDomainEvent <>), @event.Entity, properties); }
public static bool TryCatchEntity <T>(this PostInsertEvent @event, ref T entity) { if (@event.Entity is T) { entity = (T)@event.Entity; return(true); } return(false); }
public virtual void OnPostInsert(PostInsertEvent e) { if (!(e.Entity is AccountBase)) { return; } RemoveFromCache((AccountBase)e.Entity); }
public void OnPostInsert(PostInsertEvent @event) { var name = @event.Entity.GetType().Name; if (_authorizationObjects.Any(a => a == name)) { OperationAuthorizationService.InvalidateCache(); } }
public void OnPostInsert(IUnitOfWorkTracked uow, PostInsertEvent insertEvent) { var change = new EntityChangeEvent(insertEvent); foreach (var subscriber in GetSingleSubscribers(change)) { subscriber.Invoke(change); } }
public static IEnumerable <PropertyEntry> ToPropertyEntry( this PostInsertEvent @event) { var entityType = NHibernateUtil.GetClass(@event.Entity); return(@event.State .Select((t, i) => @event.Persister.PropertyNames[i]) .Select((name, i) => new NHibernatePropertyEntry(entityType.GetProperty(@event.Persister.PropertyNames[i]), false, null, @event.State, i))); }
public void OnPostInsert(PostInsertEvent @event) { IAuditor auditor; auditors.TryGetValue(@event.Persister.EntityName, out auditor); if (auditor == null) { return; } auditor.Inserted(@event); }
public void OnPostInsert(PostInsertEvent @event) { var vc = GetVersionedClass(@event); if (vc == null) { return; } var processor = _transactionManager.Get(@event.Session); processor.Add(new InsertWorkUnit(@event, vc)); }
private void PostCommitInsert() { IPostInsertEventListener[] postListeners = Session.Listeners.PostCommitInsertEventListeners; if (postListeners.Length > 0) { var postEvent = new PostInsertEvent(Instance, generatedId, State, Persister, (IEventSource)Session); foreach (IPostInsertEventListener listener in postListeners) { listener.OnPostInsert(postEvent); } } }
public Task OnPostInsertAsync(PostInsertEvent @event, CancellationToken cancellationToken) { if (@event.Entity is Orders) { Orders order = (Orders)@event.Entity; return(Task.Run(() => Console.WriteLine($@"Insert - {order.OrderID}"))); } else { return(Task.Run(() => { })); } }
public void OnPostInsert(PostInsertEvent @event) { IUnitOfWorkEventHandler uow = GetUnitOfWork(@event.Session); if (uow != null) { uow.HibernateTracker?.OnPostInsert(@event); } else { logger.Warn("Пришло событие OnPostUpdate но соответствующий сессии UnitOfWork не найден."); } }
private async Task PostCommitInsertAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); IPostInsertEventListener[] postListeners = Session.Listeners.PostCommitInsertEventListeners; if (postListeners.Length > 0) { var postEvent = new PostInsertEvent(Instance, generatedId, state, Persister, (IEventSource)Session); foreach (IPostInsertEventListener listener in postListeners) { await(listener.OnPostInsertAsync(postEvent, cancellationToken)).ConfigureAwait(false); } } }
public void OnPostInsert(PostInsertEvent @event) { var seat = default(Seat); if (@event.TryCatchEntity(ref seat)) { if (_seatBoxRepository == null) { _seatBoxRepository = ServiceLocator.Current.GetInstance <ISeatBoxRepository>(); } _seatBoxRepository.MakePersistent(new SeatBox(seat)); } }