Esempio n. 1
0
        /// <summary>
        /// 取得相应的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);
            Type   type     = paramType.GetGenericArguments()[0];          //得到泛型的具体类型
            string jsonList = currentHttpRequest.WebParameters[paramName]; //得到json的传参

            if (string.IsNullOrEmpty(jsonList))
            {
                return(null);
            }


            PropertyInfo[] propertys = type.GetPropertyInfos(GetRequestDataStrategy.bindingFlags); //反射该类型的属性

            var        batchJson = typeof(BatchJson <>).MakeGenericType(type).CreateInstace();     //动态创建所指定的泛型类型
            MethodInfo addMethod = GetAddMethodInfo(typeof(BatchJson <>).MakeGenericType(type));   //得到batch泛型的添加方法

            JsonData jsonData = JsonMapper.ToObject(jsonList);                                     //反序列化Json数组数据得到JsonData

            for (int i = 0, count = jsonData.Count; i < count; i++)
            {
                //如果反序列化得到的数据位object 型,在litJson中为Dict型
                if (jsonData[0].IsObject)
                {
                    //将该类型指定为一个新字典
                    IDictionary <string, JsonData> newDict = jsonData[i].Inst_Object;

                    string state = string.Empty;
                    if (newDict.ContainsKey(STATE_KEY))
                    {
                        //如果有state标志 取得该值
                        state = newDict["_state"].ToString();
                    }

                    #region 取得实体类的值
                    object t = type.CreateInstace();//动态创建实体的实例
                    for (int j = 0; j < propertys.Length; j++)
                    {
                        if (newDict.Keys.Contains(propertys[j].Name))
                        {
                            //从键值对里面得到值
                            string val = newDict[propertys[j].Name].ToString();

                            if (propertys[j].PropertyType.IsSampleType() && propertys[j].CanWrite)
                            {
                                //如果是简单的类型 并且为可写  就将值进行转换
                                object obj = propertys[j].PropertyType.ConvertSampleTypeValue(val);
                                propertys[j].SetValue(t, obj, null);
                            }
                            //不是  还不是简单地类型 就不再进行操作 直接舍弃
                        }
                    }
                    #endregion
                    //执行add的方法  将实体方法泛型类中
                    addMethod.Invoke(batchJson, new object[] { state, t });
                }
            }

            return(batchJson);
        }
Esempio n. 2
0
        /// <summary>
        /// 取得相应的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);
            HttpPostedFile file = currentHttpRequest.Context.Request.Files[paramName];

            return(file);
        }
Esempio n. 3
0
        public async Task <HttpRequestDescription> GetRequestDescriptionAsync(HttpRequest request)
        {
            var HeadersToIgnore = Options.Value.HeadersToIgnore.ToLower().Split('|').ToList();

            HttpRequestDescription requestDescription = new HttpRequestDescription();

            requestDescription.Body = await ReadBodyFirstCharsAsync(request, Options.Value.RequestBodyMaxLength);

            requestDescription.Method      = request.Method;
            requestDescription.SourceIp    = request.HttpContext.Connection.RemoteIpAddress.ToString();
            requestDescription.Path        = $"{request.Path}{(string.IsNullOrEmpty(request.QueryString.ToString()) ? "" : request.QueryString.ToString())}";
            requestDescription.Timestamp   = DateTime.UtcNow;
            requestDescription.QueryParams = new List <KeyValuePair <string, string> >();
            requestDescription.Headers     = new List <KeyValuePair <string, string> >();

            foreach (var param in request.Query)
            {
                requestDescription.QueryParams.Add(new KeyValuePair <string, string>(param.Key, param.Value));
            }

            foreach (var header in request.Headers)
            {
                if (!HeadersToIgnore.Contains(header.Key.ToLower()))
                {
                    requestDescription.Headers.Add(new KeyValuePair <string, string>(header.Key, header.Value));
                }
            }
            return(requestDescription);
        }
