Пример #1
0
        protected virtual void PreProcess(MethodCallContext ctx)
        {
            List <BeforeAdvisor> advisors = new List <BeforeAdvisor>();

            try
            {
                string[] advisorNames = m_WeaveManager.GetAdvisorNames(ctx);
                for (int i = 0; i < advisorNames.Length; i++)
                {
                    BeforeAdvisor advisor = m_WeaveManager.GetAdvisor <BeforeAdvisor>(advisorNames[i]);
                    advisor.SetContext(ctx);
                    advisors.Add(advisor);
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowWeaveException(ctx, ex);
            }

            try
            {
                for (int i = 0; i < advisors.Count; i++)
                {
                    advisors[i].Execute();
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowAspectExecuteError(ctx, ex);
            }
        }
Пример #2
0
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodCallMessage mcm = msg as IMethodCallMessage;
            MethodCallContext ctx = new MethodCallContext(mcm, m_NextSink);

            ctx.Position = Position.Before;
            PreProcess(ctx);

            ctx.Position = Position.Around;
            AroundProcess(ctx);

            if (ctx.ReturnMessage.Exception != null)
            {
                ctx.Position = Position.Throw;
                ExceptionProcess(ctx);
            }

            ctx.Position = Position.After;
            PostProcess(ctx);

            return ctx.ReturnMessage;
        }
Пример #3
0
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodCallMessage mcm = msg as IMethodCallMessage;
            MethodCallContext  ctx = new MethodCallContext(mcm, m_NextSink);

            ctx.Position = Position.Before;
            PreProcess(ctx);

            ctx.Position = Position.Around;
            AroundProcess(ctx);

            if (ctx.ReturnMessage.Exception != null)
            {
                ctx.Position = Position.Throw;
                ExceptionProcess(ctx);
            }

            ctx.Position = Position.After;
            PostProcess(ctx);

            return(ctx.ReturnMessage);
        }
Пример #4
0
        protected virtual void AroundProcess(MethodCallContext ctx)
        {
            List<AroundAdvisor> advisors = new List<AroundAdvisor>();
            try
            {
                string[] advisorNames = m_WeaveManager.GetAdvisorNames(ctx);
                for (int i = 0; i < advisorNames.Length; i++)
                {
                    AroundAdvisor advisor = m_WeaveManager.GetAdvisor<AroundAdvisor>(advisorNames[i]);
                    advisor.SetContext(ctx);
                    advisors.Add(advisor);
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowWeaveException(ctx, ex);
            }

            for (int idx = 0; idx < advisors.Count - 1; idx++)
                advisors[idx].Next = advisors[idx + 1];

            try
            {
                if (advisors.Count == 0)
                {
                    ctx.ReturnMessage = m_NextSink.SyncProcessMessage(ctx.CallMessage) as IMethodReturnMessage;
                    return;
                }
                else
                {
                    for (int i = 0; i < advisors.Count; i++)
                    {
                        advisors[i].Execute();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowAspectExecuteError(ctx, ex);
            }

            if (ctx.ReturnMessage == null)//Note: build fake return message
            {
                Assertion.IsFalse(ctx.CallMessage.MethodBase.IsConstructor, "Should not be ctor.");
                MethodInfo method = ctx.CallMessage.MethodBase as MethodInfo;
                List<object> outArgs = new List<object>();
                ParameterInfo[] paramInfos = method.GetParameters();
                for (int idx = 0; idx < paramInfos.Length; idx++)
                {
                    if (paramInfos[idx].IsOut)
                    {
                        if (paramInfos[idx].ParameterType.IsValueType)
                        {
                            object val = Activator.CreateInstance(paramInfos[idx].ParameterType);
                            outArgs.Add(val);
                        }
                        else
                        {
                            outArgs.Add(null);
                        }
                    }
                }
                object ret = null;
                if (method.ReturnType.IsValueType && method.ReturnType != typeof(void))
                {
                    ret = Activator.CreateInstance(method.ReturnType);
                }
                else
                    ret = null;
                ReturnMessage rm = new ReturnMessage(ret, outArgs.ToArray(), outArgs.Count, ctx.CallMessage.LogicalCallContext, ctx.CallMessage);
                ctx.ReturnMessage = rm;
            }
        }
Пример #5
0
        protected virtual void PreProcess(MethodCallContext ctx)
        {
            List<BeforeAdvisor> advisors = new List<BeforeAdvisor>();
            try
            {
                string[] advisorNames = m_WeaveManager.GetAdvisorNames(ctx);
                for (int i = 0; i < advisorNames.Length; i++)
                {
                    BeforeAdvisor advisor = m_WeaveManager.GetAdvisor<BeforeAdvisor>(advisorNames[i]);
                    advisor.SetContext(ctx);
                    advisors.Add(advisor);
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowWeaveException(ctx, ex);
            }

            try
            {
                for (int i = 0; i < advisors.Count; i++)
                {
                    advisors[i].Execute();
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowAspectExecuteError(ctx, ex);
            }
        }
Пример #6
0
        protected virtual void AroundProcess(MethodCallContext ctx)
        {
            List <AroundAdvisor> advisors = new List <AroundAdvisor>();

            try
            {
                string[] advisorNames = m_WeaveManager.GetAdvisorNames(ctx);
                for (int i = 0; i < advisorNames.Length; i++)
                {
                    AroundAdvisor advisor = m_WeaveManager.GetAdvisor <AroundAdvisor>(advisorNames[i]);
                    advisor.SetContext(ctx);
                    advisors.Add(advisor);
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowWeaveException(ctx, ex);
            }

            for (int idx = 0; idx < advisors.Count - 1; idx++)
            {
                advisors[idx].Next = advisors[idx + 1];
            }

            try
            {
                if (advisors.Count == 0)
                {
                    ctx.ReturnMessage = m_NextSink.SyncProcessMessage(ctx.CallMessage) as IMethodReturnMessage;
                    return;
                }
                else
                {
                    for (int i = 0; i < advisors.Count; i++)
                    {
                        advisors[i].Execute();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ThrowAspectExecuteError(ctx, ex);
            }

            if (ctx.ReturnMessage == null)//Note: build fake return message
            {
                Assertion.IsFalse(ctx.CallMessage.MethodBase.IsConstructor, "Should not be ctor.");
                MethodInfo      method     = ctx.CallMessage.MethodBase as MethodInfo;
                List <object>   outArgs    = new List <object>();
                ParameterInfo[] paramInfos = method.GetParameters();
                for (int idx = 0; idx < paramInfos.Length; idx++)
                {
                    if (paramInfos[idx].IsOut)
                    {
                        if (paramInfos[idx].ParameterType.IsValueType)
                        {
                            object val = Activator.CreateInstance(paramInfos[idx].ParameterType);
                            outArgs.Add(val);
                        }
                        else
                        {
                            outArgs.Add(null);
                        }
                    }
                }
                object ret = null;
                if (method.ReturnType.IsValueType && method.ReturnType != typeof(void))
                {
                    ret = Activator.CreateInstance(method.ReturnType);
                }
                else
                {
                    ret = null;
                }
                ReturnMessage rm = new ReturnMessage(ret, outArgs.ToArray(), outArgs.Count, ctx.CallMessage.LogicalCallContext, ctx.CallMessage);
                ctx.ReturnMessage = rm;
            }
        }