/// <summary>
        /// 获取项目的任务列表
        /// </summary>
        /// <param name="ProjectId">项目id</param>
        /// <param name="Type">任务类型:all:默认,completed:已完成,uncompleted:未完成,expired:已过期</param>
        /// <returns>ObservableCollection<Task></returns>
        public static async Task<ObservableCollection<Worktile.Model.Task>> GetProjectTaskList(string ProjectId, string Type = "all")
        {
            string url = apiUrl + "tasks" ;
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("pid", ProjectId);
            parameters.Add("access_token", AccessToken);
            parameters.Add("type", Type);
            parameters.Add("rnd", new Random(100).Next().ToString());

            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<Model.Task> TaskList = new ObservableCollection<Model.Task>();
                    foreach (JObject obj in result)
                    {
                        Model.Task task = new Model.Task();
                        task.Name = obj["name"].ToString();
                        task.Pid = obj["pid"].ToString();
                        task.Tid = obj["tid"].ToString();
                        task.EntryId = obj["entry_id"].ToString();
                        task.EntryName = obj["entry_name"].ToString();
                        task.CreateTime = (DateTime)obj["created_at"];
                        task.UpdateTime = (DateTime)obj["updated_at"];
                        task.Position = (int)obj["pos"];

                        foreach (JObject jLabel in (JArray)obj["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();
                            task.Labels.Add(label);
                        }
                        foreach (JObject jTodo in (JArray)obj["todos"])
                        {
                            Todo todo = new Todo();
                            todo.TodoId = jTodo["todo_id"].ToString();
                            todo.Name = jTodo["name"].ToString();
                            todo.Checked = (Model.Task.TaskCompleted)int.Parse(jTodo["checked"].ToString());
                            todo.Position = jTodo["pos"].ToString();
                            task.Todos.Add(todo);
                        }
                        JObject jBadge = (JObject)obj["badges"];
                        TaskBadge badge = new TaskBadge();
                        if (!string.IsNullOrEmpty(jBadge["expire_date"].ToString()))
                        {
                            badge.ExpireDate = (DateTime)jBadge["expire_date"];
                        }
                        badge.CommentCount = (int)jBadge["comment_count"];
                        badge.TodoCheckedCount = (int)jBadge["todo_checked_count"];
                        badge.TodoCount = (int)jBadge["todo_count"];
                        badge.FileCount = (int)jBadge["file_count"];
                        task.Badges = badge;

                        foreach (JObject jWacher in (JArray)obj["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());
                            task.Watchers.Add(wacher);
                        }
                        foreach (JObject jMember in (JArray)obj["members"])
                        {
                            MemberInfo member = new MemberInfo();
                            member.Uid = jMember["uid"].ToString();
                            member.Name = jMember["name"].ToString();
                            member.NickName = jMember["display_name"].ToString();
                            member.HeadImage = jMember["avatar"].ToString();
                            member.Description = jMember["desc"].ToString();
                            member.Status = (UserProfile.UserStatus)int.Parse(jMember["status"].ToString());
                            member.Online = (UserProfile.UserOnline)int.Parse(jMember["online"].ToString());
                            task.Members.Add(member);
                        }
                        task.Completed = (Model.Task.TaskCompleted)int.Parse(obj["completed"].ToString());
                        if (!string.IsNullOrEmpty(obj["expire_date"].ToString()))
                        {
                            task.ExpireDate = (DateTime)obj["expire_date"];
                        }
                        task.Description = obj["desc"].ToString();
                        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();
                        task.Project = project;
                        TaskList.Add(task);
                    }
                    return TaskList;
                }
                catch (Exception)
                {
                    Debug.WriteLine("解析返回json失败---\n" + json);
                    return null;
                }
            }
        }
        /// <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;
                }
            }
        }
        /// <summary>
        /// 获取用户所有项目
        /// </summary>
        /// <returns>ObservableCollection<ProjectInfo></returns>
        public static async Task<ObservableCollection<ProjectInfo>> GetUserProjectList()
        {
            string url = apiUrl + "projects";
            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);
                    JArray result = JArray.Parse(json);
                    Debug.WriteLine("解析返回json成功---\n");

                    ObservableCollection<ProjectInfo> ProjectList = new ObservableCollection<ProjectInfo>();
                    foreach (JObject obj in result)
                    {
                        ProjectInfo project = new ProjectInfo();
                        project.Pid = obj["pid"].ToString();
                        project.Name = obj["name"].ToString();
                        project.TeamId = obj["team_id"].ToString();
                        project.Description = obj["desc"].ToString();
                        project.Archived = (ProjectInfo.ProjectArchived)int.Parse(obj["archived"].ToString());
                        project.Picture = obj["pic"].ToString();
                        project.BackgroundColor = obj["bg"].ToString();
                        project.Visibility = (ProjectInfo.ProjectVisibility)int.Parse(obj["visibility"].ToString());
                        project.IsStar = (ProjectInfo.ProjectIsStar)int.Parse(obj["is_star"].ToString());
                        project.Position = (Single)obj["pos"];
                        project.MemberCount = (int)obj["member_count"];
                        project.UserRole = (ProjectInfo.ProjectRole)int.Parse(obj["curr_role"].ToString());
                        project.UserPermission = (ProjectInfo.ProjectPermission)int.Parse(obj["permission"].ToString());
                        ProjectList.Add(project);
                    }
                    return ProjectList;
                }
                catch (Exception)
                {
                    Debug.WriteLine("解析返回json失败---\n" + json);
                    return null;
                }
            }
        }
        /// <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;
                }
            }
        }
        /// <summary>
        /// 创建任务
        /// </summary>
        /// <param name="ProjectId">项目id</param>
        /// <param name="EntryId">任务组id</param>
        /// <param name="TaskName">任务名称</param>
        /// <param name="Description">任务描述</param>
        /// <returns>Task</returns>
        public async static Task<Model.Task> CreateTask(string ProjectId,string EntryId, string TaskName,string Description)
        {
            string url = apiUrl + "task" + "?pid=" + ProjectId + "&access_token=" + AccessToken;
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("entry_id", EntryId);
            parameters.Add("name", TaskName);
            parameters.Add("desc", Description);

            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");

                    Model.Task task = new Model.Task();
                    task.Name = result["name"].ToString();
                    task.Pid = result["pid"].ToString();
                    task.Tid = result["tid"].ToString();
                    task.EntryId = result["entry_id"].ToString();
                    task.EntryName = result["entry_name"].ToString();
                    task.CreateTime = (DateTime)result["created_at"];
                    task.UpdateTime = (DateTime)result["updated_at"];
                    task.Position = (int)result["pos"];

                    JObject jBadge = (JObject)result["badges"];
                    TaskBadge badge = new TaskBadge();
                    if (!string.IsNullOrEmpty(jBadge["expire_date"].ToString()))
                    {
                        badge.ExpireDate = (DateTime)jBadge["expire_date"];
                    }
                    badge.CommentCount = (int)jBadge["comment_count"];
                    badge.TodoCheckedCount = (int)jBadge["todo_checked_count"];
                    badge.TodoCount = (int)jBadge["todo_count"];
                    badge.FileCount = (int)jBadge["file_count"];
                    task.Badges = badge;

                    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());
                        task.Watchers.Add(wacher);
                    }
                    foreach (JObject jMember in (JArray)result["members"])
                    {
                        MemberInfo member = new MemberInfo();
                        member.Uid = jMember["uid"].ToString();
                        member.Name = jMember["name"].ToString();
                        member.NickName = jMember["display_name"].ToString();
                        member.HeadImage = jMember["avatar"].ToString();
                        member.Description = jMember["desc"].ToString();
                        member.Status = (UserProfile.UserStatus)int.Parse(jMember["status"].ToString());
                        member.Online = (UserProfile.UserOnline)int.Parse(jMember["online"].ToString());
                        task.Members.Add(member);
                    }
                    task.Completed = (Model.Task.TaskCompleted)int.Parse(result["completed"].ToString());
                    if (!string.IsNullOrEmpty(result["expire_date"].ToString()))
                    {
                        task.ExpireDate = (DateTime)result["expire_date"];
                    }
                    task.Description = result["desc"].ToString();
                    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();
                    task.Project = project;

                    return task;
                }
                catch (Exception)
                {
                    Debug.WriteLine("解析返回json失败---\n" + json);
                    return null;
                }
            }

        }