private void tfsInfoBackgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { toolStripBusy.ForeColor = Color.Black; toolStripBusy.Text = "Idle"; if ((cboProject.Text != allHolder) && (cboRoles.Text == noRoleHolder)) { rtfMain.AppendText("\n\nATTENTION: You have selected to list the project names for only one project!"); rtfMain.AppendText("\nYou might want to either select all projects or a specific role other than None - \"Project Names Only\" ;-)"); } if (cancelled == false) { MessageBox.Show("Data retrieval from TFS completed successfully", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } UIControl UIController = new UIControl(this); UIController.enableProjectUIControls(); }
public void doConnectToTFS() { #region variable declarations UIControl UIControl1 = new UIControl(mainForm); UIControl1.disableProjectUIControls(); mainForm.cancelled = false; mainForm.myTeamRoles.Clear(); mainForm.myTeamProjects.Clear(); #endregion #region print opening connection string if (mainForm.rtfMain.InvokeRequired) { mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText("Opening connection...\n"); })); } #endregion try { //check for cancellation if (mainForm.connectionBackgroundWorker.CancellationPending == true) { mainForm.connectionBackgroundWorker.Dispose(); return; } #region form the URI Uri tfsUriNew = new Uri(mainForm.serverURI); mainForm.tfsConnect = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUriNew); #endregion #region establish the connection if (mainForm.chkTFS2010.Checked == true) { try { string serverURInocollection = string.Concat(mainForm.http, mainForm.serverName, mainForm.colon, mainForm.portNumber, mainForm.tfsDir); Uri tfs2010Urinocollection = new Uri(serverURInocollection); mainForm.tfs2010Server = TfsConfigurationServerFactory.GetConfigurationServer(tfs2010Urinocollection); //for TFS 2010 only CatalogNode tfsCatalog = mainForm.tfs2010Server.CatalogNode; // Query the children of the configuration server node for all of the team project collection nodes mainForm.tpcNodes = tfsCatalog.QueryChildren(new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); } catch { string error = "Cannot connect to specified server, check that it is actually running TFS version 2010!\n"; mainForm.doProcessException(error); } } IBuildServer buildServer = (IBuildServer)mainForm.tfsConnect.GetService(typeof(IBuildServer));; if (mainForm.rtfMain.InvokeRequired) { mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText(string.Format("\nServer {0} found.", mainForm.serverName)); })); } mainForm.tfsVersionShort = buildServer.BuildServerVersion.ToString(); #endregion #region put the TFS version into meaningful language //put the TFS version into more meaningful verbage //TODO this may need V5...bug on finding V5 is in progress if (mainForm.tfsVersionShort == "V5") { mainForm.tfsVersionReadable = "Microsoft Team Foundation Server 2013/2015"; } if (mainForm.tfsVersionShort == "V4") { mainForm.tfsVersionReadable = "Microsoft Team Foundation Server 2012/2013"; } if (mainForm.tfsVersionShort == "V3") { mainForm.tfsVersionReadable = "Microsoft Team Foundation Server 2010"; } if (mainForm.tfsVersionShort == "V2") { mainForm.tfsVersionReadable = "Microsoft Team Foundation Server 2008"; } if ((mainForm.tfsVersionShort != "V2") && (mainForm.tfsVersionShort != "V3") && (mainForm.tfsVersionShort != "V4") && (mainForm.tfsVersionShort != "V5")) { mainForm.tfsVersionReadable = "ERROR: Could not determine TFS version!"; } #endregion #region populate arrayLists with special values for all/none //add special entry for all project and all roles in the ArrayList which will later populate the ComboBoxes mainForm.myTeamProjects.Add(mainForm.allHolder); mainForm.myTeamRoles.Add(mainForm.allHolder); mainForm.myTeamRoles.Add(mainForm.noRoleHolder); #endregion #region project discovery if (mainForm.rtfMain.InvokeRequired) { mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText("\n\tWORKING: Discovering and adding TFS projects..."); })); } //get ICommonStructureService (later to be used to list all team projects) mainForm.iss = (ICommonStructureService)mainForm.tfsConnect.GetService(typeof(ICommonStructureService)); //get IGroupSecurityService (later to be used to retrieve identity information) mainForm.gss = (IGroupSecurityService2)mainForm.tfsConnect.GetService(typeof(IGroupSecurityService2)); mainForm.allTeamProjects = mainForm.iss.ListProjects(); if (mainForm.cboProject.InvokeRequired) { mainForm.cboProject.Invoke(new MethodInvoker(delegate { mainForm.cboProject.Items.Add(mainForm.allHolder); })); } //iterate through each project to populate the ArrayLists for projects and roles, avoiding duplicate roles foreach (ProjectInfo TFSProjectInfo in mainForm.allTeamProjects) { //mainForm.teamProjectURI = TFSProjectInfo.Uri; if (mainForm.connectionBackgroundWorker.CancellationPending == true) { return; } mainForm.myTeamProjects.Add(TFSProjectInfo.Name.ToString()); //no filtering on projects, assumed there are no duplicate projects } if (mainForm.rtfMain.InvokeRequired) { mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText("Done.\n"); })); } #endregion #region roles discovery if (mainForm.rtfMain.InvokeRequired) { mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText("\tWORKING: Discovering and adding TFS roles across all projects on the server."); })); } //iterate through each project to populate the ArrayLists for projects and roles, avoiding duplicate roles foreach (ProjectInfo TFSProjectInfo in mainForm.allTeamProjects) { if (mainForm.connectionBackgroundWorker.CancellationPending == true) { mainForm.connectionBackgroundWorker.Dispose(); return; } mainForm.teamProjectUriConnect = TFSProjectInfo.Uri; //for each Team project identify each security Group mainForm.allProjectGroups = mainForm.gss.ListApplicationGroups(mainForm.teamProjectUriConnect); //this guy is expensive...why? //filter out duplicate project roles foreach (Identity projectGroup in mainForm.allProjectGroups) { if (mainForm.myTeamRoles.Contains(projectGroup.DisplayName.ToString())) { continue; } else { mainForm.myTeamRoles.Add(projectGroup.DisplayName.ToString()); mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText(string.Format("\n\t\tFOUND: Role {0}", projectGroup.DisplayName.ToString())); })); } } } if (mainForm.rtfMain.InvokeRequired) { mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText("\n\tWORKING: Finished TFS roles discovery."); })); } #endregion #region sort projects and roles, then put them in the combo boxes //sort the projects and roles arrays - easier to read if they're alphabetical mainForm.myTeamProjects.Sort(); mainForm.myTeamRoles.Sort(); //populate the combo boxes with the values from the ArrayLists if (mainForm.allCollections == false) { if (mainForm.cboProject.InvokeRequired) { mainForm.cboProject.Invoke(new MethodInvoker(delegate { mainForm.cboProject.DataSource = mainForm.myTeamProjects; })); } } else { if (mainForm.cboProject.InvokeRequired) { mainForm.cboProject.Invoke(new MethodInvoker(delegate { mainForm.cboProject.Text = mainForm.allHolder; mainForm.cboProject.Items.Add(mainForm.allHolder); })); } } if (mainForm.cboRoles.InvokeRequired) { mainForm.cboRoles.Invoke(new MethodInvoker(delegate { mainForm.cboRoles.DataSource = mainForm.myTeamRoles; })); } //don't enable the project/role UI controls until we have a successful connection UIControl1.enableProjectUIControls(); mainForm.tfsConnected = true; #endregion } catch (Exception ex) { #region handle connection errors mainForm.doProcessException(ex.Message.ToString()); if (mainForm.rtfMain.InvokeRequired) { mainForm.rtfMain.Invoke(new MethodInvoker(delegate { mainForm.rtfMain.AppendText("\nPlease check the status of your TFS instance and try again.\n"); })); } #endregion } }