Ejemplo n.º 1
0
        public AspectNode(IGenericAspect aspect)
            : base(aspect.Name)
        {
            this.aspect = aspect;

            this.ImageIndex = 4;
            this.SelectedImageIndex = 4;

            foreach (AspectTarget target in aspect.Targets)
            {
                AspectTargetNode targetNode = new AspectTargetNode(target);
                this.Nodes.Add(targetNode);
            }

            ArrayList mixins = (ArrayList) aspect.Mixins;
            mixins.Sort();
            foreach (PresentationMixin  mixin in mixins)
            {
                MixinNode mixinNode = new MixinNode(mixin);
                this.Nodes.Add(mixinNode);
            }

            foreach (IPointcut pointcut in aspect.Pointcuts)
            {
                PointcutNode pointcutNode = new PointcutNode(pointcut);
                this.Nodes.Add(pointcutNode);
            }
        }
Ejemplo n.º 2
0
        public PresentationAspect(IGenericAspect aspect)
        {
            this.Name = aspect.Name;

            foreach (AspectTarget target in aspect.Targets)
            {
                PresentationAspectTarget presTarget = new PresentationAspectTarget(this, target);
                this.Targets.Add(presTarget);
            }

            foreach (IPointcut pointcut in aspect.Pointcuts)
            {
                PresentationPointcut presPointcut = new PresentationPointcut(this, pointcut);
                this.Pointcuts.Add(presPointcut);
            }

            foreach (object mixin in aspect.Mixins)
            {
                string typeName = "";
                if (mixin is Type)
                {
                    typeName = ((Type)mixin).FullName;
                }
                else
                {
                    typeName = (string)mixin;
                }

                PresentationMixin presMixin = new PresentationMixin(this, typeName);
                this.Mixins.Add(presMixin);
            }
        }
        public IEngine Configure(XmlElement xmlRoot, string configName)
        {
            Engine engine = new Engine(configName);

            XmlElement o = xmlRoot;

            if (o == null)
            {
                return(engine);
            }


            foreach (XmlNode settingsNode in o)
            {
                if (settingsNode.Name == "aspect")
                {
                    IGenericAspect aspect = Configure(settingsNode, useTypePlaceHolders);

                    engine.Configuration.Aspects.Add(aspect);
                }
            }


            return(engine);
        }
Ejemplo n.º 4
0
        public AspectNode(IGenericAspect aspect) : base(aspect.Name)
        {
            this.aspect = aspect;

            this.ImageIndex         = 4;
            this.SelectedImageIndex = 4;

            foreach (AspectTarget target in aspect.Targets)
            {
                AspectTargetNode targetNode = new AspectTargetNode(target);
                this.Nodes.Add(targetNode);
            }

            ArrayList mixins = (ArrayList)aspect.Mixins;

            mixins.Sort();
            foreach (PresentationMixin mixin in mixins)
            {
                MixinNode mixinNode = new MixinNode(mixin);
                this.Nodes.Add(mixinNode);
            }

            foreach (IPointcut pointcut in aspect.Pointcuts)
            {
                PointcutNode pointcutNode = new PointcutNode(pointcut);
                this.Nodes.Add(pointcutNode);
            }
        }
 private static IGenericAspect CreateAspect(ITypedAspect aspect, IGenericAspect newAspect, IList mixins,
                                            IList pointcuts)
 {
     object[] aspectTargetAttributes =
         aspect.GetType().GetCustomAttributes(typeof(AspectTargetAttribute), false);
     if (aspectTargetAttributes != null)
     {
         AspectTargetAttribute aspectTargetAttribute = (AspectTargetAttribute)aspectTargetAttributes[0];
         if (aspectTargetAttribute.TargetAttribute != null)
         {
             newAspect =
                 new AttributeAspect(aspect.GetType().Name, aspectTargetAttribute.TargetAttribute, mixins,
                                     pointcuts);
         }
         else if (aspectTargetAttribute.TargetSignature != null)
         {
             newAspect =
                 new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetSignature, mixins,
                                     pointcuts);
         }
         else if (aspectTargetAttribute.TargetType != null)
         {
             newAspect =
                 new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetType, mixins, pointcuts);
         }
         else
         {
             throw new Exception("No target specified");
         }
     }
     return(newAspect);
 }
