Beispiel #1
0
        private static void ConvertParametersType(ParameterInfo[] methodParameters, object[] parameters)
        {
            for (int i = 0; i < parameters.Length; i++)
            {
                var mp = methodParameters[i];
                var p  = parameters[i];

                var mpType = mp.ParameterType;

                //任意参数都不能为 null
                if (p == null)
                {
                    if (mpType == typeof(string))
                    {
                        p = string.Empty;
                    }
                    else
                    {
                        p = TypeHelper.GetDefaultValue(mpType);
                    }

                    parameters[i] = p;
                }

                //如果需要的参数是一个类型,而提供的参数是一个字符串,则通过字符串查找并转换为对应的实体类型。
                if (mpType == typeof(Type) && p is string)
                {
                    var em = ClientEntities.Find(p as string);
                    if (em != null)
                    {
                        parameters[i] = em.EntityType;
                    }
                }
            }
        }
Beispiel #2
0
        private static Criteria ParseCriteria(JArray filters, PagingInfo pagingInfo)
        {
            JObject jUseCriteriaType = filters[0] as JObject;
            var     clientTypeName   = jUseCriteriaType.Property("value").Value.ToString();
            var     criteriaMeta     = ClientEntities.Find(clientTypeName);

            if (criteriaMeta == null)
            {
                throw new NotSupportedException("criteriaType");
            }

            var jCriteria = filters[1] as JObject;

            if (!jCriteria.Property("property").Value.ToString().Contains("_criteria"))
            {
                throw new NotSupportedException();
            }
            var jCriteriaValues = jCriteria.Property("value").Value as JObject;

            //创建一个 Criteria 并设置它的相关属性值
            var criteria = Entity.New(criteriaMeta.EntityType) as Criteria;

            if (criteria == null)
            {
                throw new InvalidProgramException("在 Web 开发模式下,查询条件类,必须继承自 Criteria 类型。");
            }

            var setter = new EntityPropertySetter(criteriaMeta);

            setter.SetEntity(criteria, jCriteriaValues);

            criteria.PagingInfo = pagingInfo;

            return(criteria);
        }
Beispiel #3
0
        protected override string ResponseScript(HttpContext context)
        {
            var request = context.Request;

            var strType = request.QueryString["type"];

            if (string.IsNullOrEmpty(strType))
            {
                return(string.Empty);
            }

            var meta = ClientEntities.Find(strType);

            JsonModel res = null;

            if (context.Request.HttpMethod == "GET")
            {
                var evm = UIModel.Views.CreateBaseView(meta.EntityType);
                res = this.QueryEntityList(request, evm);
            }
            else
            {
                res = this.SaveEntityList(request, meta);
            }

            var js = res.ToJsonString();

            return(Compress(js));
        }
Beispiel #4
0
        protected override string ResponseScript(HttpContext context)
        {
            var request = context.Request;

            var converter = new ClientMetaFactory();
            var op        = converter.Option;

            op.ignoreCommands = request.GetQueryStringOrDefault("ignoreCommands", 0) == 1;
            op.isDetail       = request.GetQueryStringOrDefault("isDetail", 0) == 1;
            op.isLookup       = request.GetQueryStringOrDefault("isLookup", 0) == 1;
            op.isReadonly     = request.GetQueryStringOrDefault("isReadonly", 0) == 1;
            op.viewName       = request.GetQueryStringOrDefault("viewName", string.Empty);
            var moduleName   = request.GetQueryStringOrDefault("module", string.Empty);
            var typeName     = request.GetQueryStringOrDefault("type", string.Empty);
            var templateType = request.GetQueryStringOrDefault("templateType", string.Empty);
            var isAggt       = request.GetQueryStringOrDefault("isAggt", 0) == 1;

            JsonModel jsonResult = null;

            //如果指定了 module,则直接返回模块的格式。
            if (!string.IsNullOrEmpty(moduleName))
            {
                var module = CommonModel.Modules[moduleName];
                var aggt   = UIModel.AggtBlocks.GetModuleBlocks(module);
                jsonResult = converter.ConvertToAggtMeta(aggt);
            }
            else
            {
                var type = ClientEntities.Find(typeName);

                //需要聚合块
                if (isAggt)
                {
                    AggtBlocks aggt = null;
                    //通过定义的模板类来返回模块格式
                    if (!string.IsNullOrEmpty(templateType))
                    {
                        var uiTemplateType = Type.GetType(templateType);
                        var template       = Activator.CreateInstance(uiTemplateType) as BlocksTemplate;
                        template.EntityType = type.EntityType;
                        aggt = template.GetBlocks();
                    }
                    else
                    {
                        //通过定义的聚合块名称来获取聚合块
                        if (!string.IsNullOrEmpty(op.viewName))
                        {
                            aggt = UIModel.AggtBlocks.GetDefinedBlocks(op.viewName);
                        }
                        else
                        {
                            //通过默认的聚合块名称来获取聚合块
                            aggt = UIModel.AggtBlocks.GetDefaultBlocks(type.EntityType);
                        }
                    }

                    jsonResult = converter.ConvertToAggtMeta(aggt);
                }
                else
                {
                    //获取单块 UI 的元数据
                    var evm = UIModel.Views.Create(type.EntityType, op.viewName) as WebEntityViewMeta;

                    jsonResult = converter.ConvertToClientMeta(evm);
                }
            }

            var json = jsonResult.ToJsonString();

            return(json);
        }