Class representing the XHTML page
コード例 #1
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of recent project activity
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <param name="activityTypes">The activity types you want to return.</param>
        /// <returns>
        /// List of all the project activities of the desired types.
        /// </returns>
        public List <ProjectActivity> GetRecentActivity(int projectId, params RecentActivityType[] activityTypes)
        {
            StringBuilder sb = new StringBuilder();

            foreach (RecentActivityType activityType in activityTypes)
            {
                switch (activityType)
                {
                case RecentActivityType.Issues:
                    sb.Append("&show_issues=1");
                    break;

                case RecentActivityType.Changesets:
                    sb.Append("&show_changesets=1");
                    break;

                case RecentActivityType.News:
                    sb.Append("&show_news=1");
                    break;

                case RecentActivityType.Documents:
                    sb.Append("&show_documents=1");
                    break;

                case RecentActivityType.Files:
                    sb.Append("&show_files=1");
                    break;

                case RecentActivityType.WikiEdits:
                    sb.Append("&show_wiki_edits=1");
                    break;

                case RecentActivityType.Messages:
                    sb.Append("&show_messages=1");
                    break;
                }
            }

            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(RecentActivitiesRelativeUri, projectId, sb))));
            List <ProjectActivity> activities = new List <ProjectActivity>();

            foreach (AtomEntry entry in AtomParser.ParseFeed(page.XmlDocument))
            {
                activities.Add(new ProjectActivity
                {
                    Title       = entry.Title,
                    Content     = entry.Content,
                    Url         = entry.Id,
                    Updated     = DateTime.Parse(entry.Updated),
                    AuthorName  = entry.Author.Name,
                    AuthorEmail = entry.Author.Email
                });
            }

            return(activities);
        }
コード例 #2
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all available project issue statuses
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the issue statuses available for the user in selected project</returns>
        public List <Status> GetStatuses(int projectId)
        {
            XhtmlPage     page     = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List <Status> statuses = new List <Status>();

            foreach (KeyValuePair <int, string> kv in page.GetSelectOptions("issue_status_id"))
            {
                statuses.Add(new Status()
                {
                    Id = kv.Key, Name = kv.Value
                });
            }

            return(statuses);
        }
コード例 #3
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all available project issue priorities
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the issue priorities available for the user in selected project</returns>
        public List <Priority> GetPriorities(int projectId)
        {
            XhtmlPage       page       = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List <Priority> priorities = new List <Priority>();

            foreach (KeyValuePair <int, string> kv in page.GetSelectOptions("issue_priority_id"))
            {
                priorities.Add(new Priority()
                {
                    Id = kv.Key, Name = kv.Value
                });
            }

            return(priorities);
        }
コード例 #4
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all versions project issue can target
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the versions available for the user in selected project</returns>
        public List <Version> GetVersions(int projectId)
        {
            XhtmlPage      page     = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List <Version> versions = new List <Version>();

            foreach (KeyValuePair <int, string> kv in page.GetSelectOptions("issue_fixed_version_id"))
            {
                versions.Add(new Version()
                {
                    Id = kv.Key, Name = kv.Value
                });
            }

            return(versions);
        }
コード例 #5
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all the users available as watchers for the project
        /// </summary>
        /// <param name="projectId">ID of the project</param>
        /// <returns>List of all the users available as watchers for the project</returns>
        public List <User> GetWatchers(int projectId)
        {
            XhtmlPage   page     = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List <User> watchers = new List <User>();

            foreach (KeyValuePair <int, string> kv in page.GetCheckBoxOptions("issue[watcher_user_ids][]"))
            {
                watchers.Add(new User()
                {
                    Id = kv.Key, Name = kv.Value
                });
            }

            return(watchers);
        }
コード例 #6
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all users available to be assigned to project issue
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the users available to be assigned to project issues</returns>
        public List <User> GetAssignees(int projectId)
        {
            XhtmlPage   page  = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List <User> users = new List <User>();

            foreach (KeyValuePair <int, string> kv in page.GetSelectOptions("issue_assigned_to_id"))
            {
                users.Add(new User()
                {
                    Id = kv.Key, Name = kv.Value
                });
            }

            return(users);
        }
コード例 #7
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all the available issues
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the available issues for the project</returns>
        public List <Issue> GetIssues(int projectId)
        {
            if (_cache.GetIssues(projectId) != null)
            {
                return(_cache.GetIssues(projectId));
            }
            XhtmlPage    page   = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(IssueListRelativeUri, projectId))));
            List <Issue> issues = new List <Issue>();

            foreach (AtomEntry entry in AtomParser.ParseFeed(page.XmlDocument))
            {
                issues.Add(new Issue
                {
                    Id      = entry.NumericId,
                    Subject = entry.Title
                });
            }

            _cache.SetIssues(projectId, issues);
            return(issues);
        }
