Esempio n. 1
0
        public bool OnPreUpdate(IDataInvocation invocation)
        {
            if (invocation.Entity.GetType() == typeof(Employee))
            {
                // change the last name to a different value and proceed:
                ((Employee)invocation.Entity).Name.LastName = "updated";
            }

            return(true);
        }
Esempio n. 2
0
        public void ExecuteOnInsert(IDataInvocation invocation)
        {
            var canProceed         = true;
            var insertInterceptors = ResolveForInterceptor <IInsertInterceptor>();

            if (insertInterceptors != null && insertInterceptors.Count() > 0)
            {
                // pre-insert interceptors:
                foreach (var interceptor in insertInterceptors)
                {
#if DEBUG
                    Type theEntity = invocation.Entity.GetType().IsProxy()
                                        ? invocation.Entity.GetType().BaseType
                                        : invocation.Entity.GetType();

                    _environment.Logger.DebugFormat("Intercepting insert for '{0}' " +
                                                    "with interceptor '{1}' for OnPreInsert(...).",
                                                    theEntity.FullName,
                                                    interceptor.GetType().Name);
#endif

                    canProceed = interceptor.OnPreInsert(invocation);
                    if (!canProceed)
                    {
                        break;
                    }
                }

                if (canProceed)
                {
                    // do the insert operation:
                    ((DataInvocation)invocation).Proceed();

                    // post-insert interceptors:
                    foreach (var interceptor in insertInterceptors)
                    {
#if DEBUG
                        Type theEntity = invocation.Entity.GetType().IsProxy()
                                            ? invocation.Entity.GetType().BaseType
                                            : invocation.Entity.GetType();

                        _environment.Logger.DebugFormat("Intercepting insert for '{0}' " +
                                                        "with interceptor '{1}' for OnPostInsert(...).",
                                                        theEntity.FullName,
                                                        interceptor.GetType().Name);
#endif
                        interceptor.OnPostInsert(invocation);
                    }
                }
            }
            else
            {
                ((DataInvocation)invocation).Proceed();
            }
        }
Esempio n. 3
0
        public bool OnPreInsert(IDataInvocation invocation)
        {
            if (invocation.Entity.GetType() == typeof(Employee))
            {
                // change the last name to a different value and proceed:
                ((Employee)invocation.Entity).Name.LastName = "inserted";
            }

            // return true to invoke the insert action on the entity:
            return(true);
        }
Esempio n. 4
0
        public bool OnPreDelete(IDataInvocation invocation)
        {
            if (invocation.Entity.GetType() == typeof(Employee))
            {
                // mark the entity as deleted, but do not call proceed
                // or we will remove the entity from the persistance store,
                // we will update the entity in the persistance store with
                // a custom flag instead:
                ((Employee)invocation.Entity).IsDeleted = true;
                invocation.Session.Save(invocation.Entity as Employee);
            }

            // do not proceed with the delete action:
            return(false);
        }
Esempio n. 5
0
 public void OnPostDelete(IDataInvocation invocation)
 {
     // never called when OnPreDelete returns false...
 }
Esempio n. 6
0
 public void OnPostUpdate(IDataInvocation invocation)
 {
 }
Esempio n. 7
0
 public void OnPostInsert(IDataInvocation invocation)
 {
 }
Esempio n. 8
0
 public void OnPostDelete(IDataInvocation invocation)
 {
 }
Esempio n. 9
0
 public bool OnPreDelete(IDataInvocation invocation)
 {
     return(true);
 }