Пример #1
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            IMethodReturn returnValue = null;

            //顺序执行
            returnValue = getNext()(input, getNext);

            //若符合要求
            if (input.MethodBase is MethodInfo && (input.MethodBase as MethodInfo).ReturnType == typeof(bool))
            {
                //根据异常状态设置返回值
                if (null != returnValue.Exception)
                {
                    returnValue.ReturnValue = true;
                }
                else
                {
                    returnValue.ReturnValue = false;
                }

                //设置返回值类型
                returnValue = CustomMethodReturn.PrepareCustomReturn(input, returnValue);
            }


            return(returnValue);
        }
Пример #2
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            IMethodReturn returnValue = null;

            //若符合要求
            if (input.MethodBase is MethodInfo && (input.MethodBase as MethodInfo).ReturnType == typeof(bool))
            {
                //开启连接上下文
                using (var ctx = m_useContextCreater.CreatDbContext())
                {
                    //开启事务
                    using (var ta = ctx.Database.BeginTransaction())
                    {
                        returnValue = getNext()(input, getNext);
                        //若没有异常则提交事务
                        if (null == returnValue.Exception)
                        {
                            //事务提交
                            ta.Commit();
                            //设置返回值
                            returnValue.ReturnValue = true;
                        }
                        else
                        {
                            //事务回滚
                            ta.Rollback();
                            //设置返回值
                            returnValue.ReturnValue = false;
                        }

                        //设置返回值类型
                        returnValue = CustomMethodReturn.PrepareCustomReturn(input, returnValue);
                    }
                }
            }
            //正常执行
            else
            {
                returnValue = getNext()(input, getNext);
            }


            return(returnValue);
        }
Пример #3
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            IMethodReturn returnValue = null;

            //若符合要求
            if (input.MethodBase is MethodInfo && (input.MethodBase as MethodInfo).ReturnType == typeof(bool))
            {
                //开启事务
                using (TransactionScope useScope = new TransactionScope(TransactionScopeOption.RequiresNew, m_useTrancsactionOptions))
                {
                    returnValue = getNext()(input, getNext);
                    //若没有异常则提交事务
                    if (null == returnValue.Exception)
                    {
                        useScope.Complete();
                        //设置返回值
                        returnValue.ReturnValue = true;
                    }
                    else
                    {
                        //设置返回值
                        returnValue.ReturnValue = false;
                    }

                    //设置返回值类型
                    returnValue = CustomMethodReturn.PrepareCustomReturn(input, returnValue);
                }
            }
            //正常执行
            else
            {
                returnValue = getNext()(input, getNext);
            }


            return(returnValue);
        }