コード例 #8
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all available project activities
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the activities available for the user</returns>
        public List <Activity> GetActivities(int projectId)
        {
            if (_cache.GetActivities(projectId) != null)
            {
                return(_cache.GetActivities(projectId));
            }
            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(TimeLogFormRelativeUri, projectId))));

            List <Activity> activities = new List <Activity>();

            foreach (KeyValuePair <int, string> kv in page.GetSelectOptions("time_entry_activity_id"))
            {
                activities.Add(new Activity()
                {
                    Id = kv.Key, Description = kv.Value
                });
            }

            _cache.SetActivities(projectId, activities);
            return(activities);
        }
コード例 #9
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Gets the list of all the available projects
        /// </summary>
        /// <returns>List of all the projects available to the user</returns>
        public List <Project> GetProjects()
        {
            if (_cache.Projects != null)
            {
                return(_cache.Projects);
            }

            XhtmlPage      page     = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(ProjectListRelativeUri)));
            List <Project> projects = new List <Project>();

            foreach (AtomEntry entry in AtomParser.ParseFeed(page.XmlDocument))
            {
                projects.Add(new Project
                {
                    Id   = entry.NumericId,
                    Name = entry.Title
                });
            }

            _cache.Projects = projects;
            return(projects);
        }
コード例 #10
0
ファイル: Redmine.cs プロジェクト: MisterY/redmine-client
        /// <summary>
        /// Logs user into Redmine
        /// </summary>
        public void LogIn()
        {
            if (!this.authenticated && !string.IsNullOrEmpty(this.RedmineUser))
            {
                //Get authenticity token from the server
                XhtmlPage   page1 = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(LoginRelativeUri)));
                XmlNodeList nodes = page1.XmlDocument.GetElementsByTagName("input");
                AuthenticityToken = String.Empty;
                foreach (XmlNode node in nodes)
                {
                    if (node.Attributes["name"].Value == "authenticity_token")
                    {
                        AuthenticityToken = node.Attributes["value"].Value;
                    }
                }
                //Now we can log in
                string requestData = String.Format(LoginRequest,
                                                   System.Web.HttpUtility.UrlEncode(
                                                       this.ConstructUri(ProjectListRelativeUri).ToString()),
                                                   System.Web.HttpUtility.UrlEncode(this.RedmineUser),
                                                   System.Web.HttpUtility.UrlEncode(this.RedminePassword),
                                                   System.Web.HttpUtility.UrlEncode(AuthenticityToken));
                XhtmlPage page = new XhtmlPage(this.httpHelper.PostUrlEncodedWebRequest(this.ConstructUri(LoginRelativeUri), requestData));

                // if we get a feed with projects, we assume that we are successfully authenticated
                // if we do get xhtml, it's the login form again
                // this solution is quite ugly, but redmine doesn't provide much help in knowing what went wrong anyway...
                if (page.XmlDocument.DocumentElement != null && page.XmlDocument.DocumentElement.Name == "feed")
                {
                    this.authenticated = true;
                }
                else
                {
                    throw new AuthenticationException("Authentication in Redmine failed.");
                }
            }
        }
コード例 #11
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of all the available projects
        /// </summary>
        /// <returns>List of all the projects available to the user</returns>
        public List<Project> GetProjects()
        {
            if (_cache.Projects != null)
            {
                return _cache.Projects;
            }

            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(ProjectListRelativeUri)));
            List<Project> projects = new List<Project>();
            foreach (AtomEntry entry in AtomParser.ParseFeed(page.XmlDocument))
            {
                projects.Add(new Project
                                 {
                                     Id = entry.NumericId,
                                     Name = entry.Title
                                 });
            }

            _cache.Projects = projects;
            return projects;
        }
コード例 #12
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of all available project activities
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the activities available for the user</returns>
        public List<Activity> GetActivities(int projectId)
        {
            if (_cache.GetActivities(projectId) != null)
            {
                return _cache.GetActivities(projectId);
            }
            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(TimeLogFormRelativeUri, projectId))));

            List<Activity> activities = new List<Activity>();
            foreach (KeyValuePair<int, string> kv in page.GetSelectOptions("time_entry_activity_id"))
            {
                activities.Add(new Activity() { Id = kv.Key, Description = kv.Value });
            }

            _cache.SetActivities(projectId, activities);
            return activities;
        }
コード例 #13
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of all available project issue statuses
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the issue statuses available for the user in selected project</returns>
        public List<Status> GetStatuses(int projectId)
        {
            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List<Status> statuses = new List<Status>();
            foreach (KeyValuePair<int, string> kv in page.GetSelectOptions("issue_status_id"))
            {
                statuses.Add(new Status() { Id = kv.Key, Name = kv.Value });
            }

            return statuses;
        }
