/// <summary>
        /// Stops the work progress of an Issue
        /// </summary>
        /// <param name="issueKey">The key of the issue whose progress is being stopped</param>
        public void StopIssueProgress(string issueKey)
        {
            string actionId = ((int)JiraWorkflowAction.STOP_PROGRESS).ToString();

            // No special parameters for this action
            RemoteFieldValue[] actionParams = new RemoteFieldValue[0];
            JiraSoapHelper.GetJiraSoapServiceProxy().progressWorkflowAction(AuthenticationToken, issueKey, actionId, actionParams);
        }
        /// <summary>
        /// Adds a comment to an Issue
        /// </summary>
        /// <param name="comment">The <c>RemoteComment</c> to add to the issue</param>
        /// <param name="issueKey">The key of the issue to which the comment will be added</param>
        public void AddCommentToIssue(string issueKey, IssueComment comment)
        {
            RemoteComment rc = new RemoteComment();

            rc.body          = comment.Text;
            rc.timePerformed = comment.Date;
            rc.username      = comment.Author;
            JiraSoapHelper.GetJiraSoapServiceProxy().addComment(this.AuthenticationToken, issueKey, rc);
        }
        /// <summary>
        /// Gets all the available resolutions from the JIRA Server Instance
        /// </summary>
        /// <returns>A generic dictionary of strings representing the resolution names and keys</returns>
        public List <KeyValuePair <string, string> > GetAvailableResolutions()
        {
            List <KeyValuePair <string, string> > ret = new List <KeyValuePair <string, string> >();

            RemoteResolution[] resolutions = JiraSoapHelper.GetJiraSoapServiceProxy().getResolutions(this.AuthenticationToken);
            foreach (RemoteResolution resolution in resolutions)
            {
                ret.Add(new KeyValuePair <string, string>(resolution.id, resolution.name));
            }
            return(ret);
        }
        /// <summary>
        /// Gets all the available workflow actions for a given issue
        /// </summary>
        /// <param name="issueKey">The Key of the issue whose available actions we want to know</param>
        /// <returns>A List of integers, each one representing the ID of an available actions</returns>
        public List <int> GetAvailableActions(string issueKey)
        {
            List <int> ret = new List <int>();

            RemoteNamedObject[] availableActions = JiraSoapHelper.GetJiraSoapServiceProxy().getAvailableActions(AuthenticationToken, issueKey);
            foreach (RemoteNamedObject o in availableActions)
            {
                ret.Add(Int32.Parse(o.id));
            }
            return(ret);
        }
        /// <summary>
        /// Gets all the available project keys in a JIRA Server Instance to which the user has access
        /// </summary>
        /// <returns>An array of strings containing the project keys</returns>
        public List <string> GetAllProjectKeysForCurrenUser()
        {
            RemoteProject[] projects = JiraSoapHelper.GetJiraSoapServiceProxy().getProjects(this.AuthenticationToken);
            List <string>   keys     = new List <string>();

            foreach (RemoteProject rp in projects)
            {
                keys.Add(rp.key);
            }
            return(keys);
        }
        /// <summary>
        /// Uses JIRA SOAP Service in order to obtain a Project ID from a Project Key
        /// </summary>
        private string GetProjectIdFromProjectKey(string projectKey)
        {
            string ret = String.Empty;

            RemoteProject[] projects = JiraSoapHelper.GetJiraSoapServiceProxy().getProjects(this.AuthenticationToken);
            foreach (RemoteProject rp in projects)
            {
                if (String.Equals(rp.key, projectKey))
                {
                    ret = rp.id;
                }
            }
            return(ret);
        }
        /// <summary>
        /// Get all te comments associated with a specified issue
        /// </summary>
        /// <param name="issueKey">The Key of the Issue whose comments are to be retrieved </param>
        /// <returns>A generic list of <c>IssueComment</c> entities</returns>
        public List <IssueComment> GetIssueComments(string issueKey)
        {
            List <IssueComment> issueComments = new List <IssueComment>();

            //Obtains an array of JIRA's RemoteComment entities and converts each one of them into a IssueComment entity
            RemoteComment[] comments =
                JiraSoapHelper.GetJiraSoapServiceProxy().getComments(this.AuthenticationToken, issueKey);

            foreach (RemoteComment comment in comments)
            {
                issueComments.Add(new IssueComment(comment.username, comment.timePerformed, comment.body));
            }

            return(issueComments);
        }
        /// <summary>
        /// Progress the workflow of and Issue in order to resolve it or close it
        /// </summary>
        /// <param name="actionId">The string representation of the numeric id corresponding to the workflow action to perform</param>
        /// <param name="issueKey">The key of the Issue to resolve</param>
        /// <param name="resolutionKey">The resolution key of the issue</param>
        /// <param name="resolutionComment">An optional comment related to the action</param>
        /// <param name="fixVersions">A list a list containing all the Issue fix versions' ID's</param>
        /// <param name="affectsVersions">A list a list containing all the Issue affects versions' ID's</param>
        public void ProgressWorkflowForResolution(string actionId, string issueKey, string resolutionKey, string resolutionComment, string[] fixVersions, string[] affectsVersions)
        {
            RemoteCustomFieldValue[] customFields = this.GetIssueCustomFields(issueKey);

            List <RemoteFieldValue> actionParams = new List <RemoteFieldValue>();

            RemoteFieldValue asigneeParam = new RemoteFieldValue();

            asigneeParam.id     = "assignee";
            asigneeParam.values = new string[] { "-1" }; //Automatic
            actionParams.Add(asigneeParam);

            RemoteFieldValue resolutionParam = new RemoteFieldValue();

            resolutionParam.id     = "resolution";
            resolutionParam.values = new string[] { resolutionKey };
            actionParams.Add(resolutionParam);

            RemoteFieldValue fixVersionsParam = new RemoteFieldValue();

            fixVersionsParam.id     = "fixVersions";
            fixVersionsParam.values = fixVersions;
            actionParams.Add(fixVersionsParam);

            RemoteFieldValue affectsVersionsParam = new RemoteFieldValue();

            affectsVersionsParam.id     = "affectsVersions";
            affectsVersionsParam.values = affectsVersions;
            actionParams.Add(affectsVersionsParam);

            foreach (RemoteCustomFieldValue customField in customFields)
            {
                RemoteFieldValue customFieldParam = new RemoteFieldValue();
                customFieldParam.id = customField.customfieldId;
                //Nasty workaround for the fact that the SOAP API returns the same id for both items in a Cascading Select Custom Field
                foreach (RemoteFieldValue ap in actionParams)
                {
                    if (ap.id.Equals(customFieldParam.id))
                    {
                        customFieldParam.id += ":1";
                    }
                }
                customFieldParam.values = customField.values;
                actionParams.Add(customFieldParam);
            }

            JiraSoapHelper.GetJiraSoapServiceProxy().progressWorkflowAction(AuthenticationToken, issueKey, actionId, actionParams.ToArray());
        }
        /// <summary>
        /// Gets a list of Version ID's according to those Versions Names
        /// </summary>
        /// <param name="versionNames">The list containing the versions names whose IDs we want to get</param>
        /// <returns>A list containing the IDs of the appropiate versions</returns>
        public List <string> GetVersionsIdsFromVersionNames(string[] versionNames)
        {
            List <string> versionIDs = new List <string>();

            RemoteVersion[] projectVersions =
                JiraSoapHelper.GetJiraSoapServiceProxy().getVersions(AuthenticationToken, JiraConfigurationHelper.getCurrentProjectKey());

            foreach (string name in versionNames)
            {
                foreach (RemoteVersion projectVersion in projectVersions)
                {
                    if (projectVersion.name.Equals(name))
                    {
                        versionIDs.Add(projectVersion.id);
                        break;
                    }
                }
            }
            return(versionIDs);
        }
 /// <summary>
 /// Authenticates a user in a JIRA Implementation
 /// </summary>
 /// <param name="userName">The JIRA UserName</param>
 /// <param name="password">The password for that UserName in clear text</param>
 /// <returns>A boolean indicating where the login attempt was successful or not</returns>
 public bool AuthenticateUser(string userName, string password)
 {
     this.authenticationToken = JiraSoapHelper.GetJiraSoapServiceProxy().login(userName, password);
     return(true);
 }
 private RemoteCustomFieldValue[] GetIssueCustomFields(string issueKey)
 {
     return(JiraSoapHelper.GetJiraSoapServiceProxy().getIssue(AuthenticationToken, issueKey).customFieldValues);
 }
        /// <summary>
        /// Authenticates a user in a JIRA Server instance, generating an authentication token
        /// that is saved for future calls between JiraConnector and the server.
        /// </summary>
        /// <param name="url">The URL of the JIRA Server Instance</param>
        /// <param name="port">The corresponding port</param>
        /// <param name="username">The username to authenticate</param>
        /// <param name="password">The password corresponding to the user</param>
        public void AuthenticateUser(string url, string port, string username, string password)
        {
            JiraSoapServiceService proxy = JiraSoapHelper.GetJiraSoapServiceProxy(url, port);

            this.authenticationToken = proxy.login(username, password);
        }