示例#1
0
        public void Before(MethodInfo method, object[] args, object target)
        {
            //打出环境参数
            LogHelper <BeforeAdvice> .PrintEvn();

            AddinMethodInvocation invocation = new AddinMethodInvocation(method, args, target);

            //请求的参数保存到当前的服务器内存中
            AddinEnvironment.SaveServiceRequestParam(invocation);

            bool rtn = false;

            try
            {
                rtn = executor.ExecuteBeforeMethod(method, args, target);
                //是否要判断返回值来处理
                LogHelper <BeforeAdvice> .Error("功能注入方法前方法执行结果:" + rtn);
            }
            catch (Exception e)
            {
                LogHelper <BeforeAdvice> .Error("功能注入执行方法前方法出错:" + e.StackTrace);

                throw new AddinException("功能注入提示信息:" + e.Message);
            }
        }
示例#2
0
        public void AfterReturning(object returnValue, MethodInfo method, object[] args, object target)
        {
            //打出环境参数
            LogHelper <AfterAdvice> .PrintEvn();

            AddinMethodInvocation invocation = new AddinMethodInvocation(method, args, target);

            AddinEnvironment.SaveServiceRequestParam(invocation);


            try
            {
                LogHelper <AfterAdvice> .Info("方法执行的结果是:" + (returnValue == null ? "null":returnValue.ToString()));

                bool rtn = executor.ExecuteAfterMethod(returnValue, method, args, target);
                //是否要判断返回值来处理
                LogHelper <AfterAdvice> .Info("功能注入方法执行的结果是:" + rtn);
            }
            catch (Exception e)
            {
                LogHelper <AfterAdvice> .Error("执行方法后方法出错:" + e.StackTrace);

                throw new AddinException("功能注入提示信息:" + e.Message);
            }
        }
示例#3
0
        /// <summary>
        /// 方法前调用
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        public bool ExecuteBeforeMethod(MethodInfo method, object[] args, object target)
        {
            bool     rtn     = false;
            ISession session = null;

            try
            {
                //判断是否能够注入方法
                var entity = AddinConfigure.GetPluginConfigure(method.Name, args, target, EnumInterceptorType.Before);
                if (entity == null)
                {
                    LogHelper <AfterAdvice> .Info(string.Format("无法取得注入方法的配置信息 class:{0},method:{1}", target.ToString(), method.Name));

                    return(false);
                }

                AddinMethodInvocation invocation = new AddinMethodInvocation(method, args, target);

                if (entity != null)
                {
                    //取得当前服务方法的session
                    session = hibernateTemplate.SessionFactory.GetCurrentSession();
                    if (session == null)
                    {
                        throw new AddinException("无法通过GetCurrentSession获得session");
                    }

                    IBeforeInterceptor[] executors = AddinInterceptorFactory.GetBeforeExecutor(entity, session);

                    foreach (var executor in executors)
                    {
                        if (executor != null)
                        {
                            rtn = executor.Before(invocation);
                        }
                    }
                    //session.Close();
                }

                return(rtn);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //if (session!=null && session.IsOpen)
                //{
                //    session.Close();
                //}
            }
        }
示例#4
0
        /// <summary>
        /// 方法后调用
        /// </summary>
        /// <param name="returnObject"></param>
        /// <param name="invocation"></param>
        /// <returns></returns>
        public bool ExecuteAfterMethod(object returnObject, MethodInfo method, object[] args, object target)
        {
            bool rtn = false;


            //判断是否能够注入方法
            var entity = AddinConfigure.GetPluginConfigure(method.Name, args, target, EnumInterceptorType.After);

            if (entity == null)
            {
                LogHelper <BeforeAdvice> .Info(string.Format("无法取得注入方法的配置信息 class:{0},method:{1}", target.ToString(), method.Name));

                return(false);
            }

            AddinMethodInvocation invocation = new AddinMethodInvocation(method, args, target);

            if (returnObject != null)
            {
                var result = returnObject as SavedResult <long>;
                if (result != null)
                {
                    //将结果注入到线程上下文
                    CallContext.SetData("returnobject", (result.KeyCodes.ToList())[0]);
                    LogHelper <InterceptorExecutor> .Info("取得的主键信息是" + (result.KeyCodes.ToList())[0]);
                }
                else
                {
                    //为空的情况下判断是不是ResponseResult
                    var result2 = returnObject as ResponseResult;
                }
            }

            if (entity != null)
            {
                ISession session = hibernateTemplate.SessionFactory.GetCurrentSession();
                if (session == null)
                {
                    throw new AddinException("无法通过GetCurrentSession获得session");
                }

                IAfterInterceptor[] executors = AddinInterceptorFactory.GetAfterExecutor(entity, session);
                LogHelper <InterceptorExecutor> .Info("待处理的后处理事件是有" + executors.Length);

                foreach (var executor in executors)
                {
                    rtn = executor.After(returnObject, invocation);
                }
            }

            return(rtn);
        }