public virtual void OnPostInsert(PostInsertEvent e)
 {
     if (used)
     {
         ProcessWork(e.Entity, e.Id, WorkType.Add, e);
     }
 }
        public void OnPostInsert(PostInsertEvent e)
        {
            if ( Params.SkipTrakingList.Contains(e.Entity.GetType().FullName)
                || e.Entity.GetType().Name.Equals("AuditRegister"))
                return;

            foreach (var p in e.Entity.GetType().GetProperties())
            {
                var aud = new AuditRegister()
                {

                    ColumnName = p.Name,
                    ContextId = long.Parse(e.Id.ToString()),
                    NewValue = p.GetValue(e.Entity) == null ? string.Empty : p.GetValue(e.Entity).ToString(),
                    OperationDate = DateTime.Now,
                    OperationType = AuditOperationType.Insert,
                    ColumnTitle = AnnotationsAttributes.GetPropertyTitle(e.Entity.GetType(), p.Name),
                    ContextUser = GetUsuarioLogado(),
                    ObjectName = AnnotationsAttributes.GetClassTitle(e.Entity.GetType())
                };

                e.Session.Save(aud);
            }

            return;
        }
        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();
            }
        }
Example #4
0
 public void OnPostInsert(PostInsertEvent @event)
 {
     var persistableObject = @event.Entity as IPersistableObject;
     persistableObject.OnInserted();
     //if (persistableObject != null)
     //{
     //    persistableObject.SysState = EntityStateEnum.Unchanged;
     //}
 }
        /// <summary>
        /// The on post insert.
        /// </summary>
        /// <param name="event">
        /// The event.
        /// </param>
        public void OnPostInsert(PostInsertEvent @event)
        {
            if (!(@event.Entity is IEntity))
            {
                return;
            }

            var domainEvent = CreateDomainEvent(typeof(EntityInsertedEvent<>), @event.Entity);
            DomainEvents.Raise(domainEvent);
        }
Example #6
0
		public void OnPostInsert(PostInsertEvent @event)
		{
			IAuditor auditor;
			auditors.TryGetValue(@event.Persister.EntityName, out auditor);
			if (auditor == null)
			{
				return;
			}
			auditor.Inserted(@event);
		}
Example #7
0
        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));
            }
        }
Example #8
0
        public void OnPostInsert(PostInsertEvent @event)
        {
            if (@event.Entity is ISearchable == false)
                return;

            using (var session = sessionFactory.OpenSession())
            {
                session.FlushMode = FlushMode.Never;
                var entity = session.Get(@event.Entity.GetType(), ((ISearchable) @event.Entity).Id);
                Indexer.WriteChangesToLucene((ISearchable)entity);
            }
        }
Example #9
0
        public virtual void OnPostInsert(PostInsertEvent evt)
        {
            var entityName = evt.Persister.EntityName;
            if (!VerCfg.EntCfg.IsVersioned(entityName)) return;

            var auditProcess = VerCfg.AuditProcessManager.Get(evt.Session);
            var workUnit = new AddWorkUnit(evt.Session, evt.Persister.EntityName, VerCfg,
                                                                        evt.Id, evt.Persister, evt.State);
            auditProcess.AddWorkUnit(workUnit);
            if (workUnit.ContainsWork())
            {
                GenerateBidirectionalCollectionChangeWorkUnits(auditProcess, evt.Persister, entityName, evt.State,
                                                                        null, evt.Session);
            }
        }
Example #10
0
        public void OnPostInsert(PostInsertEvent @event)
        {
            if (!(@event.Entity is Entity))
                return;

            var session = @event.Session.GetSession(EntityMode.Poco);
            var entityName = @event.Entity.GetType().Name;
            var propertyNames = @event.Persister.EntityMetamodel.PropertyNames;
            var before = string.Empty;
            var after = Serialize(propertyNames, @event.State);

            Log.Debug(after);

            AuditEvent(session, @event.Id, "INSERT", entityName, before, after);
        }
        public void OnPostInsert(PostInsertEvent @event)
        {
            LogHelper.TraceIfEnabled<NhEventListeners>("OnPostInsert for '{0}' with id '{1}'",
                                                     () => @event.Entity.GetType().Name, () => @event.Id);

            var referenceByGuid = @event.Entity as IReferenceByGuid;
            if (referenceByGuid == null)
            {
                LogHelper.TraceIfEnabled<NhEventListeners>("Not raising event because casting entity to IReferenceByGuid resulted in null value");
                return;
            }

            //if (NodeIdAvailable != null) NodeIdAvailable(referenceByGuid, (Guid)@event.Id);
            OnNodeIdAvailable(referenceByGuid, (Guid)@event.Id);
        }
