/// <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); } } }
/// <summary> /// Perform background job and show view while process executes /// </summary> /// <param name="message">View title message</param> /// <returns>If false - cancel buton in supported view was pressed</returns> public bool DoWork(string message) { if (_doWorkFunc == null) { return(false); } // Show perform operation dialog bool canceling = false; IWaitView waitView = new WaitFrm(message, delegate(object sender, EventArgs e) { canceling = true; }); int repeatNum = 1; string errorMessage = null; bool success = false; do { try { if (Invoke(message, waitView) || canceling) { success = true; break; } } catch (Exception ex) { Logger.Create().Error(ex.ToString()); LoginHelper.DoLogout(); errorMessage = ex.Message; message = string.Format("Reconnection attempt #{0}...", repeatNum.ToString()); DateTime waitTo = DateTime.Now.AddMilliseconds(_repeatIntervalOnException); while (!(canceling || DateTime.Now > waitTo)) { Application.DoEvents(); Thread.Sleep(10); } if (canceling) { break; } } }while (repeatNum++ <= _repeatCountOnException); if (success || canceling) { if (!string.IsNullOrEmpty(message)) { waitView.CloseView(); } return(!canceling ? success : false); } bool executionResult = false; while (true) { try { ErrorFrm frmError = new ErrorFrm(errorMessage, delegate(object o, EventArgs e) { executionResult = Invoke("Reconnection...", waitView); }, _doReloginFunc); DialogResult res = frmError.ShowDialog(); if (res == DialogResult.Cancel) { break; } if (res != DialogResult.OK) { if (_doReloginFunc != null) { IsReloginInvoked = true; _doReloginFunc.BeginInvoke(null, null, null, null); } break; } if (executionResult) { break; } } catch (Exception ex) { Logger.Create().Error(ex.ToString()); } } if (!string.IsNullOrEmpty(message)) { waitView.CloseView(); } return(executionResult); }
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); } } }