/// <summary> /// Map view data to upload object /// </summary> /// <param name="upload"></param> /// <param name="isUploading"></param> private void MapObjectData(ref BindProjectEntity upload, bool isUploading) { if (isUploading) { upload.SelectedProject = _view.SelectedProject; upload.isPublic = _view.SelectedProject.IsPublic; } else { upload.SelectedProject = null; } }
/// <summary> /// Perform upload project /// </summary> /// <param name="parentView">Parent view</param> /// <param name="upload">Upload data</param> public void BindProject(IView parentView, BindProjectEntity upload) { MapViewData(upload); if (!upload.IsUploading) { upload.IsUploading = true; try { bool isConfirmed = _view.ShowModalView(parentView) == System.Windows.Forms.DialogResult.OK; MapObjectData(ref upload, isConfirmed); upload.CommandResult = (isConfirmed) ? System.Windows.Forms.DialogResult.OK : System.Windows.Forms.DialogResult.Cancel; return; } finally { upload.IsUploading = false; } } upload.SelectedProject = null; upload.CommandResult = System.Windows.Forms.DialogResult.Cancel; }
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> /// Map upload object data to view /// </summary> /// <param name="upload"></param> private void MapViewData(BindProjectEntity upload) { _view.ProjectList = upload.CxProjectsDisplayData.projectList; }