Esempio n. 4
0
        /// <summary>
        /// 取得简单数据类型的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);

            //转为相应的数据类型 进行返回
            return paramType.ConvertSampleTypeValue(currentHttpRequest.WebParameters[paramName]);
        }
Esempio n. 5
0
        /// <summary>
        /// 取得简单数据类型的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);


            string enumValue = currentHttpRequest.WebParameters[paramName];

            if (string.IsNullOrEmpty(enumValue))
            {
                //枚举值为空
                return(null);
            }

            /***************************************
             *  这里重定义枚举的值 是为了转成int整形之后
             *  能够使用枚举的Int类型区判断他是否存在该定义枚举重
             * ***************************************/
            object objValue = enumValue;

            if (Regex.IsMatch(enumValue, @"^\d+$"))
            {
                objValue = Convert.ToInt32(enumValue);
            }

            if (!Enum.IsDefined(paramType, objValue))
            {
                //不在定义范围内
                return(null);
            }

            //转为相应的枚举类型 进行返回
            return(Enum.Parse(paramType, enumValue, true));
        }
Esempio n. 6
0
        protected async Task <HttpRequestDescription> GetRequestDescription(HttpRequest request)
        {
            HttpRequestDescription requestDescription = new HttpRequestDescription();

            requestDescription.Body = await ReadBodyFirstCharsAsync(request, Options.Value.RequestBodyMaxLength);

            //requestDescription.Body = await new StreamReader(request.Body).ReadToEndAsync();
            requestDescription.Method      = request.Method;
            requestDescription.SourceIp    = request.HttpContext.Connection.RemoteIpAddress.ToString();
            requestDescription.Path        = $"{request.Path}{(string.IsNullOrEmpty(request.QueryString.ToString()) ? "" : request.QueryString.ToString())}";
            requestDescription.Timestamp   = DateTime.UtcNow;
            requestDescription.QueryParams = new List <KeyValuePair <string, string> >();
            requestDescription.Headers     = new List <KeyValuePair <string, string> >();

            foreach (var param in request.Query)
            {
                requestDescription.QueryParams.Add(new KeyValuePair <string, string>(param.Key, param.Value));
            }

            foreach (var header in request.Headers)
            {
                requestDescription.Headers.Add(new KeyValuePair <string, string>(header.Key, header.Value));
            }

            return(requestDescription);
        }
Esempio n. 7
0
        /// <summary>
        /// 取得简单数据类型的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);

            string enumValue=currentHttpRequest.WebParameters[paramName];
            if (string.IsNullOrEmpty(enumValue))
            {
                //枚举值为空
                return null;
            }

            /***************************************
             *  这里重定义枚举的值 是为了转成int整形之后
             *  能够使用枚举的Int类型区判断他是否存在该定义枚举重
             * ***************************************/
            object objValue = enumValue;
            if (Regex.IsMatch(enumValue, @"^\d+$"))
            {
                objValue = Convert.ToInt32(enumValue);
            }

            if (!Enum.IsDefined(paramType, objValue))
            {
                //不在定义范围内
                return null;
            }

            //转为相应的枚举类型 进行返回
            return Enum.Parse(paramType, enumValue, true);
        }
        /// <summary>
        /// 取得简单数据类型的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);

            //转为相应的数据类型 进行返回
            return paramType.ConvertSampleTypeValue(currentHttpRequest.WebParameters[paramName]);
            
        }
Esempio n. 9
0
 public void Add(HttpRequestDescription requestDescription)
 {
     RequestHistoryItems.Add(requestDescription);
     if (RequestHistoryItems.Count > Options.Value.RequestBinMaxSize)
     {
         RequestHistoryItems = RequestHistoryItems.Skip(1).ToList();
     }
 }