Example #12
0
        public void OnPostInsert(PostInsertEvent @event)
        {
            LogHelper.TraceIfEnabled<NhEventListeners>("OnPostInsert for '{0}' with id '{1}'",
                                                     () => @event.Entity.GetType().Name, () => @event.Id);

            AggregateDataInterceptor.CheckNodeVersionId(@event.Entity, EnsureVersionIdsInitialised());

            var referenceByGuid = @event.Entity as IReferenceByGuid;
            if (referenceByGuid == null)
            {
                LogHelper.TraceIfEnabled<NhEventListeners>("Not raising event because casting entity to IReferenceByGuid resulted in null value");
                return;
            }

            //if (NodeIdAvailable != null) NodeIdAvailable(referenceByGuid, (Guid)@event.Id);
            OnNodeIdAvailable(referenceByGuid, (Guid)@event.Id);
        }
        public void OnPostInsert(PostInsertEvent @event)
        {
            if (@event.Entity is Audit)
            {
                return;
            }

            if (@event.Entity is IAuditable)
            {

                var auditableEntity = @event.Entity as IAuditable;
                var entityId = @event.Id.ToString();
                var entityFullName = @event.Entity.GetType().FullName;
                var propertyNames = @event.Persister.PropertyNames;
                var now = DateTime.Now;
                var updateId = Guid.NewGuid();

                for (int i = 0; i < propertyNames.Length; i++)
                {
                    var propertyDetails = GetPropertyDetails(@event, i);

                    if (auditableEntity.CreatedBy == null)
                    {
                        throw new AuditInsertCreatedByNotSetExceptions(entityFullName, entityId);
                    }

                    AddRecord(
                        "I",
                        entityFullName,
                        entityId,
                        propertyDetails.PropertyName,
                        NoValueString,
                        propertyDetails.PropertyValue,
                        now,
                        auditableEntity.CreatedBy.Id.ToString(),
                        updateId);

                }
            }
        }
