/// <summary> /// 获取日程详情 /// </summary> /// <param name="ProjectId">项目id</param> /// <param name="EventId">日程id</param> /// <returns>Event</returns> public async static Task<Event> GetEventDetail(string ProjectId, string EventId) { string url = apiUrl + "events" + EventId + "?pid=" + ProjectId + "&access_token=" + AccessToken; Dictionary<string, string> parameters = new Dictionary<string, string>(); string json = await Helper.HttpHelper.DoGet(url, parameters); if (string.IsNullOrEmpty(json)) { return null; } else { //开始解析返回数据 try { Debug.WriteLine("开始解析返回json---\n" + json); JObject result = JObject.Parse(json); Debug.WriteLine("解析返回json成功---\n"); Event myEvent = new Event(); myEvent.EventId = result["event_id"].ToString(); myEvent.Name = result["name"].ToString(); myEvent.Summary = result["summary"].ToString(); myEvent.Location = result["location"].ToString(); myEvent.StartTime = (DateTime)result["start"]; myEvent.EndTime = (DateTime)result["end"]; myEvent.Recurrence = (Event.EventRecurrence)int.Parse(result["recurrence"].ToString()); foreach (JObject jWacher in (JArray)result["attendees"]) { UserProfile wacher = new UserProfile(); wacher.Uid = jWacher["uid"].ToString(); wacher.Name = jWacher["name"].ToString(); wacher.NickName = jWacher["display_name"].ToString(); wacher.HeadImage = jWacher["avatar"].ToString(); wacher.Description = jWacher["desc"].ToString(); wacher.Status = (UserProfile.UserStatus)int.Parse(jWacher["status"].ToString()); wacher.Online = (UserProfile.UserOnline)int.Parse(jWacher["online"].ToString()); myEvent.Attendees.Add(wacher); } ProjectInfo project = new ProjectInfo(); JObject jProject = (JObject)result["project"]; project.Pid = jProject["pid"].ToString(); project.Name = jProject["name"].ToString(); project.Picture = jProject["pic"].ToString(); project.BackgroundColor = jProject["bg"].ToString(); myEvent.Project = project; return myEvent; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }
/// <summary> /// 我参与的今日日程 /// </summary> /// <param name="ProjectId">项目id</param> /// <returns>ObservableCollection<Event></returns> public static async Task<ObservableCollection<Event>> GetTodayEventList(string ProjectId) { string url = apiUrl + "events/today"; Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("access_token", AccessToken); parameters.Add("pid", ProjectId); string json = await Helper.HttpHelper.DoGet(url, parameters); if (string.IsNullOrEmpty(json)) { return null; } else { //开始解析返回数据 try { Debug.WriteLine("开始解析返回json---\n" + json); JArray result = JArray.Parse(json); Debug.WriteLine("解析返回json成功---\n"); ObservableCollection<Event> EventList = new ObservableCollection<Event>(); foreach (JObject obj in result) { Event myEvent = new Event(); myEvent.EventId = obj["event_id"].ToString(); myEvent.Name = obj["name"].ToString(); myEvent.Summary = obj["summary"].ToString(); myEvent.Location = obj["location"].ToString(); myEvent.StartTime = (DateTime)obj["start"]; myEvent.EndTime = (DateTime)obj["end"]; myEvent.Recurrence = (Event.EventRecurrence)int.Parse(obj["recurrence"].ToString()); foreach (JObject jWacher in (JArray)obj["attendees"]) { UserProfile wacher = new UserProfile(); wacher.Uid = jWacher["uid"].ToString(); wacher.Name = jWacher["name"].ToString(); wacher.NickName = jWacher["display_name"].ToString(); wacher.HeadImage = jWacher["avatar"].ToString(); wacher.Description = jWacher["desc"].ToString(); wacher.Status = (UserProfile.UserStatus)int.Parse(jWacher["status"].ToString()); wacher.Online = (UserProfile.UserOnline)int.Parse(jWacher["online"].ToString()); myEvent.Attendees.Add(wacher); } ProjectInfo project = new ProjectInfo(); JObject jProject = (JObject)obj["project"]; project.Pid = jProject["pid"].ToString(); project.Name = jProject["name"].ToString(); project.Picture = jProject["pic"].ToString(); project.BackgroundColor = jProject["bg"].ToString(); myEvent.Project = project; EventList.Add(myEvent); } return EventList; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }