Пример #1
0
        /// <summary>
        /// Start creating a scan report.
        /// </summary>
        /// <param name="scanId">
        /// The scan ID to generate a report for.
        /// </param>
        /// <param name="reportType">
        /// The report type.
        /// </param>
        /// <returns>
        /// The report ID.
        /// </returns>
        /// <exception cref="CheckmarxErrorException">
        /// The Checkmarx API returned an unexpected error.
        /// </exception>
        /// <exception cref="CheckmarxCommunicationException">
        /// An error occurred communicating with the Checkmarx server.
        /// </exception>
        public long CreateScanReport(long scanId, CxWSReportType reportType)
        {
            CxWSReportRequest reportRequest;

            reportRequest = new CxWSReportRequest()
            {
                ScanID = scanId,
                Type   = reportType
            };

            return(CallCheckmarxApi(() => SoapClient.CreateScanReport(SessionId, reportRequest)).ID);
        }
        /// <summary>
        /// Generate a Checkmarx scan report for the most recent scan for the given project.
        /// </summary>
        /// <param name="checkmarxApiSession">
        /// The <see cref="ICheckmarxApiSession"/> to generate the report with. This cannot be null.
        /// </param>
        /// <param name="project">
        /// The project to get the last scan for. This cannot be null.
        /// </param>
        /// <param name="reportType">
        /// The result format for the report.
        /// </param>
        /// <returns>
        /// An <see cref="XDocument"/> containing the loaded scan report.
        /// </returns>
        /// <exception cref="CheckmarxErrorException">
        /// Either the report generation failed or Checkmarx returned invalid XML for the scan report.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// no argument can be null.
        /// </exception>
        private static byte[] GenerateLastScanReport(ICheckmarxApiSession checkmarxApiSession,
                                                     ProjectScannedDisplayData project, CxWSReportType reportType)
        {
            if (checkmarxApiSession == null)
            {
                throw new ArgumentNullException(nameof(checkmarxApiSession));
            }
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }
            if (!Enum.IsDefined(typeof(CxWSReportType), reportType))
            {
                throw new ArgumentOutOfRangeException(nameof(reportType));
            }

            long reportId;

            reportId = checkmarxApiSession.CreateScanReport(project.LastScanID, reportType);
            for (;;)
            {
                CxWSReportStatusResponse reportStatusResponse = checkmarxApiSession.GetScanReportStatus(reportId);
                if (reportStatusResponse.IsFailed)
                {
                    throw new CheckmarxErrorException(
                              $"Generating report ID {reportId} on scan {project.LastScanID} on project {project.ProjectName} failed");
                }
                else if (reportStatusResponse.IsReady)
                {
                    break;
                }

                // TODO: Consider a better mechanism
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));

                // TODO: Consider a timeout
            }

            return(checkmarxApiSession.GetScanReport(reportId));
        }