コード例 #1
0
ファイル: Data.cs プロジェクト: Rhett2014/AjaxFramework
        public JsonData Get_Data(HttpRequestDescription http)
        {
            id++;
            DataTable dt = new DataTable("dt");
            dt.Columns.Add("USER_ID");
            dt.Columns.Add("USER_NAME_");

            DataRow row = dt.NewRow();
            row["USER_ID"] = 1;
            row["USER_NAME_"] = "tom";
            dt.Rows.Add(row);

            DataRow row2 = dt.NewRow();
            row2["USER_ID"] = 2;
            row2["USER_NAME_"] = "peter";
            dt.Rows.Add(row2);
            IDictionary<string, object> dict = new Dictionary<string, object>();

            dict.Add("name", "tom");
            dict.Add("cls", dt);

            string json = JsonMapper.ToJson(dict);
            //return dt;
            JsonData jd = JsonMapper.ToObject(json);
            return jd;
            /*return new JsonpResult()
            {
                JsonpKey = "1235",
                JsonpData = dt
            };*/
        }
コード例 #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="currentHttpRequest">当前Http请求</param>
        public ParameterHelper(HttpRequestDescription currentHttpRequest)
        {
            if (currentHttpRequest == null)
            {
                throw new ArgumentNullException("currentHttpRequest");
            }

            this._currentHttpRequest = currentHttpRequest;
        }
コード例 #3
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="currentHttpRequest">当前Http请求</param>
        public ParameterHelper(HttpRequestDescription currentHttpRequest)
        {
            if (currentHttpRequest == null)
            {
                throw new ArgumentNullException("currentHttpRequest");
            }

            this._currentHttpRequest = currentHttpRequest;
        }
コード例 #4
0
ファイル: MethodHelper.cs プロジェクト: mtfnx/AjaxFramework
        /// <summary>
        /// 初始化方法
        /// </summary>
        /// <exception cref="Ajax404Exception">没有找到页面</exception>
        public void InitMethod()
        {
            CustomMethodInfo customMethodInfo = MethodCache.GetMethodCache(this._methodPathInfo.ToString());

            #region 获取该方法
            if (customMethodInfo == null)
            {
                #region 如果缓存中不存在 将会反射重新获取方法信息 并且记录缓存
                customMethodInfo = ReflectionHelper.GetMethodBaseInfo(this._methodPathInfo, MethodCache.BINDING_ATTR);
                if (customMethodInfo == null)
                {
                    throw new Ajax404Exception(string.Format("没有找到页面{0}", this._methodPathInfo.MethodName));
                }
                else
                {
                    //添加进缓存
                    MethodCache.AddMethodCache(_methodPathInfo.ToString(), customMethodInfo);
                }
                #endregion
            }
            #endregion

            #region 判断该方法是否有 自定义网络访问的webMethodAttr的特性了 如果没有此特性 根本不给此方法
            if (customMethodInfo.CurWebMethodAttr == null)
            {
                //没有该特性
                throw new Ajax404Exception("没有找到此页面");
            }
            else
            {
                //实例化网络请求方法的一些信息  用于传给特性使用
                _httpRequestDescription = new HttpRequestDescription
                {
                    Context           = this._context,
                    WebParameters     = customMethodInfo.CurWebMethodAttr.GetWebParameters(this._context),
                    CurrentMethodInfo = customMethodInfo
                };
            }
            #endregion

            this.CurCustomMethodInfo = customMethodInfo;
        }