Esempio n. 10
0
        /// <summary>
        /// 取得相应的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);
            Type type = paramType.GetGenericArguments()[0];//得到泛型的具体类型
            string jsonList = currentHttpRequest.WebParameters[paramName];//得到json的传参
            if (string.IsNullOrEmpty(jsonList))
            {
                return null;
            }

            PropertyInfo[] propertys = type.GetPropertyInfos(GetRequestDataStrategy.bindingFlags);//反射该类型的属性

            var batchJson = typeof(BatchJson<>).MakeGenericType(type).CreateInstace();//动态创建所指定的泛型类型
            MethodInfo addMethod = GetAddMethodInfo(typeof(BatchJson<>).MakeGenericType(type));//得到batch泛型的添加方法

            JsonData jsonData = JsonMapper.ToObject(jsonList);//反序列化Json数组数据得到JsonData
            for (int i = 0, count = jsonData.Count; i < count; i++)
            {
                //如果反序列化得到的数据位object 型,在litJson中为Dict型
                if (jsonData[0].IsObject)
                {
                    //将该类型指定为一个新字典
                    IDictionary<string, JsonData> newDict = jsonData[i].Inst_Object;

                    string state = string.Empty;
                    if (newDict.ContainsKey(STATE_KEY))
                    {
                        //如果有state标志 取得该值
                        state = newDict["_state"].ToString();
                    }

                    #region 取得实体类的值
                    object t = type.CreateInstace();//动态创建实体的实例
                    for (int j = 0; j < propertys.Length; j++)
                    {
                        if (newDict.Keys.Contains(propertys[j].Name))
                        {
                            //从键值对里面得到值
                            string val = newDict[propertys[j].Name].ToString();

                            if (propertys[j].PropertyType.IsSampleType() && propertys[j].CanWrite)
                            {
                                //如果是简单的类型 并且为可写  就将值进行转换
                                object obj = propertys[j].PropertyType.ConvertSampleTypeValue(val);
                                propertys[j].SetValue(t, obj, null);
                            }
                            //不是  还不是简单地类型 就不再进行操作 直接舍弃
                        }
                    }
                    #endregion
                    //执行add的方法  将实体方法泛型类中
                    addMethod.Invoke(batchJson, new object[] { state, t });
                }
            }

            return batchJson;
        }
        /// <summary>
        /// Encodes string values on the HttpRequestBinHistory to Html so it can be rendered properly
        /// Sorts requests by Timestamp descending
        /// </summary>
        /// <param name="requestBinHistory"></param>
        /// <returns></returns>
        private HttpRequestBinHistory PrepareBinHistoryForHtml(HttpRequestBinHistory requestBinHistory)
        {
            if (requestBinHistory == null)
            {
                return(null);
            }
            if (requestBinHistory.RequestHistoryItems == null)
            {
                return(requestBinHistory);
            }

            var htmlEncodedRequestBinHistory = new HttpRequestBinHistory();

            htmlEncodedRequestBinHistory.BinId               = HttpUtility.HtmlEncode(requestBinHistory.BinId);
            htmlEncodedRequestBinHistory.BinUrl              = HttpUtility.HtmlEncode(requestBinHistory.BinUrl);
            htmlEncodedRequestBinHistory.Timestamp           = requestBinHistory.Timestamp;
            htmlEncodedRequestBinHistory.ErrorMessage        = HttpUtility.HtmlEncode(requestBinHistory.ErrorMessage);
            htmlEncodedRequestBinHistory.RequestHistoryItems = new List <HttpRequestDescription>();
            foreach (var request in requestBinHistory.RequestHistoryItems.OrderByDescending(i => i.Timestamp).ToList())
            {
                var htmlEncodedRequest = new HttpRequestDescription();
                htmlEncodedRequest.Body        = HttpUtility.HtmlEncode(request.Body);
                htmlEncodedRequest.Method      = HttpUtility.HtmlEncode(request.Method);
                htmlEncodedRequest.Path        = HttpUtility.HtmlEncode(request.Path);
                htmlEncodedRequest.SourceIp    = HttpUtility.HtmlEncode(request.SourceIp);
                htmlEncodedRequest.Timestamp   = request.Timestamp;
                htmlEncodedRequest.QueryParams = new List <KeyValuePair <string, string> >();
                htmlEncodedRequest.Headers     = new List <KeyValuePair <string, string> >();
                foreach (var queryParam in request.QueryParams)
                {
                    htmlEncodedRequest.QueryParams.Add(new KeyValuePair <string, string>(HttpUtility.HtmlEncode(queryParam.Key), HttpUtility.HtmlEncode(queryParam.Value)));
                }
                foreach (var header in request.Headers)
                {
                    htmlEncodedRequest.Headers.Add(new KeyValuePair <string, string>(HttpUtility.HtmlEncode(header.Key), HttpUtility.HtmlEncode(header.Value)));
                }
                htmlEncodedRequestBinHistory.RequestHistoryItems.Add(htmlEncodedRequest);
            }
            htmlEncodedRequestBinHistory.Settings = new HttpRequestBinHistory.HttpRequestBinSettings();
            htmlEncodedRequestBinHistory.Settings.RequestBinProvider           = requestBinHistory.Settings.RequestBinProvider;
            htmlEncodedRequestBinHistory.Settings.RequestBinRenderer           = requestBinHistory.Settings.RequestBinRenderer;
            htmlEncodedRequestBinHistory.Settings.RequestBinMaxSize            = requestBinHistory.Settings.RequestBinMaxSize;
            htmlEncodedRequestBinHistory.Settings.RequestBodyMaxLength         = requestBinHistory.Settings.RequestBodyMaxLength;
            htmlEncodedRequestBinHistory.Settings.RequestBinSlidingExpiration  = requestBinHistory.Settings.RequestBinSlidingExpiration;
            htmlEncodedRequestBinHistory.Settings.RequestBinAbsoluteExpiration = requestBinHistory.Settings.RequestBinAbsoluteExpiration;

            return(htmlEncodedRequestBinHistory);
        }