Ejemplo n.º 6
0
        public int Compare(object x, object y)
        {
            IGenericAspect a1 = x as IGenericAspect;
            IGenericAspect a2 = y as IGenericAspect;

            if (x == null)
            {
                throw new Exception("Object is not of type IGenericAspect");
            }
            if (y == null)
            {
                throw new Exception("Object is not of type IGenericAspect");
            }

            return(a1.Name.CompareTo(a2.Name));
        }
        /// <summary>
        /// Convert a typed aspect into a generic one.
        /// </summary>
        /// <param name="aspect"></param>
        /// <returns></returns>
        public static IGenericAspect Convert(ITypedAspect aspect)
        {
            IGenericAspect newAspect = null;

            IList mixins    = new ArrayList();
            IList pointcuts = new ArrayList();

            AddMixins(aspect, mixins);

            AddInterceptors(aspect, pointcuts);


            newAspect = CreateAspect(aspect, newAspect, mixins, pointcuts);

            return(newAspect);
        }
        public IEngine Configure(XmlNode xmlRoot, string configName, bool useTypePlaceHolders)
        {
            Engine engine = new Engine(configName);

            if (xmlRoot == null)
            {
                return(engine);
            }


            foreach (XmlNode settingsNode in xmlRoot.SelectNodes("aspect"))
            {
                IGenericAspect aspect = Configure(settingsNode, useTypePlaceHolders);

                engine.Configuration.Aspects.Add(aspect);
            }

            return(engine);
        }
 private static IGenericAspect CreateAspect(ITypedAspect aspect, IGenericAspect newAspect, IList mixins,
                                            IList pointcuts)
 {
     object[] aspectTargetAttributes =
         aspect.GetType().GetCustomAttributes(typeof (AspectTargetAttribute), false);
     if (aspectTargetAttributes != null)
     {
         AspectTargetAttribute aspectTargetAttribute = (AspectTargetAttribute) aspectTargetAttributes[0];
         if (aspectTargetAttribute.TargetAttribute != null)
             newAspect =
                 new AttributeAspect(aspect.GetType().Name, aspectTargetAttribute.TargetAttribute, mixins,
                                     pointcuts);
         else if (aspectTargetAttribute.TargetSignature != null)
             newAspect =
                 new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetSignature, mixins,
                                     pointcuts);
         else if (aspectTargetAttribute.TargetType != null)
             newAspect =
                 new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetType, mixins, pointcuts);
         else
             throw new Exception("No target specified");
     }
     return newAspect;
 }
 public PresentationMixin(IGenericAspect aspect, string mixin)
 {
     this.aspect = aspect;
     this.typeName = mixin;
 }
 public PresentationMixin(IGenericAspect aspect)
 {
     this.aspect = aspect;
 }
Ejemplo n.º 12
0
 public AspectProperties(IGenericAspect aspect)
 {
     this.aspect = aspect;
 }