コード例 #14
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of recent project activity
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <param name="activityTypes">The activity types you want to return.</param>
        /// <returns>
        /// List of all the project activities of the desired types.
        /// </returns>
        public List<ProjectActivity> GetRecentActivity(int projectId, params RecentActivityType[] activityTypes)
        {
            StringBuilder sb = new StringBuilder();
            foreach (RecentActivityType activityType in activityTypes)
            {
                switch (activityType)
                {
                    case RecentActivityType.Issues:
                        sb.Append("&show_issues=1");
                        break;
                    case RecentActivityType.Changesets:
                        sb.Append("&show_changesets=1");
                        break;
                    case RecentActivityType.News:
                        sb.Append("&show_news=1");
                        break;
                    case RecentActivityType.Documents:
                        sb.Append("&show_documents=1");
                        break;
                    case RecentActivityType.Files:
                        sb.Append("&show_files=1");
                        break;
                    case RecentActivityType.WikiEdits:
                        sb.Append("&show_wiki_edits=1");
                        break;
                    case RecentActivityType.Messages:
                        sb.Append("&show_messages=1");
                        break;
                }
            }

            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(RecentActivitiesRelativeUri, projectId, sb))));
            List<ProjectActivity> activities = new List<ProjectActivity>();
            foreach (AtomEntry entry in AtomParser.ParseFeed(page.XmlDocument))
            {
                activities.Add(new ProjectActivity
                                   {
                                       Title = entry.Title,
                                       Content = entry.Content,
                                       Url = entry.Id,
                                       Updated = DateTime.Parse(entry.Updated),
                                       AuthorName = entry.Author.Name,
                                       AuthorEmail = entry.Author.Email
                                   });
            }

            return activities;
        }
コード例 #15
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of all available project trackers
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the trackers available for the user in selected project</returns>
        public List<Tracker> GetTrackers(int projectId)
        {
            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List<Tracker> trackers = new List<Tracker>();
            foreach (KeyValuePair<int, string> kv in page.GetSelectOptions("issue_tracker_id"))
            {
                trackers.Add(new Tracker() { Id = kv.Key, Name = kv.Value });
            }

            return trackers;
        }
コード例 #16
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of all versions project issue can target
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the versions available for the user in selected project</returns>
        public List<Version> GetVersions(int projectId)
        {
            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List<Version> versions = new List<Version>();
            foreach (KeyValuePair<int, string> kv in page.GetSelectOptions("issue_fixed_version_id"))
            {
                versions.Add(new Version() { Id = kv.Key, Name = kv.Value });
            }

            return versions;
        }
コード例 #17
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of all the users available as watchers for the project
        /// </summary>
        /// <param name="projectId">ID of the project</param>
        /// <returns>List of all the users available as watchers for the project</returns>
        public List<User> GetWatchers(int projectId)
        {
            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(NewIssueRelativeUri, projectId))));
            List<User> watchers = new List<User>();
            foreach (KeyValuePair<int, string> kv in page.GetCheckBoxOptions("issue[watcher_user_ids][]"))
            {
                watchers.Add(new User() { Id = kv.Key, Name = kv.Value });
            }

            return watchers;
        }
コード例 #18
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Logs user into Redmine
        /// </summary>
        public void LogIn()
        {
            if (!this.authenticated && !string.IsNullOrEmpty(this.RedmineUser))
            {
                //Get authenticity token from the server
                XhtmlPage page1 = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(LoginRelativeUri)));
                XmlNodeList nodes = page1.XmlDocument.GetElementsByTagName("input");
                AuthenticityToken = String.Empty;
                foreach (XmlNode node in nodes)
                {
                    if (node.Attributes["name"].Value == "authenticity_token")
                    {
                        AuthenticityToken = node.Attributes["value"].Value;
                    }
                }
                //Now we can log in
                string requestData = String.Format(LoginRequest,
                                                   System.Web.HttpUtility.UrlEncode(
                                                       this.ConstructUri(ProjectListRelativeUri).ToString()),
                                                   System.Web.HttpUtility.UrlEncode(this.RedmineUser),
                                                   System.Web.HttpUtility.UrlEncode(this.RedminePassword),
                                                   System.Web.HttpUtility.UrlEncode(AuthenticityToken));
                XhtmlPage page = new XhtmlPage(this.httpHelper.PostUrlEncodedWebRequest(this.ConstructUri(LoginRelativeUri), requestData));

                // if we get a feed with projects, we assume that we are successfully authenticated
                // if we do get xhtml, it's the login form again
                // this solution is quite ugly, but redmine doesn't provide much help in knowing what went wrong anyway...
                if (page.XmlDocument.DocumentElement != null && page.XmlDocument.DocumentElement.Name == "feed")
                {
                    this.authenticated = true;
                }
                else
                {
                    throw new AuthenticationException("Authentication in Redmine failed.");
                }
            }
        }
コード例 #19
0
ファイル: Redmine.cs プロジェクト: bdrhoa/redmine-client
        /// <summary>
        /// Gets the list of all the available issues
        /// </summary>
        /// <param name="projectId">Project Id</param>
        /// <returns>List of all the available issues for the project</returns>
        public List<Issue> GetIssues(int projectId)
        {
            if (_cache.GetIssues(projectId) != null)
            {
                return _cache.GetIssues(projectId);
            }
            XhtmlPage page = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(String.Format(IssueListRelativeUri, projectId))));
            List<Issue> issues = new List<Issue>();
            foreach (AtomEntry entry in AtomParser.ParseFeed(page.XmlDocument))
            {
                issues.Add(new Issue
                {
                    Id = entry.NumericId,
                    Subject = entry.Title
                });
            }

            _cache.SetIssues(projectId, issues);
            return issues;
        }