Esempio n. 12
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">参数类型</param>
        /// <param name="currentHttpRequest">当前的详细请求</param>
        public GetRequestDataContext(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            if (currentHttpRequest == null)
            {
                throw new ArgumentNullException("当前的请求信息不能为空");
            }

            if (paramType == null)
            {
                throw new ArgumentNullException("参数类型不能为空!");
            }

            this._paramName          = paramName;
            this._paramType          = paramType;
            this._currentHttpRequest = currentHttpRequest;
            InitStrategy(paramType);
        }
Esempio n. 13
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">参数类型</param>
        /// <param name="currentHttpRequest">当前的详细请求</param>
        public GetRequestDataContext( string paramName, Type paramType,HttpRequestDescription currentHttpRequest)
        {
            if (currentHttpRequest == null)
            {
                throw new ArgumentNullException("当前的请求信息不能为空");
            }

            if (paramType == null)
            {
                throw new ArgumentNullException("参数类型不能为空!");
            }

            this._paramName = paramName;
            this._paramType = paramType;
            this._currentHttpRequest = currentHttpRequest;
            InitStrategy(paramType);
        }
Esempio n. 14
0
        /// <summary>
        /// 得到相应类型的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public virtual object GetValue(string paramName,Type paramType,HttpRequestDescription currentHttpRequest)
        {
            //验证参数名称是否为空
            if (string.IsNullOrEmpty(paramName))
            {
                throw new ArgumentNullException("paramName");
            }

            //验证当前类型是否为空
            if (paramType == null)
            {
                throw new ArgumentNullException("paramType");
            }

            //验证当前的请求详情是否为空
            if(currentHttpRequest==null)
            {
                throw new ArgumentNullException("currentHttpRequest");
            }
            return null;
        }