Ejemplo n.º 13
0
 public AspectProperties(IGenericAspect aspect)
 {
     this.aspect = aspect;
 }
        private static IGenericAspect Configure(XmlNode settingsNode, bool useTypePlaceHolders)
        {
            IList pointcuts = new ArrayList();
            IList mixins    = new ArrayList();
            IList targets   = new ArrayList();

            string aspectName = settingsNode.Attributes["name"].Value;

            foreach (XmlNode aspectNode in settingsNode)
            {
                if (aspectNode.Name == "pointcut")
                {
                    string name = "Pointcut";
                    if (aspectNode.Attributes["name"] != null)
                    {
                        name = aspectNode.Attributes["name"].Value;
                    }

                    IList interceptors    = new ArrayList();
                    IList pointcutTargets = new ArrayList();

                    foreach (XmlNode pointcutNode in aspectNode)
                    {
                        if (pointcutNode.Name == "interceptor")
                        {
                            string typeString      = pointcutNode.Attributes["type"].Value;
                            Type   interceptorType = Type.GetType(typeString);
                            if (interceptorType == null)
                            {
                                if (useTypePlaceHolders)
                                {
                                    interceptors.Add(typeString);
                                }
                                else
                                {
                                    throw new Exception(
                                              string.Format("Interceptor type '{0}' was not found!", typeString));
                                }
                            }
                            else
                            {
                                object interceptor = Activator.CreateInstance(interceptorType);
                                interceptors.Add(interceptor);
                            }
                        }

                        if (pointcutNode.Name == "target")
                        {
                            string signature = null;
                            if (pointcutNode.Attributes["signature"] != null)
                            {
                                signature = pointcutNode.Attributes["signature"].Value;
                            }

                            string targetTypeString = null;
                            if (pointcutNode.Attributes["type"] != null)
                            {
                                targetTypeString = pointcutNode.Attributes["type"].Value;
                            }

                            if (signature == null)
                            {
                                signature = "";
                            }

                            string excludeString = null;
                            if (pointcutNode.Attributes["exclude"] != null)
                            {
                                excludeString = pointcutNode.Attributes["exclude"].Value;
                            }
                            bool exclude = false;
                            if (excludeString != null)
                            {
                                exclude = FromBool(excludeString);
                            }

                            PointcutTargetType targetType = PointcutTargetType.Signature;
                            if (targetTypeString != null)
                            {
                                switch (targetTypeString.ToLower())
                                {
                                case "signature":
                                    targetType = PointcutTargetType.Signature;
                                    break;

                                case "fullsignature":
                                    targetType = PointcutTargetType.FullSignature;
                                    break;

                                case "attribute":
                                    targetType = PointcutTargetType.Attribute;
                                    break;

                                default:
                                    throw new Exception(String.Format("Unknown pointcut target type {0}", targetTypeString));
                                }
                            }

                            PointcutTarget target = null;
                            if (targetType == PointcutTargetType.Signature)
                            {
                                target = new PointcutTarget(signature, targetType, exclude);
                            }
                            else
                            {
                                Type signatureType = Type.GetType(signature);
                                if (signatureType == null)
                                {
                                    if (useTypePlaceHolders)
                                    {
                                        target = new PointcutTarget(signature, targetType, exclude);
                                    }
                                    else
                                    {
                                        throw new Exception(
                                                  string.Format("Type '{0}' was not found!", signatureType));
                                    }
                                }
                                else
                                {
                                    target = new PointcutTarget(signatureType, targetType, exclude);
                                }
                            }

                            pointcutTargets.Add(target);
                        }
                    }

                    IPointcut pointcut = null;
                    if (aspectNode.Attributes["target-signature"] != null)
                    {
                        string targetMethodSignature = aspectNode.Attributes["target-signature"].Value;
                        pointcut = new Pointcut(interceptors);
                        pointcut.Targets.Add(new PointcutTarget(targetMethodSignature, PointcutTargetType.Signature));
                    }

                    if (aspectNode.Attributes["target-attribute"] != null)
                    {
                        string attributeTypeString = aspectNode.Attributes["target-attribute"].Value;
                        pointcut = new Pointcut(interceptors);

                        Type attributeType = Type.GetType(attributeTypeString);
                        if (attributeType == null)
                        {
                            if (useTypePlaceHolders)
                            {
                                pointcut.Targets.Add(new PointcutTarget(attributeTypeString, PointcutTargetType.Attribute));
                            }
                            else
                            {
                                throw new Exception(
                                          string.Format("Attribute type '{0}' was not found!", attributeTypeString));
                            }
                        }
                        else
                        {
                            pointcut.Targets.Add(new PointcutTarget(attributeType, PointcutTargetType.Attribute));
                        }
                    }

                    foreach (PointcutTarget target in pointcutTargets)
                    {
                        pointcut.Targets.Add(target);
                    }

                    pointcut.Name = name;

                    pointcuts.Add(pointcut);
                }

                if (aspectNode.Name == "mixin")
                {
                    string typeString = aspectNode.Attributes["type"].Value;
                    Type   mixinType  = Type.GetType(typeString);
                    if (mixinType == null)
                    {
                        if (useTypePlaceHolders)
                        {
                            mixins.Add(typeString);
                        }
                        else
                        {
                            throw new Exception(string.Format("Mixin type '{0}' was not found!", typeString));
                        }
                    }
                    else
                    {
                        mixins.Add(mixinType);
                    }
                }

                if (aspectNode.Name == "target")
                {
                    string signature = null;
                    if (aspectNode.Attributes["signature"] != null)
                    {
                        signature = aspectNode.Attributes["signature"].Value;
                    }

                    string targetTypeString = null;
                    if (aspectNode.Attributes["type"] != null)
                    {
                        targetTypeString = aspectNode.Attributes["type"].Value;
                    }

                    if (signature == null)
                    {
                        signature = "";
                    }

                    string excludeString = null;
                    if (aspectNode.Attributes["exclude"] != null)
                    {
                        excludeString = aspectNode.Attributes["exclude"].Value;
                    }
                    bool exclude = false;
                    if (excludeString != null)
                    {
                        exclude = FromBool(excludeString);
                    }

                    AspectTargetType targetType = AspectTargetType.Signature;
                    if (targetTypeString != null)
                    {
                        switch (targetTypeString.ToLower())
                        {
                        case "signature":
                            targetType = AspectTargetType.Signature;
                            break;

                        case "attribute":
                            targetType = AspectTargetType.Attribute;
                            break;

                        case "interface":
                            targetType = AspectTargetType.Interface;
                            break;

                        default:
                            throw new Exception(String.Format("Unknown aspect target type {0}", targetTypeString));
                        }
                    }
                    AspectTarget target = null;
                    if (targetType == AspectTargetType.Signature)
                    {
                        target = new AspectTarget(signature, targetType, exclude);
                    }
                    else
                    {
                        Type signatureType = Type.GetType(signature);
                        if (signatureType == null)
                        {
                            if (useTypePlaceHolders)
                            {
                                target = new AspectTarget(signature, targetType, exclude);
                            }
                            else
                            {
                                throw new Exception(
                                          string.Format("Type '{0}' was not found!", signatureType));
                            }
                        }
                        else
                        {
                            target = new AspectTarget(signatureType, targetType, exclude);
                        }
                    }

                    targets.Add(target);
                }
            }

            IGenericAspect aspect = null;

            if (settingsNode.Attributes["target-signature"] != null)
            {
                string targetTypeSignature = settingsNode.Attributes["target-signature"].Value;
                //aspect = new SignatureAspect(aspectName, targetTypeSignature, mixins, pointcuts);
                aspect = new GenericAspect(aspectName, mixins, pointcuts);
                aspect.Targets.Add(new AspectTarget(targetTypeSignature, AspectTargetType.Signature));
            }

            if (settingsNode.Attributes["target-attribute"] != null)
            {
                string attributeTypeString = settingsNode.Attributes["target-attribute"].Value;
                aspect = new GenericAspect(aspectName, mixins, pointcuts);

                Type attributeType = Type.GetType(attributeTypeString);
                if (attributeType == null)
                {
                    if (useTypePlaceHolders)
                    {
                        aspect.Targets.Add(new AspectTarget(attributeTypeString, AspectTargetType.Attribute));
                    }
                    else
                    {
                        throw new Exception(
                                  string.Format("Attribute type '{0}' was not found!", attributeTypeString));
                    }
                }
                else
                {
                    aspect.Targets.Add(new AspectTarget(attributeType, AspectTargetType.Attribute));
                }
            }

            if (settingsNode.Attributes["target-interface"] != null)
            {
                string interfaceTypeString = settingsNode.Attributes["target-interface"].Value;
                aspect = new GenericAspect(aspectName, mixins, pointcuts);

                Type interfaceType = Type.GetType(interfaceTypeString);
                if (interfaceType == null)
                {
                    if (useTypePlaceHolders)
                    {
                        aspect.Targets.Add(new AspectTarget(interfaceTypeString, AspectTargetType.Interface));
                    }
                    else
                    {
                        throw new Exception(
                                  string.Format("Type '{0}' was not found!", interfaceTypeString));
                    }
                }
                else
                {
                    aspect.Targets.Add(new AspectTarget(interfaceType, AspectTargetType.Interface));
                }
            }

            foreach (AspectTarget target in targets)
            {
                aspect.Targets.Add(target);
            }

            return(aspect);
        }
