예제 #1
0
파일: rx_field.cs 프로젝트: ruanxu/rx
 public rx_field(string key, object value, rx_entity entity)
 {
     this._base_value = value == DBNull.Value ? null : value;
     this._key        = key;
     this.value       = this._base_value;
     this.entity      = entity;
 }
예제 #2
0
파일: rx_field.cs 프로젝트: ruanxu/rx
 public rx_field(string key, object value, rx_entity entity, date_format_type date_format_type)
 {
     this.date_format_type = date_format_type;
     this._base_value      = value == DBNull.Value ? null : value;
     this._key             = key;
     this.value            = this._base_value;
     this.entity           = entity;
 }
예제 #3
0
파일: rx_field.cs 프로젝트: ruanxu/rx
 internal rx_field clone(rx_entity entity)
 {
     return(new rx_field(this.key, this.value, entity, this._date_format_type)
     {
         compare_symbol = this.compare_symbol,
         logic_symbol = this.logic_symbol,
         date_format_type = this.date_format_type,
         build_quote = this.build_quote,
         auto_remove = this.auto_remove
     });
 }
예제 #4
0
파일: rx_entity.cs 프로젝트: ruanxu/rx
        /// <summary>
        /// 克隆当前这个实体的对象
        /// </summary>
        /// <returns></returns>
        public rx_entity clone()
        {
            rx_entity obj = new rx_entity(this.entity_name)
            {
                command_type         = this.command_type,
                is_use_null          = this.is_use_null,
                _where_keys          = this._where_keys,
                _select_display_keys = this._select_display_keys,
            };

            foreach (string key in this.Keys)
            {
                obj[key] = this[key].clone();
            }
            return(obj);
        }
예제 #5
0
파일: rx_field.cs 프로젝트: ruanxu/rx
 /// <summary>
 /// 生成一个空的rx_field
 /// </summary>
 /// <param name="key"></param>
 /// <param name="entity"></param>
 /// <returns></returns>
 internal static rx_field empty(string key, rx_entity entity)
 {
     return(new rx_field(key, null, entity));
 }
