Пример #1
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;
                }
            }
        }
Пример #2
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;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 获取项目详情
        /// </summary>
        /// <param name="ProjectId">项目id</param>
        /// <returns>ProjectDetail</returns>
        public static async Task<ProjectInfo> GetProjectDetail(string ProjectId)
        {
            string url = apiUrl + "projects/" + ProjectId  ;
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            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);
                    JObject result = JObject.Parse(json);
                    Debug.WriteLine("解析返回json成功---\n");

                    ProjectInfo project = new ProjectInfo();
                    project.Pid = result["pid"].ToString();
                    project.Name = result["name"].ToString();
                    project.TeamId = result["team_id"].ToString();
                    project.Description = result["desc"].ToString();
                    project.Archived = (ProjectInfo.ProjectArchived)int.Parse(result["archived"].ToString());
                    project.Picture = result["pic"].ToString();
                    project.BackgroundColor = result["bg"].ToString();
                    project.Visibility = (ProjectInfo.ProjectVisibility)int.Parse(result["visibility"].ToString());

                    foreach (JObject jLabel in (JArray)result["labels"])
                    {
                        Label label = new Label();
                        label.Name = jLabel["name"].ToString();
                        label.Color = label.Name.Substring(0, 1).ToUpper() + label.Name.Substring(1);
                        label.Description = jLabel["desc"].ToString();
                        project.Labels.Add(label);
                    }

                    JObject jCreateUser = (JObject)result["created_by"];
                    UserProfile user = new UserProfile();
                    user.Uid = jCreateUser["uid"].ToString();
                    user.Name = jCreateUser["name"].ToString();
                    user.NickName = jCreateUser["display_name"].ToString();
                    user.HeadImage = jCreateUser["avatar"].ToString();
                    user.Description  = jCreateUser["desc"].ToString();
                    user.Status = (UserProfile.UserStatus)int.Parse(jCreateUser["status"].ToString());
                    user.Online = (UserProfile.UserOnline)int.Parse(jCreateUser["online"].ToString());
                    project.CreatedBy = user;

                    return project;
                }
                catch (Exception)
                {
                    Debug.WriteLine("解析返回json失败---\n" + json);
                    return null;
                }
            }
        }
Пример #4
0
        /// <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;
                }
            }

        }
Пример #5
0
        /// <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;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns>UserProfile</returns>
        public static async Task<UserProfile> GetUserProfile()
        {
            string url = apiUrl + "user/profile";
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            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);
                    JObject result = JObject.Parse(json);
                    Debug.WriteLine("解析返回json成功---\n");

                    UserProfile userProfile = new UserProfile()
                    {
                        Uid = result["uid"].ToString(),
                        Name = result["name"].ToString(),
                        NickName = result["display_name"].ToString(),
                        Email = result["email"].ToString(),
                        Description = result["desc"].ToString(),
                        HeadImage = result["avatar"].ToString(),
                        Status = (UserProfile.UserStatus)int.Parse(result["status"].ToString()),
                        Online = (UserProfile.UserOnline)int.Parse(result["online"].ToString())
                    };
                    return userProfile;
                }
                catch (Exception)
                {
                    Debug.WriteLine("解析返回json失败---\n" + json);
                    return null;
                }
            }

        }
Пример #7
0
 public Team()
 {
     CreatedBy = new UserProfile();
 }