private static TreeEntityJson ConvertRecur(Entity entity, EntityViewMeta evm) { var jEntity = new TreeEntityJson(); EntityJsonConverter.EntityToJson(evm, entity, jEntity); foreach (Entity child in entity.TreeChildren) { var c = ConvertRecur(child, evm); jEntity.children.Add(c); } return(jEntity); }
private static object ConvertOutputComponent(object value) { //服务的输出属性如果类型是一个实体或者实体列表,则需要进行格式转换。 if (value is IDomainComponent) { var model = (value as IDomainComponent).GetRepository().EntityType; //TODO:这里可能存在问题:当一个非默认的视图请求这个服务得到一个默认视图的实体数据时,可能会因为列不一致而出现问题。 var defaultVM = UIModel.Views.CreateBaseView(model); if (value is EntityList) { var listRes = new EntityJsonList { model = model }; EntityJsonConverter.EntityToJson(defaultVM, value as EntityList, listRes.entities); listRes.total = listRes.entities.Count; value = listRes; } else if (value is Entity) { var entityJson = new EntityJson(); EntityJsonConverter.EntityToJson(defaultVM, value as Entity, entityJson); //在纯数据的基础上添加以下两个约定的属性:标记这是一个实体以及它在客户端的类型名称。 entityJson.SetProperty(Consts.isEntityProperty, BooleanBoxes.True); entityJson.SetProperty(Consts.modelProperty, ClientEntities.GetClientName(model)); value = entityJson; } else { throw new NotSupportedException("只支持对实体、实体列表进行格式转换。"); } } return(value); }
private JsonModel QueryEntityList(HttpRequest request, EntityViewMeta evm) { var repo = RF.Find(evm.EntityType); var pagingInfo = ParsePagingInfo(request, repo); var entities = QueryEntityListCore(request, repo, pagingInfo); var list = new EntityJsonList { model = evm.EntityType }; if (repo.SupportTree) { var roots = entities; foreach (var rootItem in roots) { var i = ConvertRecur(rootItem, evm); i.expanded = true; list.entities.Add(i); } list.total = (entities as ITreeComponent).CountNodes(); } else { //如果此时,还需要进行统计,表示在数据层查询时,并没有对分页进行处理。这时,只能在内存中对实体进行分页。 if (pagingInfo.IsNeedCount) { entities = JumpToPageInMemory(repo, entities, pagingInfo); } EntityJsonConverter.EntityToJson(evm, entities, list.entities); list.total = pagingInfo.TotalCount; } return(list); #region //暂时不用 //var repo = RF.Create(evm.EntityType); //EntityList entities = QueryEntityListCore(request, repo); //if (repo.SupportTree) //{ // entities.EnsureObjectRelations(); // var root = new RootTreeEntityJson(); // var roots = entities.FindRoots(); // foreach (var rootItem in roots) // { // var i = ConvertRecur(rootItem, evm); // root.children.Add(i); // } // return root; //} //else //{ // var page = request.GetQueryStringOrDefault("page", 1); // var limit = request.GetQueryStringOrDefault("limit", 10); // var pagerInfo = new PagerInfo(page, limit, true); // entities = JumpToPage(repo, entities, pagerInfo); // var list = new EntityJsonList // { // totalCount = pagerInfo.TotalCount, // }; // EntityJsonConverter.EntityToJson(evm, entities, list.entities); // return list; //} #endregion }