Exemple #1
0
        private void DrawInterceptor(VizInterceptor vizInterceptor, Graphics g, int y)
        {
            Rectangle consumerBounds = new Rectangle(30, y, 450, 30);



            if (vizInterceptor.InterceptorType == VizInterceptorType.After)
            {
                consumerBounds = new Rectangle(130, y, 350, 30);
            }
            else if (vizInterceptor.InterceptorType == VizInterceptorType.Around)
            {
            }
            else if (vizInterceptor.InterceptorType == VizInterceptorType.Before)
            {
                consumerBounds = new Rectangle(30, y, 350, 30);
            }

            if (vizInterceptor.ThrowsExceptionTypes.Count > 0)
            {
                Pen pen = new Pen(Brushes.Red, 1);
                int y2  = consumerBounds.Y + 15;

                for (int x = consumerBounds.X - 25; x < 350 + 130 + 25; x += 20)
                {
                    g.DrawLine(pen, x, y2, x + 10, y2 + 5);
                    g.DrawLine(pen, x + 10, y2 + 5, x + 20, y2);
                }

                Rectangle exceptionBounds = new Rectangle(350 + 130 + 25 + 5, y2 - 5, 200, vizInterceptor.ThrowsExceptionTypes.Count * 15 + 5);
                DrawBox(exceptionBounds, g, Color.White, Color.LightYellow);

                foreach (string exception in vizInterceptor.ThrowsExceptionTypes)
                {
                    DrawString(350 + 130 + 25 + 10, y2 - 3, string.Format("May throw {0}", exception), g);
                    y2 += 15;
                }
            }

            DrawBox(consumerBounds, g, Color.White, Color.FromArgb(230, 210, 255));

            DrawStringBold(consumerBounds.X + 30, consumerBounds.Y + 3, string.Format("{0} interceptor", vizInterceptor.InterceptorType), g);
            DrawString(consumerBounds.X + 30, consumerBounds.Y + 15, string.Format("{0} : from aspect {1}", vizInterceptor.Name, "xxx"), g);



            if (vizInterceptor.MayBreakFlow)
            {
                Pen pen = new Pen(Brushes.Silver, 3f);
                pen.EndCap    = LineCap.ArrowAnchor;
                pen.DashStyle = DashStyle.Dash;
                g.DrawLine(pen, consumerBounds.X + 80, consumerBounds.Y + 43, consumerBounds.Right - 80, consumerBounds.Y + 43);
                DrawString(consumerBounds.X + 90, consumerBounds.Y + 45, "May break flow", g);
            }
        }
        private void SerializeInterceptors(VizMethodBase vizMethodBase, IList interceptors)
        {
            foreach (object interceptor in interceptors)
            {
                VizInterceptorType interceptorType = VizInterceptorType.Around;
                VizInterceptor     vizInterceptor  = new VizInterceptor();
                if (interceptor is IAfterInterceptor)
                {
                    interceptorType     = VizInterceptorType.After;
                    vizInterceptor.Name = interceptor.GetType().Name;
                }
                else if (interceptor is IBeforeInterceptor)
                {
                    interceptorType     = VizInterceptorType.Before;
                    vizInterceptor.Name = interceptor.GetType().Name;
                }
                else if (interceptor is IAroundInterceptor)
                {
                    interceptorType     = VizInterceptorType.Around;
                    vizInterceptor.Name = interceptor.GetType().Name;
                }
                else if (interceptor is AroundDelegate)
                {
                    interceptorType = VizInterceptorType.Around;
                    Delegate ad = (Delegate)interceptor;
                    vizInterceptor.Name = ad.Method.DeclaringType.Name + "." + ad.Method.Name;
                }
                else if (interceptor is AfterDelegate)
                {
                    interceptorType = VizInterceptorType.After;
                    Delegate ad = (Delegate)interceptor;
                    vizInterceptor.Name = ad.Method.DeclaringType.Name + "." + ad.Method.Name;
                }
                else if (interceptor is BeforeDelegate)
                {
                    interceptorType = VizInterceptorType.Before;
                    Delegate ad = (Delegate)interceptor;
                    vizInterceptor.Name = ad.Method.DeclaringType.Name + "." + ad.Method.Name;
                }


                vizInterceptor.TypeName = interceptor.GetType().Name;

                vizInterceptor.InterceptorType = interceptorType;

                if (interceptor.GetType().GetCustomAttributes(typeof(MayBreakFlowAttribute), false).Length > 0)
                {
                    vizInterceptor.MayBreakFlow = true;
                }

                if (interceptor.GetType().GetCustomAttributes(typeof(IsRequiredAttribute), false).Length > 0)
                {
                    vizInterceptor.IsRequired = true;
                }

                object[] exceptionTypes = interceptor.GetType().GetCustomAttributes(typeof(ThrowsAttribute), false);
                foreach (ThrowsAttribute throws in exceptionTypes)
                {
                    vizInterceptor.ThrowsExceptionTypes.Add(throws.ExceptionType.Name);
                }

                vizMethodBase.Interceptors.Add(vizInterceptor);
            }
        }