public ConfigurationResult GetConfigurationList(string sessionId, BackgroundWorkerHelper bg, CxWebServiceClient client) { ConfigurationResult configuration = null; bg.DoWorkFunc = delegate(object obj) { configuration = new ConfigurationResult(); CxWSResponseConfigSetList cxWSResponseConfigSetList = client.ServiceClient.GetConfigurationSetList(sessionId); configuration.IsSuccesfull = cxWSResponseConfigSetList.IsSuccesfull; configuration.Configurations = new Dictionary <long, string>(); if (cxWSResponseConfigSetList != null && cxWSResponseConfigSetList.ConfigSetList.Length > 0) { for (int i = 0; i < cxWSResponseConfigSetList.ConfigSetList.Length; i++) { configuration.Configurations.Add(cxWSResponseConfigSetList.ConfigSetList[i].ID, cxWSResponseConfigSetList.ConfigSetList[i].ConfigSetName); } } }; if (!bg.DoWork("Receive Configuration list...")) { return(null); } return(configuration); }
private void ShowScanData(ref CxWSQueryVulnerabilityData[] scanData, ref long scanId, CxWebServiceClient client) { // Get url to scanned project result string savedFileName = string.Format("report{0}", Guid.NewGuid()); long id = 0; CxWSResponseScanStatus scanStatus = client.ServiceClient.GetStatusOfSingleScan(_scan.LoginResult.SessionId, _scan.RunScanResult.ScanId); string ScanTaskId = scanStatus.ScanId.ToString();//after scan is finished the server replaces the scan id with task scan id scanData = PerspectiveHelper.GetScanResultsPaths(ScanTaskId, ref scanId); id = scanId; LoginData.BindProject bindProject = _scan.LoginResult.AuthenticationData.BindedProjects.Find(project => project.BindedProjectId == CommonData.ProjectId && project.ProjectName == CommonData.ProjectName && project.RootPath == CommonData.ProjectRootPath); if (bindProject == null) // scaned for the first time { bindProject = new LoginData.BindProject(); bindProject.ProjectName = CommonData.ProjectName; bindProject.RootPath = CommonData.ProjectRootPath; bindProject.IsBound = true; _scan.LoginResult.AuthenticationData.BindedProjects.Add(bindProject); } if (!CommonData.IsProjectBound) // its new project { bindProject.BindedProjectId = scanStatus.ProjectId; CommonData.ProjectId = scanStatus.ProjectId; CommonData.IsProjectPublic = scanStatus.IsPublic; bindProject.IsPublic = scanStatus.IsPublic; bindProject.IsBound = true; } bindProject.SelectedScanId = id; bindProject.ScanReports = new List <ScanReportInfo>(); LoginHelper.Save(_scan.LoginResult.AuthenticationData); BackgroundWorkerHelper bgWork = new BackgroundWorkerHelper(delegate { CommonData.SelectedScanId = id; String path = PerspectiveHelper.GetScanXML(id); ScanReportInfo scanReportInfo = new ScanReportInfo(); scanReportInfo.Path = path; scanReportInfo.Id = id; LoginData.BindProject projectToUpdate = _scan.LoginResult.AuthenticationData.BindedProjects.Find(delegate(LoginData.BindProject bp) { return(bp.BindedProjectId == CommonData.ProjectId); } ); projectToUpdate.ScanReports = new List <ScanReportInfo>(); projectToUpdate.ScanReports.Add(scanReportInfo); LoginHelper.Save(_scan.LoginResult.AuthenticationData); }); bgWork.DoWork(); }
static ProjectScanStatuses EditRemark(LoginResult loginResult, long resultId, long pathId, string remark) { bool cxWSBasicResponse = false; // show bind project form CxWebServiceClient client = null; bool isThrewError = false; BackgroundWorkerHelper bg = new BackgroundWorkerHelper(delegate(object obj) { try { client = new CxWebServiceClient(loginResult.AuthenticationData); } catch (Exception e) { Common.Logger.Create().Error(e.ToString()); System.Windows.Forms.MessageBox.Show(e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK); isThrewError = true; return; } if (client == null) { System.Windows.Forms.MessageBox.Show("Cannot connect to server", "Error", System.Windows.Forms.MessageBoxButtons.OK); isThrewError = true; return; } ResultStateData[] dataArr = new ResultStateData[1]; dataArr[0] = new ResultStateData() { data = string.Empty, PathId = pathId, Remarks = remark, ResultLabelType = (int)ResultLabelTypeEnum.Remark, scanId = resultId }; cxWSBasicResponse = PerspectiveHelper.UpdateResultState(dataArr); }, loginResult.AuthenticationData.ReconnectInterval * 1000, loginResult.AuthenticationData.ReconnectCount); //Show wait dialog and perform server request in different thread to safe UI responsibility if (!bg.DoWork("Changing remark")) { return(ProjectScanStatuses.CanceledByUser); } if (!cxWSBasicResponse || isThrewError) { return(ProjectScanStatuses.Error); } return(ProjectScanStatuses.Success); }
private byte[] ZipProject(Scan scan, Project project, BackgroundWorkerHelper bg) { byte[] zippedProject = null; bg.DoWorkFunc = delegate(object obj) { string error = string.Empty; zippedProject = ZipHelper.Compress(project, scan.LoginResult.AuthenticationData.ExcludeFileExt, scan.LoginResult.AuthenticationData.ExcludeFolder, scan.LoginResult.AuthenticationData.MaxZipFileSize * 1048576, out error); if (zippedProject == null) { TopMostMessageBox.Show(string.Format("Zip Error: {0}", error), "Zip Error", MessageBoxButtons.OK); } }; //Convert mb to byte bg.DoWork("Zip project before sending..."); return(zippedProject); }
/// <summary> /// Find specified problem description /// </summary> /// <param name="queryId">Problem identifier</param> /// <returns>If file description was found method returns full path to file, otherwise retutn null</returns> public static string GetStoredProblem(int queryId) { QueryDescriptionResult queryResult = new QueryDescriptionResult(); queryResult.QueryId = queryId; string file = queryResult.GetFileDescription(); if (string.IsNullOrEmpty(file)) { if (CommonData.IsWorkingOffline) { MessageBox.Show("You are working offline. \rCannot get data", "Error", MessageBoxButtons.OK); return(null); } BackgroundWorkerHelper bg = new BackgroundWorkerHelper(delegate(object obj) { CxWSResponseQueryDescription cxWSResponseQueryDescription = QueryDescriptionResult.GetById(queryResult.QueryId); queryResult = new QueryDescriptionResult(); queryResult.Description = cxWSResponseQueryDescription.QueryDescription; queryResult.IsSuccesfull = cxWSResponseQueryDescription.IsSuccesfull; queryResult.QueryId = queryId; }, 0, 0); if (!bg.DoWork("Downloading description...")) { return(null); } if (queryResult.IsSuccesfull && queryResult.Save()) { file = queryResult.GetFileDescription(); } } return(file); }
static void BindSelectedProject(LoginResult loginResult, Entities.Project project) { CxWSResponseProjectsDisplayData cxWSResponseProjectsDisplayData = null; // show bind project form CxWebServiceClient client = null; bool isThrewError = false; BackgroundWorkerHelper bg = new BackgroundWorkerHelper(delegate { try { client = new CxWebServiceClient(loginResult.AuthenticationData); } catch (Exception e) { Logger.Create().Error(e.ToString()); System.Windows.Forms.MessageBox.Show(e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK); isThrewError = true; return; } if (client == null) { System.Windows.Forms.MessageBox.Show("Cannot connect to server", "Error", System.Windows.Forms.MessageBoxButtons.OK); isThrewError = true; return; } cxWSResponseProjectsDisplayData = client.ServiceClient.GetProjectsDisplayData(loginResult.SessionId); }, loginResult.AuthenticationData.ReconnectInterval * 1000, loginResult.AuthenticationData.ReconnectCount); //Show wait dialog and perform server request in different thread to safe UI responsibility if (!bg.DoWork(RETRIEVE_RESULTS_LOADING_TEXT)) { return; } if (cxWSResponseProjectsDisplayData == null || !cxWSResponseProjectsDisplayData.IsSuccesfull || isThrewError) { return; } var bindProjectEntity = new BindProjectEntity { CxProjectsDisplayData = cxWSResponseProjectsDisplayData }; #region show Select Project window // if (projectID < 0) // { if (_dispatcher == null) { _dispatcher = ServiceLocators.ServiceLocator.GetDispatcher(); } if (_dispatcher != null) { _dispatcher.Dispatch(bindProjectEntity); } if (bindProjectEntity.CommandResult == System.Windows.Forms.DialogResult.Cancel) { _canceled = true; return; } // } #endregion long selectedProjectId = 0; if (client != null && ((bindProjectEntity.SelectedProject != null && bindProjectEntity.CommandResult == System.Windows.Forms.DialogResult.OK))) { Logger.Create().Info("Loading project id: " + bindProjectEntity.SelectedProject.projectID); bg.DoWorkFunc = delegate(object obj) { selectedProjectId = bindProjectEntity.SelectedProject.projectID; if (loginResult.AuthenticationData.BindedProjects == null) { loginResult.AuthenticationData.BindedProjects = new List <LoginData.BindProject>(); } LoginData.BindProject bindProject = loginResult.AuthenticationData.BindedProjects.Find(delegate(LoginData.BindProject bp) { return(bp.ProjectName == project.ProjectName && bp.RootPath == project.RootPath); } ); bool isNewProject = true; if (bindProject != null) { bindProject.BindedProjectId = selectedProjectId; bindProject.ScanReports = new List <ScanReportInfo>(); bindProject.IsBound = true; bindProject.SelectedScanId = 0; bindProject.IsPublic = bindProjectEntity.isPublic; isNewProject = false; } else { bindProject = new LoginData.BindProject() { BindedProjectId = selectedProjectId, RootPath = project.RootPath, ProjectName = project.ProjectName, ScanReports = new List <ScanReportInfo>(), IsPublic = bindProjectEntity.isPublic, IsBound = true, }; isNewProject = true; } CxWSResponseScansDisplayData cxWSResponseScansDisplayData = PerspectiveHelper.GetScansDisplayData(selectedProjectId); if (cxWSResponseScansDisplayData.ScanList.Length == 0) { // show error about 0 scan list System.Windows.Forms.MessageBox.Show("The chosen project doesn't contain scans", "Error", System.Windows.Forms.MessageBoxButtons.OK); isThrewError = true; return; } foreach (ScanDisplayData item in cxWSResponseScansDisplayData.ScanList) { // Add relation to scanned project and scan report ScanReportInfo scanReportInfo = new ScanReportInfo { Id = item.ScanID }; string minutes = item.QueuedDateTime.Minute.ToString().Length > 1 ? item.QueuedDateTime.Minute.ToString() : "0" + item.QueuedDateTime.Minute; scanReportInfo.Name = string.Format("{0}/{1}/{2} {3}:{4}", item.QueuedDateTime.Month, item.QueuedDateTime.Day, item.QueuedDateTime.Year, item.QueuedDateTime.Hour, minutes); bindProject.AddScanReport(scanReportInfo); } if (bindProject.ScanReports.Count > 0) { CommonData.SelectedScanId = bindProject.ScanReports[0].Id; bindProject.SelectedScanId = CommonData.SelectedScanId; } if (isNewProject) { loginResult.AuthenticationData.BindedProjects.Add(bindProject); } }; bool bCancel = !bg.DoWork("Downloading project data..."); if (!bCancel && !isThrewError) { CommonData.ProjectId = selectedProjectId; LoginHelper.Save(loginResult.AuthenticationData); } } }
/// <summary> /// Set upload params /// </summary> /// <param name="loginResult">Auth user data for uploading</param> /// <param name="project">Selected solution project data</param> /// <returns></returns> internal static Upload SetUploadSettings(LoginResult loginResult, Project project, bool cancelStatus) { cancelStatus = false; PresetResult presetResult = null; TeamResult teamResult = null; BackgroundWorkerHelper bg = new BackgroundWorkerHelper(delegate(object obj) { _client = InitCxClient(loginResult); if (_client == null) { return; } presetResult = GetPresets(loginResult, presetResult); CxWSResponseGroupList teamXmlList = _client.ServiceClient.GetAssociatedGroupsList(loginResult.SessionId); teamResult = new TeamResult(); teamResult.IsSuccesfull = teamXmlList.IsSuccesfull; teamResult.Teams = new Dictionary <string, string>(); if (teamXmlList.GroupList != null && teamXmlList.GroupList.Length > 0) { for (int i = 0; i < teamXmlList.GroupList.Length; i++) { teamResult.Teams.Add(teamXmlList.GroupList[i].ID, teamXmlList.GroupList[i].GroupName); } } if (_client != null) { _client.Close(); } }, loginResult.AuthenticationData.ReconnectInterval * 1000, loginResult.AuthenticationData.ReconnectCount); //Show wait dialog and perform server request in different thread to safe UI responsibility if (!bg.DoWork(PRESETS_LOADING_TEXT)) { cancelStatus = true; return(null); } if (!presetResult.IsSuccesfull) { return(null); } var uploadData = new Upload(new EntityId(loginResult), project.ProjectName, string.Format("{0} Description", project.ProjectName), presetResult.Presets, 0, teamResult.Teams, Guid.Empty.ToString(), true); if (_dispatcher == null) { _dispatcher = ServiceLocators.ServiceLocator.GetDispatcher(); } if (_dispatcher != null) { _dispatcher.Dispatch(uploadData); } return(uploadData); }
private RunScanResult RunScan(BackgroundWorkerHelper bg, CxWebServiceClient client, ConfigurationResult configuration, byte[] zippedProject) { RunScanResult runScanResult = null; bg.DoWorkFunc = delegate(object obj) { ProjectSettings projectSettings = new ProjectSettings(); projectSettings.AssociatedGroupID = _scan.UploadSettings.Team.ToString(); projectSettings.PresetID = _scan.UploadSettings.Preset; projectSettings.ProjectName = _scan.UploadSettings.ProjectName; projectSettings.ScanConfigurationID = configuration.FirstConfigurationKey; LocalCodeContainer localCodeContainer = new LocalCodeContainer(); localCodeContainer.FileName = "zipCxViewer"; localCodeContainer.ZippedFile = zippedProject; try { CxWSResponseRunID cxWSResponseRunID; if (_scan.IsIncremental) { cxWSResponseRunID = client.ServiceClient.RunIncrementalScan( _scan.LoginResult.SessionId, projectSettings, localCodeContainer , _scan.UploadSettings.IsPublic, _scan.IsPublic ); } else { cxWSResponseRunID = client.ServiceClient.CreateAndRunProject( _scan.LoginResult.SessionId, projectSettings, localCodeContainer , _scan.UploadSettings.IsPublic, _scan.IsPublic ); } runScanResult = new RunScanResult(); runScanResult.IsSuccesfull = cxWSResponseRunID.IsSuccesfull; runScanResult.ScanId = cxWSResponseRunID.RunId;//Server actually returns the scanId which is a long number (and not the runID) _scan.LoginResult.AuthenticationData.UnboundRunID = cxWSResponseRunID.RunId; runScanResult.ProjectId = cxWSResponseRunID.ProjectID; _scan.RunScanResult = runScanResult; if (!cxWSResponseRunID.IsSuccesfull) { TopMostMessageBox.Show(string.Format("Scan Error: {0}", cxWSResponseRunID.ErrorMessage), "Scanning Error", MessageBoxButtons.OK); } else { LoginHelper.Save(_scan.LoginResult.AuthenticationData); } } catch (Exception err) { Logger.Create().Error(err.ToString()); TopMostMessageBox.Show(string.Format("Scan Error: {0}", err.Message), "Scanning Error", MessageBoxButtons.OK); } }; if (!bg.DoWork("Upload project zipped source for scanning...")) { return(null); } return(runScanResult); }
private RunScanResult RunBoundedProjectScan(Scan scan, BackgroundWorkerHelper bg, CxWebServiceClient client, byte[] zippedProject) { RunScanResult runScanResult = null; bg.DoWorkFunc = delegate(object obj) { ProjectSettings projectSettings = new ProjectSettings(); projectSettings.projectID = CommonData.ProjectId; LocalCodeContainer localCodeContainer = new LocalCodeContainer(); localCodeContainer.FileName = "zipCxViewer"; localCodeContainer.ZippedFile = zippedProject; try { CxWSResponseRunID cxWSResponseRunID; if (_scan.IsIncremental) { cxWSResponseRunID = client.ServiceClient.RunIncrementalScan( scan.LoginResult.SessionId, projectSettings, localCodeContainer , CommonData.IsProjectPublic, scan.IsPublic ); } else { cxWSResponseRunID = client.ServiceClient.RunScanAndAddToProject( scan.LoginResult.SessionId, projectSettings, localCodeContainer , CommonData.IsProjectPublic, scan.IsPublic ); } runScanResult = new RunScanResult(); // RunScanResult.FromXml(scanZipedSource); runScanResult.IsSuccesfull = cxWSResponseRunID.IsSuccesfull; runScanResult.ScanId = cxWSResponseRunID.RunId; //Server actually returns the scanId which is a long number (and not the runID) scan.LoginResult.AuthenticationData.UnboundRunID = cxWSResponseRunID.RunId; CommonData.ProjectId = cxWSResponseRunID.ProjectID; _scan.RunScanResult = runScanResult; if (!cxWSResponseRunID.IsSuccesfull) { TopMostMessageBox.Show(string.Format("Scan Error: {0}", cxWSResponseRunID.ErrorMessage), "Scanning Error", MessageBoxButtons.OK); } else { LoginHelper.Save(scan.LoginResult.AuthenticationData); } } catch (Exception err) { Logger.Create().Error(err.ToString()); TopMostMessageBox.Show(string.Format("Scan Error: {0}", err.Message), "Scanning Error", MessageBoxButtons.OK); } }; if (!bg.DoWork("Upload project zipped source for scanning...")) { return(null); } return(runScanResult); }
private StatusScanResult UpdateScanStatus(ref bool bCancel, bool backgroundMode, IScanView view, BackgroundWorkerHelper bg, CxWebServiceClient client, ref bool isIISStoped) { // Get current scan status CxWSResponseScanStatus cxWSResponseScanStatus = null; StatusScanResult statusScan = null; bg.DoWorkFunc = delegate(object obj) { cxWSResponseScanStatus = client.ServiceClient.GetStatusOfSingleScan(_scan.LoginResult.SessionId, _scan.RunScanResult.ScanId); statusScan = new StatusScanResult(); statusScan.CurrentStage = cxWSResponseScanStatus.CurrentStage; statusScan.CurrentStagePercent = cxWSResponseScanStatus.CurrentStagePercent; statusScan.Details = cxWSResponseScanStatus.StepDetails; statusScan.IsSuccesfull = cxWSResponseScanStatus.IsSuccesfull; statusScan.QueuePosition = cxWSResponseScanStatus.QueuePosition; statusScan.RunId = cxWSResponseScanStatus.RunId; statusScan.RunStatus = cxWSResponseScanStatus.CurrentStatus; statusScan.StageMessage = cxWSResponseScanStatus.StageMessage; statusScan.StageName = cxWSResponseScanStatus.StageName; statusScan.StepMessage = cxWSResponseScanStatus.StepMessage; statusScan.TimeFinished = cxWSResponseScanStatus.TimeFinished != null?cxWSResponseScanStatus.TimeFinished.ToString() : null; statusScan.TimeStarted = cxWSResponseScanStatus.TimeScheduled != null?cxWSResponseScanStatus.TimeScheduled.ToString() : null; statusScan.TotalPercent = cxWSResponseScanStatus.TotalPercent; }; bCancel = !bg.DoWork(null); if (!BackgroundWorkerHelper.IsReloginInvoked) { isIISStoped = !_scan.LoginResult.AuthenticationData.SaveSastScan; } else { BackgroundWorkerHelper.IsReloginInvoked = false; } if (!bCancel && cxWSResponseScanStatus != null && !isIISStoped) { ScanProgress progress = new ScanProgress( _scan.UploadSettings.ProjectName, statusScan.RunStatus.ToString(), statusScan.StageName, statusScan.StepMessage, statusScan.CurrentStagePercent, 0, 100, statusScan.TotalPercent); if (!backgroundMode) { view.Progress = progress; } try { CommonActionsInstance.getInstance().ScanProgressView.Progress = progress; } catch (Exception ex) { Logger.Create().Error(ex.ToString()); } if (statusScan.RunStatus == CurrentStatusEnum.Failed) { TopMostMessageBox.Show(statusScan.StageMessage, "Scan Error"); bCancel = true; } if (_scan.ScanView == null || _scan.ScanView.Visibility == false) { var scanStatusBar = new ScanStatusBar(true, string.Format("Scaning project {0}: {1} {2}", _scan.UploadSettings.ProjectName, statusScan.StepMessage, statusScan.RunStatus), statusScan.TotalPercent, 100); CommonActionsInstance.getInstance().UpdateScanProgress(scanStatusBar); } } return(statusScan); }
/// <summary> /// Execute scan /// </summary> /// <param name="project">Upload project folder</param> /// <param name="scanData"></param> /// <param name="scanId"></param> /// <returns></returns> private ProjectScanStatuses ExecuteScan(Project project, ref CxWSQueryVulnerabilityData[] scanData, ref long scanId) { Logger.Create().Debug("DoScan in"); bool bCancel = false; bool backgroundMode = _scan.LoginResult.AuthenticationData.IsRunScanInBackground == SimpleDecision.Yes; if (_dispatcher == null) { _dispatcher = ServiceLocators.ServiceLocator.GetDispatcher(); } if (_dispatcher != null) { IScanView view = null; var waitEnd = new ManualResetEvent(false); //if was selected "always run in background" checkbox - hide dialog if (!backgroundMode) { ICommandResult commandResult = _dispatcher.Dispatch(_scan); view = ((ScanPresenter)commandResult).View; } _scan.ScanView = view; BackgroundWorkerHelper bg = new BackgroundWorkerHelper(_scan.LoginResult.AuthenticationData.ReconnectInterval * 1000, _scan.LoginResult.AuthenticationData.ReconnectCount); CxWebServiceClient client = new CxWebServiceClient(_scan.LoginResult.AuthenticationData); client.ServiceClient.Timeout = 1800000; bool isIISStoped = false; bool isScanningEror = false; //User click cancel while info dialog was showed if (!bCancel) { ShowScanProgressBar(); ConfigurationResult configuration = _configurationHelper.GetConfigurationList(_scan.LoginResult.SessionId, bg, client); if (configuration == null) { _cancelPressed = true; } if (!configuration.IsSuccesfull) { LoginHelper.DoLogout(); if (client != null) { client.Close(); } if (view != null) { view.CloseView(); } _scan.InProcess = false; return(ProjectScanStatuses.CanceledByUser); } //User click cancel while info dialog was showed if (!bCancel) { byte[] zippedProject = ZipProject(_scan, project, bg); if (!_scan.IsCancelPressed && zippedProject != null) { if (configuration.Configurations.Count > 0) { RunScanResult runScanResult = null; if (!CommonData.IsProjectBound) { if (_uploadSettings.IsPublic) { _scan.IsPublic = SetScanPrivacy(); } runScanResult = RunScan(bg, client, configuration, zippedProject); } else { if (_scan.UploadSettings.IsPublic) { _scan.IsPublic = SetScanPrivacy(); } runScanResult = RunBoundedProjectScan(_scan, bg, client, zippedProject); } if (runScanResult == null || !runScanResult.IsSuccesfull) { bCancel = true; isIISStoped = true; isScanningEror = true; } // Continue if project uploaded succesfull and cancel button while process wasn't pressed if (runScanResult != null && runScanResult.IsSuccesfull) { _scan.RunScanResult = runScanResult; //perform scan work in separated thread to improve UI responsibility System.Threading.ThreadPool.QueueUserWorkItem(delegate(object stateInfo) { try { // Wait while scan operation complete while (true) { StatusScanResult statusScan = UpdateScanStatus(ref bCancel, backgroundMode, view, bg, client, ref isIISStoped); // if scan complete with sucess or failure or cancel button was pressed // operation complete bCancel = bCancel ? bCancel : _scan.WaitForCancel(); if (isIISStoped || bCancel || (statusScan != null && statusScan.RunStatus == CurrentStatusEnum.Finished) || (statusScan != null && statusScan.RunStatus == CurrentStatusEnum.Failed)) { break; } } waitEnd.Set(); } catch (Exception err) { Logger.Create().Error(err.ToString()); // show error waitEnd.Set(); isIISStoped = true; Logger.Create().Debug(err); } if (_scan.ScanView == null || _scan.ScanView.Visibility == false) { var scanStatusBar = new ScanStatusBar(false, "", 0, 0, true); CommonActionsInstance.getInstance().UpdateScanProgress(scanStatusBar); //ObserversManager.Instance.Publish(typeof (ScanStatusBar), scanStatusBar); } }); while (!waitEnd.WaitOne(0, false)) { Application.DoEvents(); Thread.Sleep(10); } } } #region [Scan completed. Open perspective] if (!bCancel && !isIISStoped) { ShowScanData(ref scanData, ref scanId, client); } else { #region [Stop scan in cancel pressed] if (_scan.RunScanResult != null && !isIISStoped) { bg.DoWorkFunc = delegate { if (!isIISStoped) { client.ServiceClient.CancelScan(_scan.LoginResult.SessionId, _scan.RunScanResult.ScanId); } }; bg.DoWork("Stop scan..."); } #endregion } #endregion client.Close(); } else { client.Close(); bCancel = true; } } else { } } else { } if (!backgroundMode && view != null) { view.CloseView(); } if (isIISStoped) { if (isScanningEror) { return(ProjectScanStatuses.Error); } else { return(ProjectScanStatuses.CanceledByUser); } } if (!bCancel) { return(ProjectScanStatuses.Success); } else { if (isScanningEror) { return(ProjectScanStatuses.Error); } else { return(ProjectScanStatuses.CanceledByUser); } } } return(ProjectScanStatuses.CanceledByUser); }
/// <summary> /// Execute 'Previous Result' command /// </summary> public static void DoPrevResult() { Logger.Create().Debug("DoPrevResult in"); // Get logged user credentials and project relation data LoginData login = Helpers.LoginHelper.Load(0); CxWSQueryVulnerabilityData[] perspective = null; login.IsOpenPerspective = Entities.Enum.SimpleDecision.Yes; LoginData.BindProject bindProject = login.BindedProjects.Find(delegate(LoginData.BindProject bp) { return(bp.BindedProjectId == CommonData.ProjectId && bp.ProjectName == CommonData.ProjectName && bp.RootPath == CommonData.ProjectRootPath); } ); if (bindProject != null && bindProject.ScanReports != null && bindProject.ScanReports.Count > 0) { ScanReportInfo tmp = bindProject.ScanReports.Find(delegate(ScanReportInfo sri) { return(sri.Id == CommonData.SelectedScanId); } ); if (tmp == null || tmp.Id == 0) { tmp = bindProject.ScanReports[0]; CommonData.SelectedScanId = tmp.Id; } perspective = GetScanResultsPath(tmp.Id); bindProject.SelectedScanId = tmp.Id; if (!string.IsNullOrEmpty(tmp.Path)) { StorageHelper.Delete(tmp.Path); } BackgroundWorkerHelper bgWork = new BackgroundWorkerHelper(delegate { tmp.Path = PerspectiveHelper.GetScanXML(CommonData.SelectedScanId); LoginHelper.Save(login); }); bgWork.DoWork(); Dictionary <string, long> list = new Dictionary <string, long>(); foreach (ScanReportInfo item in bindProject.ScanReports) { if (!list.ContainsKey(item.Name)) { list.Add(item.Name, item.Id); } } CommonActionsInstance.getInstance().ReportPersepectiveView.SetScanList(list, tmp.Id); if (perspective != null) { ShowStored(perspective, login, tmp.Id); } } }
public static LoginResult ExecuteLogin(LoginData login, out bool cancelPressed, bool relogin) { LoginResult loginResult = new LoginResult(); cancelPressed = !login.IsLogging; if (login != null && login.IsLogging && (!_isLogged || relogin)) { CxWebServiceClient client = null; BackgroundWorkerHelper bg = new BackgroundWorkerHelper(delegate { try { client = new CxWebServiceClient(login); } catch (Exception e) { Logger.Create().Error(e.ToString()); System.Windows.Forms.MessageBox.Show(e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK); return; } if (client == null) { System.Windows.Forms.MessageBox.Show("Cannot connect to server", "Error", System.Windows.Forms.MessageBoxButtons.OK); return; } // perform login try { serverBaseUrl = login.ServerBaseUri; bool loginSucceeded = DolLogin(login, client); if (loginSucceeded) { loginResult.IsSuccesfull = true; loginResult.AuthenticationData = login; } _loginResult = loginResult; } catch (WebException ex) { Logger.Create().Error(ex.Message, ex); loginResult.LoginResultType = LoginResultType.UnknownServerName; loginResult.LoginResultMessage = ex.Message; loginResult.IsSuccesfull = false; } catch (Exception ex) { Logger.Create().Error(ex.Message, ex); loginResult.LoginResultType = LoginResultType.UnknownError; loginResult.LoginResultMessage = ex.Message; } finally { if (client != null) { client.Close(); } } }, login.ReconnectInterval * 1000, login.ReconnectCount); cancelPressed = !bg.DoWork(WAIT_DIALOG_PROGRESS_TEXT); } return(loginResult); }