Example #1
0
        /// <summary>
        /// 执行,按实际结果返回
        /// </summary>
        /// <param name="letter">客户端递交的参数信息</param>
        /// <returns></returns>
        public static object Exec(Letter letter)
        {
            //1.创建对象,即$api.get("account/single")中的account
            object execObj = ExecuteMethod.CreateInstance(letter);
            //2.获取要执行的方法,即$api.get("account/single")中的single
            MethodInfo method = getMethod(execObj.GetType(), letter);

            //3#.验证方法的特性,一是验证Http动词,二是验证是否登录后操作,三是验证权限
            //----验证Http谓词访问限制
            HttpAttribute.Verify(letter.HTTP_METHOD, method);
            //LoginAttribute.Verify(method);
            //----范围控制,本机或局域网,或同域
            bool isRange = RangeAttribute.Verify(letter, method);
            //----验证是否需要登录
            LoginAttribute loginattr = LoginAttribute.Verify(method);


            //4.构建执行该方法所需要的参数
            object[] parameters = getInvokeParam(method, letter);
            //5.执行方法,返回结果
            object objResult = method.Invoke(execObj, parameters);

            //将执行结果写入日志
            LoginAttribute.LogWrite(loginattr, objResult);
            return(objResult);
        }
Example #2
0
        /// <summary>
        /// 执行,按实际结果返回
        /// </summary>
        /// <param name="letter">客户端递交的参数信息</param>
        /// <returns></returns>
        public static object Exec(Letter letter)
        {
            //1.创建对象,即$api.get("account/single")中的account
            IViewAPI execObj = ExecuteMethod.CreateInstance(letter);
            //2.获取要执行的方法,即$api.get("account/single")中的single
            MethodInfo method = getMethod(execObj.GetType(), letter);

            //清除缓存
            if (letter.HTTP_METHOD.Equals("put", StringComparison.CurrentCultureIgnoreCase))
            {
                CacheAttribute.Remove(method, letter);
            }
            //3#.验证方法的特性,一是验证Http动词,二是验证是否登录后操作,三是验证权限
            //----验证Http谓词访问限制
            HttpAttribute.Verify(letter.HTTP_METHOD, method);
            //LoginAttribute.Verify(method);
            //----范围控制,本机或局域网,或同域
            bool isRange = RangeAttribute.Verify(method, letter);
            //----验证是否需要登录
            LoginAttribute loginattr = LoginAttribute.Verify(method, letter);

            //----清理参数值中的html标签,默认全部清理,通过设置not参数不过虑某参数
            HtmlClearAttribute.Clear(method, letter);


            //4.构建执行该方法所需要的参数
            object[] parameters = getInvokeParam(method, letter);
            //5.执行方法,返回结果
            object objResult = null;    //结果
            //只有get方式时,才使用缓存
            CacheAttribute cache = null;

            //if (letter.HTTP_METHOD.Equals("put", StringComparison.CurrentCultureIgnoreCase))
            //    CacheAttribute.Remove(method, letter);
            if (letter.HTTP_METHOD.Equals("get", StringComparison.CurrentCultureIgnoreCase))
            {
                cache = CacheAttribute.GetAttr <CacheAttribute>(method);
            }
            if (cache != null)
            {
                objResult = CacheAttribute.GetResult(method, letter);
                if (objResult == null)
                {
                    objResult = method.Invoke(execObj, parameters);
                    CacheAttribute.Insert(cache.Expires, method, letter, objResult);
                }
            }
            else
            {
                objResult = method.Invoke(execObj, parameters);
            }
            //将执行结果写入日志
            LoginAttribute.LogWrite(loginattr, objResult);
            return(objResult);
        }
Example #3
0
        /// <summary>
        /// 执行,按实际结果返回
        /// </summary>
        /// <param name="letter">客户端递交的参数信息</param>
        /// <returns></returns>
        public static object Exec(Letter letter)
        {
            //1.创建对象,即$api.get("account/single")中的account
            object execObj = ExecuteMethod.CreateInstance(letter);
            //2.获取要执行的方法,即$api.get("account/single")中的single
            MethodInfo method = getMethod(execObj.GetType(), letter);

            //3#.验证方法的特性,一是验证Http动词,二是验证是否登录后操作,三是验证权限

            //4.构建执行该方法所需要的参数
            object[] parameters = getInvokeParam(method, letter);
            //5.执行方法
            return(method.Invoke(execObj, parameters));
        }
Example #4
0
        /// <summary>
        /// 执行,按实际结果返回
        /// </summary>
        /// <param name="letter">客户端递交的参数信息</param>
        /// <returns></returns>
        public static object Exec(Letter letter)
        {
            //1.创建对象,即$api.get("account/single")中的account
            object execObj = ExecuteMethod.CreateInstance(letter);
            //2.获取要执行的方法,即$api.get("account/single")中的single
            MethodInfo method = getMethod(execObj.GetType(), letter);

            //3#.验证方法的特性,一是验证Http动词,二是验证是否登录后操作,三是验证权限
            //----验证Http谓词访问限制
            HttpAttribute.Verify(letter.HTTP_METHOD, method);
            //LoginAttribute.Verify(method);
            //----范围控制,本机或局域网,或同域
            bool isRange = RangeAttribute.Verify(letter, method);
            //----验证是否需要登录
            LoginAttribute loginattr = LoginAttribute.Verify(method);


            //4.构建执行该方法所需要的参数
            object[] parameters = getInvokeParam(method, letter);
            //5.执行方法,返回结果
            object objResult = null;    //结果
            //只有get方式时,才使用缓存
            CacheAttribute cache = null;

            if (letter.HTTP_METHOD == "GET")
            {
                cache = CacheAttribute.GetAttr <CacheAttribute>(method);
            }
            if (cache != null)
            {
                objResult = CacheAttribute.GetResult(method, letter);
                if (objResult == null)
                {
                    objResult = method.Invoke(execObj, parameters);
                    CacheAttribute.Insert(cache.Expires, method, letter, objResult);
                }
            }
            else
            {
                objResult = method.Invoke(execObj, parameters);
            }
            //将执行结果写入日志
            LoginAttribute.LogWrite(loginattr, objResult);
            return(objResult);
        }