Esempio n. 15
0
        /// <summary>
        /// 得到相应类型的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public virtual object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            //验证参数名称是否为空
            if (string.IsNullOrEmpty(paramName))
            {
                throw new ArgumentNullException("paramName");
            }

            //验证当前类型是否为空
            if (paramType == null)
            {
                throw new ArgumentNullException("paramType");
            }

            //验证当前的请求详情是否为空
            if (currentHttpRequest == null)
            {
                throw new ArgumentNullException("currentHttpRequest");
            }
            return(null);
        }
Esempio n. 16
0
        /// <summary>
        /// 得到实体类的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName,Type paramType,HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType,currentHttpRequest);

            //得到该实体类的属性
            PropertyInfo[] propertys = paramType.GetPropertyInfos(GetRequestDataStrategy.bindingFlags);

            object t = paramType.CreateInstace();
            for (int i = 0; i < propertys.Length; i++)
            {
                if (propertys[i].CanWrite)
                {
                    //如果为可写时   尝试再次使用策略进行转化
                    GetRequestDataContext context = new GetRequestDataContext(propertys[i].Name, propertys[i].PropertyType, currentHttpRequest);

                    object obj = context.GetValue();
                    propertys[i].SetValue(t, obj, null);
                }
                //不是  还不是简单地类型 就不再进行操作 直接舍弃
            }
            return t;
        }
Esempio n. 17
0
        /// <summary>
        /// 得到实体类的值
        /// </summary>
        /// <param name="paramName">当前参数的名称</param>
        /// <param name="paramType">当前参数的类型</param>
        /// <param name="currentHttpRequest">当前的请求详情</param>
        /// <returns></returns>
        public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
        {
            base.GetValue(paramName, paramType, currentHttpRequest);

            //得到该实体类的属性
            PropertyInfo[] propertys = paramType.GetPropertyInfos(GetRequestDataStrategy.bindingFlags);

            object t = paramType.CreateInstace();

            for (int i = 0; i < propertys.Length; i++)
            {
                if (propertys[i].CanWrite)
                {
                    //如果为可写时   尝试再次使用策略进行转化
                    GetRequestDataContext context = new GetRequestDataContext(propertys[i].Name, propertys[i].PropertyType, currentHttpRequest);

                    object obj = context.GetValue();
                    propertys[i].SetValue(t, obj, null);
                }
                //不是  还不是简单地类型 就不再进行操作 直接舍弃
            }
            return(t);
        }
Esempio n. 18
0
        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
             * };*/
        }
Esempio n. 19
0
 /// <summary>
 /// 得到实体类的值
 /// </summary>
 /// <param name="paramName">当前参数的名称</param>
 /// <param name="paramType">当前参数的类型</param>
 /// <param name="currentHttpRequest">当前的请求详情</param>
 /// <returns></returns>
 public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
 {
     base.GetValue(paramName, paramType, currentHttpRequest);
     //在这里直接返回上下文
     return(currentHttpRequest.Context);
 }
Esempio n. 20
0
 /// <summary>
 /// 取得相应的值
 /// </summary>
 /// <param name="paramName">当前参数的名称</param>
 /// <param name="paramType">当前参数的类型</param>
 /// <param name="currentHttpRequest">当前的请求详情</param>
 /// <returns></returns>
 public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
 {
     base.GetValue(paramName, paramType, currentHttpRequest);
     HttpPostedFile file = currentHttpRequest.Context.Request.Files[paramName];
     return file;
 }
Esempio n. 21
0
 /// <summary>
 /// 得到实体类的值
 /// </summary>
 /// <param name="paramName">当前参数的名称</param>
 /// <param name="paramType">当前参数的类型</param>
 /// <param name="currentHttpRequest">当前的请求详情</param>
 /// <returns></returns>
 public override object GetValue(string paramName, Type paramType, HttpRequestDescription currentHttpRequest)
 {
     base.GetValue(paramName, paramType, currentHttpRequest);
     //在这里直接返回上下文
     return currentHttpRequest;
 }