예제 #6
0
        public void ProcessRequest(HttpContext context)
        {
            this.context = context;
            if (context.Request["rx_orm_addin_test"] == "rx_orm_addin_test")
            {
                response_write_json(new
                {
                    version          = rx_manager.version,
                    api_type         = "asp_net_handle",
                    i_rx_risk        = this is i_rx_risk,
                    i_rx_risk_proc   = this is i_rx_risk_proc,
                    i_rx_risk_update = this is i_rx_risk_update,
                    i_rx_risk_delete = this is i_rx_risk_delete,
                    i_rx_risk_insert = this is i_rx_risk_insert,
                    i_rx_sign        = this is i_rx_sign
                });
                return;
            }

            if (this is i_rx_sign && !sign_validate())
            {
                response_write_json(new dml_result("")
                {
                    result_code = dml_result_code.error,
                    message     = "sign 签名不正确"
                });
                return;
            }

            string rx_method = context.Request["rx_method"];

            if (rx_method == null || rx_method.Trim() == "")
            {
                response_write("该控制器继承了rx_handle,所以请按照规则或者rx_manager前端sdk进行调用!");
                return;
            }

            if (!(this is i_rx_risk))
            {
                throw new Exception("当前控制器或者handle必须继承i_rx_risk才能开启前端orm调用接口");
            }

            if (rx_manager.rx_function_md5.ContainsKey(rx_method))
            {
                if (!rx_manager.rx_function_md5[rx_method].Contains(context.Request["rx_function"]))
                {
                    response_write("检测到非法的调用,你是否调用了尝试修改rx_manager进行注入调用?");
                    return;
                }
            }


            List <MethodInfo> methods = rx_manager.method_list.Where(a => a.Name == rx_method).OrderByDescending(a => a.GetParameters().Length).ToList();

            if (methods.Count == 0)
            {
                response_write_json(new
                {
                    message = string.Format("rx_manager中不存在 {0} 这个静态方法", rx_method)
                });
            }
            JavaScriptSerializer jss = new JavaScriptSerializer();

            for (int i = 0; i < methods.Count; i++)
            {
                bool                        is_continue      = false;
                ParameterInfo[]             parameters       = methods[i].GetParameters();
                object[]                    input_parameters = new object[parameters.Length];
                Dictionary <string, object> result           = new Dictionary <string, object>();
                Dictionary <string, int>    ref_index        = new Dictionary <string, int>();
                for (int j = 0; j < parameters.Length; j++)
                {
                    if (context.Request[parameters[j].Name] == null && !parameters[j].ParameterType.IsByRef)
                    {
                        is_continue = true;
                        break;
                    }

                    if (parameters[j].ParameterType.IsByRef)
                    {
                        input_parameters[j] = Activator.CreateInstance(Type.GetType(parameters[j].ParameterType.FullName.Replace("&", "")));
                        result.Add(parameters[j].Name, null);
                        ref_index.Add(parameters[j].Name, j);
                    }
                    else if (parameters[j].ParameterType.IsAnsiClass && parameters[j].ParameterType.FullName.ToLower() == "system.string")
                    {
                        input_parameters[j] = context.Request[parameters[j].Name];
                    }
                    else if (parameters[j].ParameterType.IsEnum)
                    {
                        input_parameters[j] = Enum.Parse(parameters[j].ParameterType, context.Request[parameters[j].Name], true);
                    }
                    else if (parameters[j].ParameterType.FullName.ToLower() == "system.data.sqlclient.sqlparameter[]")
                    {
                        List <Dictionary <string, object> > dic_list = jss.Deserialize <List <Dictionary <string, object> > >(context.Request[parameters[j].Name]);
                        if (dic_list == null)
                        {
                            input_parameters[j] = null;
                            continue;
                        }
                        SqlParameter[] paras = new SqlParameter[dic_list.Count];
                        for (int k = 0; k < dic_list.Count; k++)
                        {
                            paras[k] = new SqlParameter(dic_list[k]["ParameterName"].ToString(), dic_list[k]["Value"].ToString())
                            {
                                Direction = dic_list[k]["Value"] == null ? ParameterDirection.Input : (ParameterDirection)Enum.Parse(typeof(ParameterDirection), dic_list[k]["Direction"].ToString(), true),
                                Size      = 9999999
                            };
                        }
                        input_parameters[j] = paras;
                    }
                    else if (parameters[j].ParameterType.FullName.ToLower() == "rx.rx_entity[]")
                    {
                        List <Dictionary <string, object> > dic_list = jss.Deserialize <List <Dictionary <string, object> > >(context.Request[parameters[j].Name]);
                        rx_entity[] entitys = new rx_entity[dic_list.Count];
                        for (int k = 0; k < dic_list.Count; k++)
                        {
                            entitys[k] = new rx_entity(dic_list[k]["entity_name"].ToString());
                            entitys[k].command_type        = (dml_command_type)Enum.Parse(typeof(dml_command_type), dic_list[k]["command_type"].ToString(), true);
                            entitys[k].is_use_null         = Convert.ToBoolean(dic_list[k]["is_use_null"]);
                            entitys[k].where_keys          = dic_list[k]["where_keys"] as List <string>;
                            entitys[k].select_display_keys = dic_list[k]["select_display_keys"] as string;
                            ArrayList rx_fields = (ArrayList)dic_list[k]["rx_fields"];
                            for (int l = 0; l < rx_fields.Count; l++)
                            {
                                Dictionary <string, object> rx_field = (Dictionary <string, object>)rx_fields[l];
                                entitys[k].Add(
                                    rx_field["key"].ToString(),
                                    new rx_field(
                                        rx_field["key"].ToString(),
                                        rx_field["value"],
                                        entitys[k],
                                        (date_format_type)Enum.Parse(typeof(date_format_type), rx_field["date_format_type"].ToString(), true)
                                        )
                                {
                                    compare_symbol = (compare_symbol)Enum.Parse(typeof(compare_symbol), rx_field["compare_symbol"].ToString(), true),
                                    logic_symbol   = (logic_symbol)Enum.Parse(typeof(logic_symbol), rx_field["logic_symbol"].ToString(), true),
                                    auto_remove    = Convert.ToBoolean(rx_field["auto_remove"]),
                                    build_quote    = Convert.ToBoolean(rx_field["build_quote"])
                                }
                                    );
                            }
                            entitys[k].select_display_keys = dic_list[k]["select_display_keys"] == null ? null : dic_list[k]["select_display_keys"].ToString();
                            entitys[k].where_keys          = dic_list[k]["where_keys"] == null ? null : ((ArrayList)dic_list[k]["where_keys"]).OfType <string>().ToList();
                        }

                        input_parameters[j] = entitys;
                    }
                    else if (parameters[j].ParameterType.FullName.ToLower() == "rx.rx_entity")
                    {
                        Dictionary <string, object> dic = jss.Deserialize <Dictionary <string, object> >(context.Request[parameters[j].Name]);
                        rx_entity entity = new rx_entity(dic["entity_name"].ToString());
                        if (!rx_manager.empty_entity_and_view_keys.Keys.Contains(dic["entity_name"].ToString()))
                        {
                            throw new Exception("表或者视图 " + dic["entity_name"].ToString() + " 不存在");
                        }
                        entity.command_type        = (dml_command_type)Enum.Parse(typeof(dml_command_type), dic["command_type"].ToString(), true);
                        entity.is_use_null         = Convert.ToBoolean(dic["is_use_null"]);
                        entity.where_keys          = dic["where_keys"] as List <string>;
                        entity.select_display_keys = dic["select_display_keys"] as string;
                        ArrayList rx_fields = (ArrayList)dic["rx_fields"];
                        for (int l = 0; l < rx_fields.Count; l++)
                        {
                            Dictionary <string, object> rx_field = (Dictionary <string, object>)rx_fields[l];
                            entity.Add(
                                rx_field["key"].ToString(),
                                new rx_field(
                                    rx_field["key"].ToString(),
                                    rx_field["value"],
                                    entity,
                                    (date_format_type)Enum.Parse(typeof(date_format_type), rx_field["date_format_type"].ToString(), true)
                                    )
                            {
                                compare_symbol = (compare_symbol)Enum.Parse(typeof(compare_symbol), rx_field["compare_symbol"].ToString(), true),
                                logic_symbol   = (logic_symbol)Enum.Parse(typeof(logic_symbol), rx_field["logic_symbol"].ToString(), true),
                                auto_remove    = Convert.ToBoolean(rx_field["auto_remove"]),
                                build_quote    = Convert.ToBoolean(rx_field["build_quote"])
                            }
                                );
                        }
                        entity.select_display_keys = dic["select_display_keys"] == null ? null : dic["select_display_keys"].ToString();
                        entity.where_keys          = dic["where_keys"] == null ? null : ((ArrayList)dic["where_keys"]).OfType <string>().ToList();

                        input_parameters[j] = entity;
                    }
                    else
                    {
                        if (!parameters[j].ParameterType.IsArray)
                        {
                            input_parameters[j] = jss.DeserializeObject(context.Request[parameters[j].Name]);
                        }
                        else
                        {
                            switch (parameters[j].ParameterType.FullName.ToLower())
                            {
                            case "system.string[]":
                                input_parameters[j] = Regex.Split(context.Request[parameters[j].Name], @"\[{@}\]", RegexOptions.Compiled);
                                break;

                            case "system.int32[]":
                                input_parameters[j] = Regex.Split(context.Request[parameters[j].Name], @"\[{@}\]", RegexOptions.Compiled).Select(a => a.to_int()).ToArray();
                                break;
                            }
                        }
                    }
                }

                if (is_continue)
                {
                    continue;
                }

                if (result.Count != 0)
                {
                    result.Add("rows", invoke_method(methods[i], input_parameters));
                    foreach (string key in ref_index.Keys)
                    {
                        result[key] = input_parameters[ref_index[key]];
                    }
                    response_write_json(result);
                    return;
                }
                else
                {
                    response_write_json(invoke_method(methods[i], input_parameters));
                    return;
                }
            }

            response_write_json(new
            {
                message = string.Format("rx_manager中不存在 {0} 这个静态方法,或者没有找到符合该方法参数列表的重载匹配", rx_method)
            });
        }
예제 #7
0
파일: rx_entity.cs 프로젝트: ruanxu/rx
 /// <summary>
 /// 转换为JSON字符串
 /// </summary>
 /// <param name="rx_entity"></param>
 /// <returns></returns>
 public static string to_json_string(this rx_entity rx_entity)
 {
     return(new JavaScriptSerializer().Serialize(rx_entity.to_dictionary()));
 }