コード例 #5
0
        /// <summary>
        /// 得到方法的实例 如果没有得到 则返回空 
        /// </summary>
        /// <param name="errMsg">获取失败返回的错误信息</param>
        /// <returns></returns>
        public CustomMethodInfo GetMethod()
        {
            CustomMethodInfo customMethodInfo = null;

            #region 获取该方法

            if (_idictMethod.Keys.Contains(this.DictKey))
            {
                #region 存在缓存中 直接从缓存中取得
                //如果该方法被访问过 存在该字典中
                customMethodInfo = _idictMethod[this.DictKey];
                //更新执行时间
                customMethodInfo.LastUpdateTime = DateTime.Now;
                //访问次数加1
                customMethodInfo.Count++;
                //将调用后的信息反写进去
                _idictMethod[this.DictKey] = customMethodInfo;
                #endregion
            }
            else {
                #region 如果缓存中不存在 将会反射重新获取方法信息 并且记录缓存
                customMethodInfo = this.GetMethodBaseInfo();
                if (customMethodInfo == null)
                {
                    throw new MethodNotFoundOrInvalidException(string.Format("没有找到方法{0}", this._methodPathInfo.MethodName));
                }
                else
                {
                    #region 初始化方法的一些信息
                    //特性列表
                    customMethodInfo.AttrList = ReflectionHelper.GetAttributes<ValidateAttr>(customMethodInfo.Method);
                    //参数列表
                    customMethodInfo.ParamterInfos = customMethodInfo.Method.GetParameters();
                    //返回值类型

                    customMethodInfo.RetureType = customMethodInfo.Method.ReturnType;
                    //方法最后的更新时间
                    customMethodInfo.LastUpdateTime = DateTime.Now;
                    //方法的执行次数
                    customMethodInfo.Count = 1;
                    #endregion

                    #region 加了双重锁  防止死锁掉 将该方法加入缓存
                    //通过了特性的检测
                    if (!_idictMethod.Keys.Contains(this.DictKey))
                    {
                        lock (obj)
                        {
                            //防止在锁的时候 其他用户已经添加了键值
                            if (!_idictMethod.Keys.Contains(this.DictKey))
                            {
                                //将 此方法的信息记录到静态字典中 以便下次从内存中调用
                                _idictMethod.Add(this.DictKey, customMethodInfo);
                            }
                        }
                    }
                    #endregion

                }
                #endregion
            }
            #endregion

            #region 判断该方法是否有 自定义网络访问的webMethodAttr的特性了
            WebMethodAttr webMethodAttr = customMethodInfo.AttrList.Find(x => x is WebMethodAttr) as WebMethodAttr;
            if (webMethodAttr == null)
            {
                //没有该特性
                throw new MethodNotFoundOrInvalidException("此方法并不是网络方法,无法直接访问");
            }
            else
            {

                //实例化网络请求方法的一些信息  用于传给特性使用
                this._httpRequestDescription=new HttpRequestDescription{
                 Context=this._context,
                  WebParameters=webMethodAttr.GetWebParameters(this._context),
                   CurrentMethodInfo=customMethodInfo
                };
            }
            #endregion

            #region 验证该方法的特性
            if (!CheckAttribute(customMethodInfo.AttrList))
            {
                //检测失败 将此方法置空掉
                customMethodInfo = null;
            }
            #endregion

            return customMethodInfo;
        }
コード例 #6
0
        /// <summary>
        /// 初始化方法 
        /// </summary>
        /// <exception cref="Ajax404Exception">没有找到页面</exception>
        public void InitMethod()
        {
            CustomMethodInfo customMethodInfo = MethodCache.GetMethodCache(this._methodPathInfo.ToString());

            #region 获取该方法
            if (customMethodInfo == null)
            {
                #region 如果缓存中不存在 将会反射重新获取方法信息 并且记录缓存
                customMethodInfo = ReflectionHelper.GetMethodBaseInfo(this._methodPathInfo, MethodCache.BINDING_ATTR);
                if (customMethodInfo == null)
                {
                    throw new Ajax404Exception(string.Format("没有找到页面{0}", this._methodPathInfo.MethodName));
                }
                else
                {
                    //添加进缓存
                    MethodCache.AddMethodCache(_methodPathInfo.ToString(), customMethodInfo);

                }
                #endregion
            }
            #endregion

            #region 判断该方法是否有 自定义网络访问的webMethodAttr的特性了 如果没有此特性 根本不给此方法
            if (customMethodInfo.CurWebMethodAttr == null)
            {
                //没有该特性
                throw new Ajax404Exception("没有找到此页面");
            }
            else
            {

                //实例化网络请求方法的一些信息  用于传给特性使用
                _httpRequestDescription = new HttpRequestDescription
                {
                    Context = this._context,
                    WebParameters = customMethodInfo.CurWebMethodAttr.GetWebParameters(this._context),
                    CurrentMethodInfo = customMethodInfo
                };

            }
            #endregion

            this.CurCustomMethodInfo=customMethodInfo;
        }