Exemplo n.º 1
0
        /// <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;
                }
            }
        }
Exemplo n.º 2
0
 public async void DeleteComment(Comment comment)
 {
     MessageDialog dlg = new MessageDialog("确定要删除此评论吗?", "提示");
     dlg.Commands.Add(new UICommand("删除", async command =>
     {
         this.StartProgress();
         bool result = await Helper.WorktileClient.DeleteTaskComment(Task.Pid, Task.Tid, comment.Cid);
         this.EndProgress();
         if (result)
         {
             CommentList.Remove(comment);
         }
         else
         {
             ShowAlert("删除评论失败,请稍后重试!");
         }
     }));
     dlg.Commands.Add(new UICommand("取消"));
     dlg.DefaultCommandIndex = 0;
     dlg.CancelCommandIndex = 1;
     await dlg.ShowAsync();
 }
Exemplo n.º 3
0
        /// <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;
                }
            }
        }