Beispiel #1
0
        public void Process(IInvocation invocation, ClassDefineMetadata metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            var entity = invocation.Arguments[0];

            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var interceptors = RepositoryFramework.GetInterceptors(metadata.EntityType);

            //invoke pre event
            var preUr  = new UniqueRaise(GetRaiseType(invocation, true), metadata, entity, false);
            var postUr = new UniqueRaise(GetRaiseType(invocation, false), metadata, entity, false);

            //invoke cascade delete or update
            var preRaiseType = GetRaiseType(invocation, true);

            if (preRaiseType == RaiseType.PreDelete || preRaiseType == RaiseType.PreUpdate)
            {
                Cascade(invocation, entity);
            }

            RepositoryFramework.Raise(entity, preRaiseType, preUr);

            using (MonitorContext.Repository(invocation.Method))
                invocation.Proceed();

            //invoke post event
            var postRaiseType = GetRaiseType(invocation, false);

            RepositoryFramework.Raise(entity, postRaiseType, postUr);

            //invoke cascade create
            if (postRaiseType == RaiseType.PostCreate)
            {
                Cascade(invocation, entity);
            }

            preUr.Dispose();
            postUr.Dispose();
        }