Exemplo n.º 1
0
        /// <summary>
        /// Gets the list URL.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="redmineManager">The redmine manager.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException"></exception>
        /// <exception cref="Redmine.Net.Api.Exceptions.RedmineException">
        /// The project id is mandatory! \nCheck if you have included the parameter project_id to parameters.
        /// or
        /// The issue id is mandatory! \nCheck if you have included the parameter issue_id to parameters
        /// </exception>
        public static string GetListUrl <T>(RedmineManager redmineManager
                                            , System.Collections.Specialized.NameValueCollection parameters)
            where T : class, new()
        {
            System.Type type = typeof(T);

            if (!RedmineManager.Sufixes.ContainsKey(type))
            {
                throw new System.Collections.Generic.KeyNotFoundException(type.Name);
            }

            if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership))
            {
                string projectId = parameters.GetParameterValue(RedmineKeys.PROJECT_ID);
                if (string.IsNullOrEmpty(projectId))
                {
                    throw new RedmineException("The project id is mandatory! \nCheck if you have included the parameter project_id to parameters.");
                }

                return(string.Format(ENTITY_WITH_PARENT_FORMAT, redmineManager.Host, RedmineKeys.PROJECTS,
                                     projectId, RedmineManager.Sufixes[type], redmineManager.MimeFormat.ToString().ToLower()));
            }
            if (type == typeof(IssueRelation))
            {
                string issueId = parameters.GetParameterValue(RedmineKeys.ISSUE_ID);
                if (string.IsNullOrEmpty(issueId))
                {
                    throw new RedmineException("The issue id is mandatory! \nCheck if you have included the parameter issue_id to parameters");
                }

                return(string.Format(ENTITY_WITH_PARENT_FORMAT, redmineManager.Host, RedmineKeys.ISSUES,
                                     issueId, RedmineManager.Sufixes[type], redmineManager.MimeFormat.ToString().ToLower()));
            }
            return(string.Format(FORMAT, redmineManager.Host, RedmineManager.Sufixes[type],
                                 redmineManager.MimeFormat.ToString().ToLower()));
        }