public Task OnPreUpdateCollectionAsync(PreCollectionUpdateEvent @event, CancellationToken cancellationToken)
        {
            try
            {
                var ownerEntity     = @event.AffectedOwnerOrNull;
                var collectionEntry = @event.Session.PersistenceContext.GetCollectionEntry(@event.Collection);
                if (!collectionEntry.LoadedPersister.IsInverse)
                {
                    return(Task.CompletedTask);
                }

                var abstractCollectionPersister = collectionEntry.LoadedPersister as Persister.Collection.AbstractCollectionPersister;
                if (abstractCollectionPersister == null)
                {
                    return(Task.CompletedTask);
                }

                var ownerEntityPersister = abstractCollectionPersister.OwnerEntityPersister;
                ownerEntityPersister.GetPropertyValues(ownerEntity);
                return(Task.CompletedTask);
            }
            catch (Exception ex)
            {
                return(Task.FromException <object>(ex));
            }
        }
Esempio n. 2
0
        public virtual void OnPreUpdateCollection(PreCollectionUpdateEvent evt)
        {
            var collectionEntry = getCollectionEntry(evt);

            if (!collectionEntry.LoadedPersister.IsInverse)
            {
                onCollectionAction(evt, evt.Collection, collectionEntry.Snapshot, collectionEntry);
            }
        }
Esempio n. 3
0
        public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
        {
            if (@event.AffectedOwnerOrNull == null)
            {
                return;
            }

            this.Validate(@event.Session, @event.AffectedOwnerOrNull, true);
        }
Esempio n. 4
0
        public void OnPreUpdateCollection(PreCollectionUpdateEvent evt)
        {
            CollectionEntry collectionEntry = GetCollectionEntry(evt);

            if (!collectionEntry.LoadedPersister.IsInverse)
            {
                OnCollectionAction(evt, evt.Collection, collectionEntry.Snapshot, collectionEntry);
            }
        }
Esempio n. 5
0
        public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
        {
            var owner = @event.AffectedOwnerOrNull;

            if (!ReferenceEquals(null, owner))
            {
                Validate(owner, @event.Session.GetEntityPersister(@event.Session.GetEntityName(owner), owner).EntityMode);
            }
        }
Esempio n. 6
0
        public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
        {
            var affectedOwnerEntityName = @event.GetAffectedOwnerEntityName();

            //var role = @event.Collection.Role;
            if (_authorizationObjects.Any(a => a == affectedOwnerEntityName) &&
                @event.Collection.IsDirty)
            {
                OperationAuthorizationService.InvalidateCache();
            }
        }
Esempio n. 7
0
 public Task OnPreUpdateCollectionAsync(PreCollectionUpdateEvent @event, CancellationToken cancellationToken)
 {
     try
     {
         AddEvent(@event, this);
         return(Task.CompletedTask);
     }
     catch (System.Exception ex)
     {
         return(Task.FromException <object>(ex));
     }
 }
Esempio n. 8
0
 private void PreUpdate()
 {
     IPreCollectionUpdateEventListener[] preListeners = Session.Listeners.PreCollectionUpdateEventListeners;
     if (preListeners.Length > 0)
     {
         PreCollectionUpdateEvent preEvent = new PreCollectionUpdateEvent(Persister, Collection, (IEventSource)Session);
         for (int i = 0; i < preListeners.Length; i++)
         {
             preListeners[i].OnPreUpdateCollection(preEvent);
         }
     }
 }
 private async Task PreUpdateAsync(CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     IPreCollectionUpdateEventListener[] preListeners = Session.Listeners.PreCollectionUpdateEventListeners;
     if (preListeners.Length > 0)
     {
         PreCollectionUpdateEvent preEvent = new PreCollectionUpdateEvent(Persister, Collection, (IEventSource)Session);
         for (int i = 0; i < preListeners.Length; i++)
         {
             await(preListeners[i].OnPreUpdateCollectionAsync(preEvent, cancellationToken)).ConfigureAwait(false);
         }
     }
 }
        public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
        {
            var ownerEntity     = @event.AffectedOwnerOrNull;
            var collectionEntry = @event.Session.PersistenceContext.GetCollectionEntry(@event.Collection);

            if (!collectionEntry.LoadedPersister.IsInverse)
            {
                return;
            }

            var abstractCollectionPersister = collectionEntry.LoadedPersister as Persister.Collection.AbstractCollectionPersister;

            if (abstractCollectionPersister == null)
            {
                return;
            }

            var ownerEntityPersister = abstractCollectionPersister.OwnerEntityPersister;

            ownerEntityPersister.GetPropertyValues(ownerEntity);
        }
Esempio n. 11
0
 public Task OnPreUpdateCollectionAsync(PreCollectionUpdateEvent @event, CancellationToken cancellationToken)
 {
     OnPreUpdateCollection(@event);
     return(Task.CompletedTask);
 }
Esempio n. 12
0
 public Task OnPreUpdateCollectionAsync(PreCollectionUpdateEvent @event, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Task.Run(() => OnPreUpdateCollection(@event), cancellationToken));
 }
Esempio n. 13
0
 public void OnPreUpdateCollection(PreCollectionUpdateEvent e)
 {
     OnCollection(e);
 }
 public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
 {
     AuditTrailManager?.OnPreCollectionUpdateLogEvent(@event);
 }
Esempio n. 15
0
        public void OnPreCollectionUpdateLogEvent(PreCollectionUpdateEvent @event)
        {
            if (IsTemporarilyDisabled)
            {
                return;
            }
            if (!_isEnabled)
            {
                return;
            }
            if (@event == null || @event.AffectedOwnerOrNull is AuditLogEntry)
            {
                return;
            }
            // Is the Parent Entity of the collection Auditable?
            var affectedOwnerEntityName = @event.GetAffectedOwnerEntityName();

            if (!_auditableEntities.ContainsKey(affectedOwnerEntityName))
            {
                return;
            }
            // Is the Collection Auditable?
            var auditableEntity = _auditableEntities[affectedOwnerEntityName];
            var role            = @event.Collection.Role;
            var key             = role.Substring(role.LastIndexOf(".", StringComparison.Ordinal) + 1);

            if (!auditableEntity.Properties.ContainsKey(key))
            {
                return;
            }
            var auditableProperty      = auditableEntity.Properties[key];
            var classMetadata          = @event.Session.SessionFactory.GetClassMetadata(auditableProperty.Datatype);
            var identifierPropertyName = classMetadata.IdentifierPropertyName;

            if (!(@event.Session.SessionFactory.GetCollectionMetadata(role) is ICollectionPersister collectionPersister))
            {
                throw new Exception("CollectionPersister is null. Not sure why.");
            }

            var type = GetTypeFromClassName(auditableProperty.Datatype);

            if (!(type != null))
            {
                return;
            }
            if (collectionPersister.IsInverse)
            {
                _log.Debug($"Collection [{key}] of entity [{affectedOwnerEntityName}] is inverse!");
                return;
            }
            var session     = @event.Session.GetSession(EntityMode.Poco);
            var username    = _getAuditContext().Username;
            var shouldFlush = false;

            foreach (var obj1 in @event.Collection.GetDeletes(collectionPersister, false))
            {
                var propertyInfo = type.GetProperty(identifierPropertyName);
                if (propertyInfo == null)
                {
                    continue;
                }
                var keyValue = propertyInfo.GetValue(obj1);
                var entry    = new AuditLogEntry
                {
                    EntityShortName = @event.AffectedOwnerOrNull.GetType().Name,
                    EntityFullName  = affectedOwnerEntityName,
                    UserName        = username,
                    EntityId        = @event.AffectedOwnerIdOrNull.ToString(),
                    EntryTypeId     = _auditLogEntryTypes["UPDATE"].Id,
                    Timestamp       = DateTime.UtcNow,
                    ActionTypeId    = _auditLogPropertyActionTypes["REMOVE"].Id,
                    PropertyName    = key,
                    OldValue        = keyValue.ToString()
                };
                session.Save(entry);
                shouldFlush = true;
            }
            var i = -1;

            if (@event.Collection.IsDirty)
            {
                foreach (var entryAdded in @event.Collection.Entries(collectionPersister))
                {
                    ++i;
                    var elemType = NHibernateUtil.GetSerializable(type);
                    if ([email protected](entryAdded, i, elemType))
                    {
                        continue;
                    }
                    var propertyInfo = type.GetProperty(identifierPropertyName);
                    if (propertyInfo == null)
                    {
                        continue;
                    }
                    var keyValue = propertyInfo.GetValue(entryAdded);
                    var entry    = new AuditLogEntry
                    {
                        EntityShortName = @event.AffectedOwnerOrNull.GetType().Name,
                        EntityFullName  = affectedOwnerEntityName,
                        UserName        = username,
                        EntityId        = @event.AffectedOwnerIdOrNull.ToString(),
                        EntryTypeId     = _auditLogEntryTypes["UPDATE"].Id,
                        Timestamp       = DateTime.UtcNow,
                        ActionTypeId    = _auditLogPropertyActionTypes["ADD"].Id,
                        PropertyName    = key,
                        NewValue        = keyValue.ToString()
                    };
                    session.Save(entry);
                    shouldFlush = true;
                }
                if (i > 10)
                {
                    _log.Warn($"Parsed {i} Entities for Collection [{key}] of entity [{affectedOwnerEntityName}]!");
                }
            }
            else
            {
                _log.Info($"Collection [{key}] of entity [{affectedOwnerEntityName}] is not Dirty. Skipping looking for inserted entries.");
            }
            if (shouldFlush)
            {
                // Flush only once
                session.Flush();
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="evt"></param>
 public override void OnPreUpdateCollection(PreCollectionUpdateEvent evt)
 {
 }
Esempio n. 17
0
 public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
 {
     AddEvent(@event, this);
 }
Esempio n. 18
0
 public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
 {
     log.Debug("OnPreUpdateCollection :" + @event);
 }