/// <summary> /// 添加文档评论 /// </summary> /// <param name="ProjectId">项目id</param> /// <param name="PageId">文档id</param> /// <returns>Comment</returns> public static async Task<Comment> AddPageComment(string ProjectId, string PageId, string Message, List<string> Fids = null) { string url = apiUrl + "pages/" + PageId + "/comment?pid=" + ProjectId + "&access_token=" + AccessToken; Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("message", Message); parameters.Add("fids", JsonConvert.SerializeObject(Fids)); 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"); Comment comment = new Comment(); comment.Cid = result["cid"].ToString(); comment.Message = result["message"].ToString(); if (result["raw_message"] == null) comment.RawMessage = comment.Message; comment.Type = (Comment.CommentType)int.Parse(result["type"].ToString()); comment.Format = (Comment.CommentFormat)int.Parse(result["format"].ToString()); if (result["fids"] != null) { foreach (string fid in (JArray)result["fids"]) { comment.Fids.Add(fid); } } UserProfile owner = new UserProfile(); JObject jOwner = (JObject)result["owner"]; 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()); comment.Owner = owner; if (result["files"] != null) { foreach (JObject jFile in (JArray)result["files"]) { File file = new File(); file.Fid = jFile["fid"].ToString(); file.Name = jFile["name"].ToString(); file.Description = jFile["desc"].ToString(); file.Pid = jFile["pid"].ToString(); file.Size = jFile["size"].ToString(); file.Path = jFile["path"].ToString(); file.FolderId = jFile["folder_id"].ToString(); comment.Files.Add(file); } } comment.CreateTime = (DateTime)result["created_at"]; return comment; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }
/// <summary> /// 文件/文件夹详情 /// </summary> /// <param name="ProjectId">项目id</param> /// <param name="FileId">文件id </param> /// <returns>File</returns> public static async Task<File> GetFileDetail( string ProjectId,string FileId) { string url = apiUrl + "files/" + FileId; 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"); File file = new File(); file.Fid = result["fid"].ToString(); file.Name = result["name"].ToString(); file.Description = result["desc"].ToString(); file.Pid = result["pid"].ToString(); file.Path = result["path"].ToString(); file.FolderId = result["folder_id"].ToString(); file.FolderName = result["folder_name"].ToString(); file.Type = (File.FileType)Convert.ToInt32(result["type"].ToString()); file.CreateTime = (DateTime)result["created_at"]; file.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()); file.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()); file.Owner = owner; return file; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }
/// <summary> /// 获取文档的评论列表 /// </summary> /// <param name="ProjectId">项目id</param> /// <param name="PageId">文档id</param> /// <returns>ObservableCollection<Comment></returns> public static async Task<ObservableCollection<Comment>> GetPageCommentList(string ProjectId, string PageId) { string url = apiUrl + "pages/" + PageId + "/comments"; Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("pid", ProjectId); parameters.Add("access_token", AccessToken); 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<Comment> CommentList = new ObservableCollection<Comment>(); foreach (JObject obj in result) { Comment comment = new Comment(); comment.Cid = obj["cid"].ToString(); comment.Message = obj["message"].ToString(); comment.RawMessage = obj["raw_message"].ToString(); comment.Type = (Comment.CommentType)int.Parse(obj["type"].ToString()); comment.Format = (Comment.CommentFormat)int.Parse(obj["format"].ToString()); foreach (string fid in (JArray)obj["fids"]) { comment.Fids.Add(fid); } UserProfile owner = new UserProfile(); JObject jOwner = (JObject)obj["owner"]; 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()); comment.Owner = owner; foreach (JObject jFile in (JArray)obj["files"]) { File file = new File(); file.Fid = jFile["fid"].ToString(); file.Name = jFile["name"].ToString(); file.Description = jFile["desc"].ToString(); file.Pid = jFile["pid"].ToString(); file.Size = jFile["size"].ToString(); file.Path = jFile["path"].ToString(); file.FolderId = jFile["folder_id"].ToString(); comment.Files.Add(file); } comment.CreateTime = (DateTime)obj["created_at"]; CommentList.Add(comment); } return CommentList; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }
/// <summary> /// 项目中所有的图片列表 /// </summary> /// <param name="ProjectId">项目id</param> /// <returns>ObservableCollection<File></returns> public static async Task<ObservableCollection<File>> GetAllImageFileList( string ProjectId) { string url = apiUrl + "files/images"; 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<File> FileList = new ObservableCollection<File>(); foreach (JObject obj in result) { File file = new File(); file.Fid = obj["fid"].ToString(); file.Name = obj["name"].ToString(); file.Description = obj["desc"].ToString(); file.Pid = obj["pid"].ToString(); file.Size = obj["size"].ToString(); file.Path = obj["path"].ToString(); file.FolderId = obj["folder_id"].ToString(); file.Type = File.FileType.File; file.CreateTime = (DateTime)obj["created_at"]; file.UpdateTime = (DateTime)obj["updated_at"]; FileList.Add(file); } return FileList; } catch (Exception) { Debug.WriteLine("解析返回json失败---\n" + json); return null; } } }