/// <summary>
        /// Deletes a given user by the ID given. You should ensure that projects, scans and reports are properly
        /// assigned to others before making this call. Not doing so can result in orphaned/loss of data. Only those
        /// with Server Manager or Company Manager roles assigned may delete users in Checkmarx.
        /// </summary>
        /// <param name="userId">User ID to delete.</param>
        /// <returns>bool</returns>
        /// <see cref="GetAllUsers"/>
        public bool DeleteUser(int userId)
        {
            if (_sessionId == null)
            {
                throw new AuthenticationException();
            }

            bool deleted = false;

            try
            {
                CxSDKWebService.CxWSBasicRepsonse response =
                    CallCheckmarxApi(() => SoapClient.DeleteUser(_sessionId, userId));
                deleted = response.IsSuccesfull;
            }
            catch (ResponseException e)
            {
                log.Error(String.Format("Unable to get projects to display: {0} {1}", e.GetType().Name, e.Message), e);
            }
            catch (CommunicationException e)
            {
                log.Error(String.Format("Unable to communicate to SOAP API at endpoint {0}: {1} {2}", _endpoint.DnsSafeHost, e.GetType().Name, e.Message), e);
            }

            return(deleted);
        }
        /// <summary>
        /// Deletes requested scans. Scans that are currently running won't be deleted. If there's even a single scan that the user can't
        /// delete (due to security reasons) the operation will fail and an error message is returned.
        /// </summary>
        /// <param name="scanIds">Scan IDs to delete</param>
        /// <returns>bool</returns>
        /// <see cref="GetScanStatus(string)"/>
        public bool DeleteScans(long[] scanIds)
        {
            if (_sessionId == null)
            {
                throw new AuthenticationException();
            }

            CxSDKWebService.ArrayOfLong aLong = new CxSDKWebService.ArrayOfLong();
            foreach (long scanId in scanIds)
            {
                aLong.Add(scanId);
            }

            bool deleted = false;

            try
            {
                CxSDKWebService.CxWSBasicRepsonse response =
                    CallCheckmarxApi(() => SoapClient.DeleteScans(_sessionId, aLong));
                deleted = response.IsSuccesfull;
            }
            catch (ResponseException e)
            {
                log.Error(String.Format("Error, unable to delete scan(s): {0}", e.Message), e);
            }
            catch (CommunicationException e)
            {
                log.Error(String.Format("Unable to communicate to SOAP API at endpoint {0}: {1} {2}", _endpoint.DnsSafeHost, e.GetType().Name, e.Message), e);
            }

            return(deleted);
        }
        /// <summary>
        /// Cancel a scan in progress. The scan can be canceled while waiting in the queue or during a scan.
        /// </summary>
        /// <param name="runId">Run ID</param>
        /// <returns>bool</returns>
        /// <see cref="Scan(CxSDKWebService.ProjectSettings, CxSDKWebService.SourceCodeSettings, bool, bool, string, long, long)"/>
        /// <see cref="GetScanStatus(string)"/>
        public bool CancelScan(string runId)
        {
            if (_sessionId == null)
            {
                throw new AuthenticationException();
            }

            bool canceled = false;

            try
            {
                CxSDKWebService.CxWSBasicRepsonse response =
                    CallCheckmarxApi(() => SoapClient.CancelScan(_sessionId, runId));
                canceled = response.IsSuccesfull;
            }
            catch (ResponseException e)
            {
                log.Error(String.Format("Error, unable to cancel scan {1}: {0}", e.Message, runId), e);
            }
            catch (CommunicationException e)
            {
                log.Error(String.Format("Unable to communicate to SOAP API at endpoint {0}: {1} {2}", _endpoint.DnsSafeHost, e.GetType().Name, e.Message), e);
            }

            return(canceled);
        }
        /// <summary>
        /// Add a comment to scan results. If there is already a comment, it will be overwritten.
        /// </summary>
        /// <param name="scanId">Scan ID</param>
        /// <param name="comment">Comment to add/overwrite</param>
        /// <returns>bool</returns>
        public bool UpdateScanComment(long scanId, string comment)
        {
            if (_sessionId == null)
            {
                throw new AuthenticationException();
            }

            bool updated = false;

            try
            {
                CxSDKWebService.CxWSBasicRepsonse response =
                    CallCheckmarxApi(() => SoapClient.UpdateScanComment(_sessionId, scanId, comment));
                updated = response.IsSuccesfull;
            }
            catch (ResponseException e)
            {
                log.Error(String.Format("Error, unable to update comment for scan {1}: {0}", e.Message, scanId), e);
            }
            catch (CommunicationException e)
            {
                log.Error(String.Format("Unable to communicate to SOAP API at endpoint {0}: {1} {2}", _endpoint.DnsSafeHost, e.GetType().Name, e.Message), e);
            }

            return(updated);
        }
        /// <summary>
        /// Updates a project by the given ID with the given configuration and returns whether or not this process
        /// was successfull.
        /// </summary>
        /// <param name="projectId">Project ID</param>
        /// <param name="configuration">Project Configuration</param>
        /// <returns>bool</returns>
        /// <seealso cref="https://checkmarx.atlassian.net/wiki/spaces/KC/pages/5767327/Project+Configuration+Members"/>
        /// <see cref="GetProjectConfiguration(long)"/>
        /// <example>
        /// using(CxWebService service = new CxWebService())
        /// {
        ///     if(service.Login(username, password))
        ///     {
        ///         long projectId = 200;
        ///         long presetId = 100035; //A custom preset
        ///         long scanConfigurationId = 4; //Multi-Language Scan
        ///
        ///         CxSDKWebService.ProjectConfiguration configuration = service.GetProjectConfiguration(projectId);
        ///         configuration.PresetID = presetId;
        ///         configuration.ScanConfigurationID = scanConfigurationId;
        ///
        ///         Console.Write("Updating project {0}: ", projectId);
        ///         bool updated = service.UpdateProjectIncrementalConfiguration(projectId, configuration))
        ///         Console.WriteLine("{0}.", (updated ? "OK" : "FAILED"));
        ///     }
        /// }
        /// </example>
        public bool UpdateProjectIncrementalConfiguration(long projectId, CxSDKWebService.ProjectConfiguration configuration)
        {
            if (_sessionId == null)
            {
                throw new AuthenticationException();
            }

            bool wasUpdated = false;

            try
            {
                CxSDKWebService.CxWSBasicRepsonse response =
                    CallCheckmarxApi(() => SoapClient.UpdateProjectIncrementalConfiguration(_sessionId, projectId, configuration));
                wasUpdated = response.IsSuccesfull;
            }
            catch (ResponseException e)
            {
                log.Error(String.Format("Unable to update project {2} configuration: {0} {1}", e.GetType().Name, e.Message, projectId), e);
            }
            catch (CommunicationException e)
            {
                log.Error(String.Format("Unable to communicate to SOAP API at endpoint {0}: {1} {2}", _endpoint.DnsSafeHost, e.GetType().Name, e.Message), e);
            }

            return(wasUpdated);
        }
示例#6
0
 static void GuardResponseSuccessfull(CxSDKWebService.CxWSBasicRepsonse response)
 {
     if (!response.IsSuccesfull)
     {
         throw new Exception(response.ErrorMessage);
     }
 }