Esempio n. 1
0
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodCallMessage call = msg as IMethodCallMessage;
            IDictionary<string, object> paramDict = null;
            if (call != null)
            {
                //拦截消息,做前处理
                //kaspec.PreExcute(call.MethodName, call.InArgs);
                if (KAOPHelper.IsHaveKAopMethod(call))
                {
                    paramDict = KAOPHelper.GetParamDictionary(call);
                    _kaopAttr.PreExcute(call.MethodName, paramDict);
                }
            }

            //传递消息给下一个接收器 
            IMessage retMsg = nextSink.SyncProcessMessage(call as IMessage);
            IMethodReturnMessage dispose = retMsg as IMethodReturnMessage;
            if (dispose != null)
            {
                //调用返回时进行拦截,并进行后处理
                if (KAOPHelper.IsHaveKAopMethod(call))
                {
                    _kaopAttr.EndExcute(dispose.MethodName, paramDict, dispose.OutArgs, dispose.ReturnValue, dispose.Exception);
                }
            }
            return retMsg;
        }
Esempio n. 2
0
        /// <summary>
        /// 验证是否KAopMethodAttribute特性
        /// </summary>
        /// <param name="call">方法调用消息接口</param>
        /// <returns>true:是;false:否</returns>
        public static bool IsHaveKAopMethod(IMethodCallMessage call)
        {
            Type _type = KAOPHelper.FindTypeInCurrentDomain(call.TypeName);
            var  _arr  = _type.GetMethod(call.MethodName).GetCustomAttributes(typeof(KAopMethodAttribute), false);

            if (_arr != null && _arr.Length > 0)
            {
                return(true);
            }
            return(false);
        }