Esempio n. 1
0
        bool IsMatchType(InterceptionRule rule, Type type)
        {
            var namespaceses = this.GetNameSpaceMatchs(type.FullName);

            foreach (var key in namespaceses)
            {
                //Aquirrel.* Aquirrel.#

                //Aquirrel==Aquirrel true
                if (rule.NameSpace == key)
                {
                    return(true);
                }
                //Aquirrel.# ==Aquirrel.aa.bb true
                if (rule.NameSpace.Last() == '#' && rule.NameSpace.TrimEnd('.', '#') == key)
                {
                    return(true);
                }
                //Aquirrel.* ==Aquirrel.aa true
                if (rule.NameSpace.Last() == '*' && rule.NameSpace.TrimEnd('.', '*') == key)
                {
                    var ruleD = rule.NameSpace.Split('.').Length;
                    var keyD  = type.FullName.Split('.').Length;
                    if (ruleD == keyD)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        void ReadyConf()
        {
            this.Rules = this.configuration.GetSection("Rules").GetChildren().Select(conf =>
            {
                InterceptionRule rule = new InterceptionRule();
                rule.NameSpace        = conf["NameSpace"];
                rule.MethodName       = conf["MethodName"];
                if (conf["MethoMmodifiers"] == "" || conf["MethoMmodifiers"] == "*")
                {
                    rule.MethoMmodifiers = new[] { "public", "private", "internal", "protected", "internal protected" }
                }
                ;
                else
                {
                    //rule.MethoMmodifiers = (MethoMmodifiers)Enum.Parse(typeof(MethoMmodifiers), conf["MethoMmodifiers"].Split('|').Where(p => p.IsNotNullOrEmpty()).Select(p => "@" + p).ConcatEx("|"));
                    rule.MethoMmodifiers = conf["MethoMmodifiers"].Split('|');
                }
                rule.Ref = conf.GetSection("Ref").Get <string[]>();
                return(rule);
            }).ToArray();

            List <InterceptorSettingInterceptor> _interceptors = new List <InterceptorSettingInterceptor>();

            ConfigurationBinder.Bind(configuration.GetSection("Interceptors"), _interceptors);
            this.Interceptors = _interceptors.ToArray();
        }
Esempio n. 3
0
        bool IsMatchMethod(InterceptionRule rule, MethodInfo methodInfo)
        {
            if (methodInfo.IsDefined(typeof(UnacceptableAttribute)))
            {
                return(false);
            }
            if (!this.IsMatchType(rule, methodInfo.DeclaringType))
            {
                return(false);
            }

            if (rule.MethodName == "*")
            {
                return(true);
            }
            Regex reg = new Regex(rule.MethodName);

            if (!reg.IsMatch(methodInfo.Name))
            {
                return(false);
            }

            //{ "public", "private", "internal", "protected", "internal protected", };
            if (methodInfo.IsPublic && rule.MethoMmodifiers.Contains("public"))
            {
                return(true);
            }
            if (methodInfo.IsPrivate && rule.MethoMmodifiers.Contains("private"))
            {
                return(true);
            }
            if (methodInfo.IsAssembly && rule.MethoMmodifiers.Contains("internal"))
            {
                return(true);
            }
            if (methodInfo.IsFamily && rule.MethoMmodifiers.Contains("protected"))
            {
                return(true);
            }
            if (methodInfo.IsFamilyOrAssembly && rule.MethoMmodifiers.Contains("internal protected"))
            {
                return(true);
            }
            return(false);
        }