Ejemplo n.º 15
0
 public PresentationMixin(IGenericAspect aspect, string mixin)
 {
     this.aspect   = aspect;
     this.typeName = mixin;
 }
Ejemplo n.º 16
0
 public PresentationMixin(IGenericAspect aspect)
 {
     this.aspect = aspect;
 }
        /// <summary>
        /// return a configured <c>IEngine</c> from an xml element.
        /// </summary>
        /// <param name="xmlRoot">xml node to deserialize</param>
        /// <returns>a configured <c>IEngine</c></returns>
        public IEngine Configure(XmlElement xmlRoot)
        {
            Engine engine = new Engine("App.Config");

            XmlElement o = xmlRoot;

            if (o == null)
            {
                return(engine);
            }


            foreach (XmlNode settingsNode in o)
            {
                if (settingsNode.Name == "aspect")
                {
                    IList pointcuts = new ArrayList();
                    IList mixins    = new ArrayList();

                    string aspectName = settingsNode.Attributes["name"].Value;


                    foreach (XmlNode aspectNode in settingsNode)
                    {
                        if (aspectNode.Name == "pointcut")
                        {
                            IList interceptors = new ArrayList();

                            foreach (XmlNode pointcutNode in aspectNode)
                            {
                                if (pointcutNode.Name == "interceptor")
                                {
                                    string typeString      = pointcutNode.Attributes["type"].Value;
                                    Type   interceptorType = Type.GetType(typeString);
                                    if (interceptorType == null)
                                    {
                                        throw new Exception(
                                                  string.Format("Interceptor type '{0}' was not found!", typeString));
                                    }
                                    object interceptor = Activator.CreateInstance(interceptorType);
                                    interceptors.Add(interceptor);
                                }
                            }

                            IPointcut pointcut = null;
                            if (aspectNode.Attributes["target-signature"] != null)
                            {
                                string targetMethodSignature = aspectNode.Attributes["target-signature"].Value;
                                pointcut = new SignaturePointcut(targetMethodSignature, interceptors);
                            }

                            if (aspectNode.Attributes["target-attribute"] != null)
                            {
                                string attributeTypeString = aspectNode.Attributes["target-attribute"].Value;
                                Type   attributeType       = Type.GetType(attributeTypeString);
                                if (attributeType == null)
                                {
                                    throw new Exception(
                                              string.Format("Attribute type '{0}' was not found!", attributeTypeString));
                                }

                                pointcut = new AttributePointcut(attributeType, interceptors);
                            }


                            pointcuts.Add(pointcut);
                        }

                        if (aspectNode.Name == "mixin")
                        {
                            string typeString = aspectNode.Attributes["type"].Value;
                            Type   mixinType  = Type.GetType(typeString);
                            if (mixinType == null)
                            {
                                throw new Exception(string.Format("Mixin type '{0}' was not found!", typeString));
                            }
                            mixins.Add(mixinType);
                        }
                    }

                    IGenericAspect aspect = null;

                    if (settingsNode.Attributes["target-signature"] != null)
                    {
                        string targetTypeSignature = settingsNode.Attributes["target-signature"].Value;
                        aspect = new SignatureAspect(aspectName, targetTypeSignature, mixins, pointcuts);
                    }

                    if (settingsNode.Attributes["target-attribute"] != null)
                    {
                        string attributeTypeString = settingsNode.Attributes["target-attribute"].Value;
                        Type   attributeType       = Type.GetType(attributeTypeString);

                        aspect = new AttributeAspect(aspectName, attributeType, mixins, pointcuts);
                    }

                    engine.Configuration.Aspects.Add(aspect);
                }
            }


            return(engine);
        }