Ejemplo n.º 1
0
 /// <summary>
 /// Adds an existing user to a group. This method does not block the calling thread.
 /// </summary>
 /// <param name="groupId">The group id.</param>
 /// <param name="userId">The user id.</param>
 /// <returns>Returns the Guid associated with the async request.</returns>
 public Guid AddUserToGroupAsync(int groupId, int userId)
 {
     using (var wc = CreateWebClient(null))
     {
         var id         = Guid.NewGuid();
         var asyncToken = new AsyncToken {
             Method = RedmineMethod.AddUserToGroup, Parameter = userId, TokenId = id
         };
         wc.DownloadStringCompleted += WcDownloadStringCompleted;
         wc.UploadStringAsync(new Uri(string.Format(REQUEST_FORMAT, host, urls[typeof(Group)], groupId + "/users", mimeFormat)), POST, mimeFormat == MimeFormat.xml ? "<user_id>" + userId + "</user_id>" : "user_id:" + userId, asyncToken);
         return(id);
     }
 }
Ejemplo n.º 2
0
        public Guid GetObjectListAsync <T>(NameValueCollection parameters)
        {
            if (!urls.ContainsKey(typeof(T)))
            {
                return(Guid.Empty);
            }

            using (var wc = CreateWebClient(parameters))
            {
                var id   = Guid.NewGuid();
                var type = typeof(T);
                wc.DownloadStringCompleted += WcDownloadStringCompleted;

                var asyncToken = new AsyncToken {
                    Method = RedmineMethod.GetObjectList, ResponseType = type, TokenId = id, JsonRoot = urls[type]
                };

                if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership))
                {
                    string projectId = GetOwnerId(parameters, "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.");
                    }

                    wc.DownloadStringAsync(new Uri(string.Format(ENTITY_WITH_PARENT_FORMAT, host, "projects", projectId, urls[type], mimeFormat)), asyncToken);
                }
                else
                if (type == typeof(IssueRelation))
                {
                    string issueId = GetOwnerId(parameters, "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");
                    }
                    wc.DownloadStringAsync(new Uri(string.Format(ENTITY_WITH_PARENT_FORMAT, host, "issues", issueId, urls[type], mimeFormat)), asyncToken);
                }
                else
                {
                    wc.DownloadStringAsync(new Uri(string.Format(FORMAT, host, urls[type], mimeFormat)), asyncToken);
                }
                return(id);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates a Redmine object. This method does not block the calling thread.
        /// </summary>
        /// <typeparam name="T">The type of object to be update.</typeparam>
        /// <param name="id">The id of the object to be update.</param>
        /// <param name="obj">The object to be update.</param>
        /// <param name="projectId"></param>
        /// <returns>Returns the Guid associated with the async request.</returns>
        public Guid UpdateObjectAsync <T>(string id, T obj, string projectId = null) where T : class, new()
        {
            var type = typeof(T);

            if (!urls.ContainsKey(type))
            {
                return(Guid.Empty);
            }

            var request = Serialize(obj);

            if (string.IsNullOrEmpty(request))
            {
                return(Guid.Empty);
            }

            using (var wc = CreateWebClient(null))
            {
                var guid       = Guid.NewGuid();
                var asyncToken = new AsyncToken {
                    Method = RedmineMethod.UpdateObject, ResponseType = type, Parameter = obj, TokenId = guid
                };
                wc.DownloadStringCompleted += WcDownloadStringCompleted;
                if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership))
                {
                    if (string.IsNullOrEmpty(projectId))
                    {
                        throw new RedmineException("The project owner id is mandatory!");
                    }
                    wc.UploadStringAsync(new Uri(string.Format(ENTITY_WITH_PARENT_FORMAT, host, "projects", projectId, urls[type], mimeFormat)), PUT, request, asyncToken);
                }
                else
                {
                    wc.UploadStringAsync(new Uri(string.Format(REQUEST_FORMAT, host, urls[type], id, mimeFormat)), PUT, request, asyncToken);
                }
                return(guid);
            }
        }