Example #14
0
        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 void OnPostInsert(PostInsertEvent @event)
        {
            System.Diagnostics.Debug.WriteLine("*** OnPostInsert Start ***");

            var product = @event.Entity as SampleSolrApp.Models.Nh.Product;
            if (product != null)
            {
                var productWriter = StructureMap.ObjectFactory.GetInstance<SolrNet.ISolrOperations<SampleSolrApp.Models.Nh.Product>>();
                productWriter.Add(product);
                productWriter.Commit();
                System.Diagnostics.Debug.WriteLine("*** Product inserted and commited ***");
            }

            var manufacturer = @event.Entity as SampleSolrApp.Models.Nh.Manufacturer;
            if (manufacturer != null)
            {
                var manufacturerWriter = StructureMap.ObjectFactory.GetInstance<SolrNet.ISolrOperations<SampleSolrApp.Models.Nh.Manufacturer>>();
                manufacturerWriter.Add(manufacturer);
                manufacturerWriter.Commit();
                System.Diagnostics.Debug.WriteLine("*** Manufacturer inserted and commited ***");
            }

            System.Diagnostics.Debug.WriteLine("*** OnPostInsert End ***");
        }
        public void OnPostInsert(PostInsertEvent @event)
        {
            AuditLogItem ali = AuditLogItem.Find(@event.Entity.GetType());
            if ((ali.AuditLogAction & PPWAuditLogActionEnum.CREATE) == PPWAuditLogActionEnum.CREATE)
            {
                string identityName = IdentityNameHelper.GetIdentityName();
                DateTime now = DateTime.Now;
                string entityName = @event.Entity.GetType().Name;

                List<AuditLog> logs = new List<AuditLog>();
                int length = @event.State.Count();
                for (int fi = 0; fi < length; fi++)
                {
                    string newValue = GetStringValueFromStateArray(@event.State, fi);

                    string propertyName = @event.Persister.PropertyNames[fi];
                    PPWAuditLogActionEnum auditLogAction;
                    if (ali.Properties.TryGetValue(propertyName, out auditLogAction))
                    {
                        if ((auditLogAction & PPWAuditLogActionEnum.CREATE) == PPWAuditLogActionEnum.NONE)
                        {
                            logs.Add(new AuditLog
                            {
                                EntryType = "I",
                                EntityName = entityName,
                                EntityId = (long?)@event.Id,
                                PropertyName = propertyName,
                                OldValue = null,
                                NewValue = newValue,
                                CreatedBy = identityName,
                                CreatedAt = now,
                            });
                        }
                    }
                }
                if (logs.Count > 0)
                {
                    using (ISession session = @event.Session.GetSession(EntityMode.Poco))
                    {
                        logs.ForEach(o => session.Save(o));
                        session.Flush();
                    }
                }
            }
        }
 /// <summary>
 /// Called when [post insert].
 /// </summary>
 /// <param name="event">The @event.</param>
 public void OnPostInsert( PostInsertEvent @event )
 {
     AuditPatientAccess (
         @event.Entity, @event, PatientAccessEventType.InsertEvent, () => GetAuditNoteForEntity(@event.Entity));
 }
 public void OnPostInsert(PostInsertEvent @event) {
     throw new NotImplementedException();
 }
		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 void OnPostInsert(PostInsertEvent @event)
 {
     RaiseOnSave(@event.Entity);
 }
 public void OnPostInsert(PostInsertEvent ev)
 {
     DispatchEvents(ev.Entity as AggregateRoot);
 }
 public abstract void Inserted(PostInsertEvent eventArgs);
 public void OnPostInsert(PostInsertEvent insertEvent)
 {
     OutputCacheManager.EntityChanged(insertEvent.Entity);
 }
        private static PropertyDetails GetPropertyDetails(PostInsertEvent @event, int propertyIndex)
        {
            var result = new PropertyDetails
                             {
                                 PropertyName = @event.Persister.PropertyNames[propertyIndex]
                             };

            var newValue = @event.Persister.GetPropertyValue(@event.Entity, result.PropertyName, EntityMode.Poco);
            if (newValue == null || newValue.ToString() == string.Empty)
            {
                result.PropertyValue = NoValueString;
                return result;
            }

            if (newValue is IAuditable)
            {
                result.PropertyName = result.PropertyName + "Id";
                result.PropertyValue = (newValue as IAuditable).IdForAuditing;
                return result;
            }

            // Are we a collection if so then get all the values
            var collectionType = GetItemTypeFromGenericType(newValue.GetType());
            if (collectionType != null)
            {
                var isAuiditable =
                  collectionType.GetInterfaces().AsEnumerable().Count(x => x.Name == typeof(IAuditable).Name) == 1;
                
                if(isAuiditable)
                {
                    var collectionValues = newValue as IEnumerable;
                    foreach (var collectionValue in collectionValues)
                    {
                        var item = collectionValue as IAuditable;
                        if (result.PropertyValue != null && result.PropertyValue.Length > 0)
                        {
                            result.PropertyValue += ", ";
                        }
                        result.PropertyValue += item.IdForAuditing;
                    }
                    return result;    
                }
                
            }
            
            result.PropertyValue = newValue.ToString();
            return result;
        }
 public void OnPostInsert(PostInsertEvent @event)
 {
     Called = true;
 }
 public void OnPostInsert(PostInsertEvent @event)
 {
 }
		private void PostInsert()
		{
			if (isDelayed)
			{
				Session.PersistenceContext.ReplaceDelayedEntityIdentityInsertKeys(delayedEntityKey, generatedId);
			}
			IPostInsertEventListener[] postListeners = Session.Listeners.PostInsertEventListeners;
			if (postListeners.Length > 0)
			{
				PostInsertEvent postEvent = new PostInsertEvent(Instance, generatedId, state, Persister, (IEventSource)Session);
				foreach (IPostInsertEventListener listener in postListeners)
				{
					listener.OnPostInsert(postEvent);
				}
			}
		}
 public void OnPostInsert(PostInsertEvent @event)
 {
     var entity = @event.Entity as EntityBase;
     return;
 }
Example #29
0
 public void OnPostInsert(PostInsertEvent @event)
 {
     Debug.WriteLine("EventListener.OnPostInsert: {0}", @event.Id);
 }
Example #30
0
        public void OnPostInsert(PostInsertEvent @event)
        {
            var entity = default(Term);

            if (@event.TryCatchEntity(ref entity))
            {
                var statelessSession = @event.Persister.Factory.OpenStatelessSession();

                var log = new TermLog
                              {
                                  SourceId = entity.Id,
                                  EmployeeId = entity.GetSnapshotValue<Guid>("EmployeeId"),
                                  Action = "I",
                                  Type = entity.GetType().Name,
                                  Name = entity.Text,
                                  Category = _alterWay,
                                  OldTime = null,
                                  NewTime = FormatTime(entity.Start, entity.End),
                                  Remark = _batchAlteringComments
                              };

                SaveLog(statelessSession, log);
            }
        }