public async Task <ObservableCollection <ProjectLocation> > RetrieveProjectList() { //网络请求 string result = await Task.Run(() => WebApiCaller.HttpGet(ServiceConfig.BaseURL + string.Format(ServiceConfig.ProjectListFormat))); // JObject obj = JObject.Parse(result); string data = obj["data"].ToString(); // ObservableCollection <ProjectLocation> _obj = JsonConvert.DeserializeObject <ObservableCollection <ProjectLocation> >(data); return(_obj); }
public async Task <DGObject> Retrieve(int key) { //网络请求 string result = await Task.Run(() => WebApiCaller.HttpGet(ServiceConfig.BaseURL + string.Format(ServiceConfig.DGObjectByIDFormat, domainType.ToLower(), dgobjectName.ToLower(), projectID, key))); // JObject obj = JObject.Parse(result); string data = obj["data"].ToString(); // DGObject objHelper = ObjectHelper.CreateDGObjectFromSubclassName(dgobjectName); var _obj = JsonConvert.DeserializeObject(data, objHelper.GetType()); return(_obj as DGObject); }
//获取对象列表 public async Task <List <DGObject> > GetAllByObjs(string filter) { //网络请求 string result = await Task.Run(() => WebApiCaller.HttpGet(ServiceConfig.BaseURL + string.Format(ServiceConfig.DGObjectListFormat, domainType.ToLower(), dgobjectName.ToLower(), projectID, iS3.Core.APIMessageConverter.EnCode(filter)))); // JObject obj = JObject.Parse(result); string data = obj["data"].ToString(); JArray objList = JArray.Parse(data); // if (subclasses == null) { subclasses = from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.IsSubclassOf(typeof(DGObject)) select type; } // match the subclassName with full name at first Type t = subclasses.FirstOrDefault(x => x.FullName == dgobjectName); // if not found, match the subclassName with name if (t == null) { t = subclasses.FirstOrDefault(x => x.Name == dgobjectName); } List <DGObject> list = new List <DGObject>(); foreach (JToken token in objList) { var _obj = JsonConvert.DeserializeObject(token.ToString(), t); list.Add(_obj as DGObject); } return(list); }