/// <summary> /// 文档详情 /// </summary> /// <param name="ProjectId">项目id</param> /// <param name="PageId">文档id</param> /// <returns>Page</returns> public static async Task<Page> GetPageDetail(string ProjectId, string PageId) { string url = apiUrl + "pages/" + PageId; 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"); Page page = new Page(); page.PageId = result["page_id"].ToString(); page.ParentId = result["parent_id"].ToString(); page.Pid = result["pid"].ToString(); page.Name = result["name"].ToString(); page.Summary = result["summary"].ToString(); page.Content = result["content"].ToString(); page.CreateTime = (DateTime)result["created_at"]; page.UpdateTime = (DateTime)result["updated_at"]; foreach (JObject jWacher in (JArray)result["watchers"]) { MemberInfo wacher = new MemberInfo(); 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()); page.Watchers.Add(wacher); } JObject jOwner = (JObject)result["owner"]; MemberInfo owner = new MemberInfo(); owner.Uid = jOwner["uid"].ToString(); owner.Name = jOwner["name"].ToString(); owner.NickName = jOwner["display_name"].ToString(); owner.HeadImage = jOwner["avatar"].ToString(); owner.Description = jOwner["desc"].ToString(); owner.Status = (UserProfile.UserStatus)int.Parse(jOwner["status"].ToString()); owner.Online = (UserProfile.UserOnline)int.Parse(jOwner["online"].ToString()); page.Owner = owner; return page; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }
/// <summary> /// 新建文档 /// </summary> /// <param name="ProjectId">项目id</param> /// <param name="Name">文档名称</param> /// <param name="Content">文档内容</param> /// <returns>Page</returns> public static async Task<Page> CreatePage(string ProjectId, string Name, string Content) { string url = apiUrl + "page?pid=" + ProjectId + "&access_token=" + AccessToken; Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("name", Name); parameters.Add("content", Content); string json = await Helper.HttpHelper.DoPost(url, parameters); if (string.IsNullOrEmpty(json)) { return null; } else { //开始解析返回数据 try { Debug.WriteLine("开始解析返回json---\n" + json); JObject result = JObject.Parse(json); Debug.WriteLine("解析返回json成功---\n"); Page page = new Page(); page.PageId = result["page_id"].ToString(); page.ParentId = result["parent_id"].ToString(); page.Pid = result["pid"].ToString(); page.Name = result["name"].ToString(); page.Summary = result["summary"].ToString(); //page.Content = result["content"].ToString(); page.CreateTime = (DateTime)result["created_at"]; page.UpdateTime = (DateTime)result["updated_at"]; JObject jOwner = (JObject)result["owner"]; MemberInfo owner = new MemberInfo(); owner.Uid = jOwner["uid"].ToString(); owner.Name = jOwner["name"].ToString(); owner.NickName = jOwner["display_name"].ToString(); owner.HeadImage = jOwner["avatar"].ToString(); owner.Description = jOwner["desc"].ToString(); owner.Status = (UserProfile.UserStatus)int.Parse(jOwner["status"].ToString()); owner.Online = (UserProfile.UserOnline)int.Parse(jOwner["online"].ToString()); page.Owner = owner; return page; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }