Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        void btnConnect_Click(object sender, System.EventArgs e)
        {
            tabMain.SelectTab(0);
            if (connectionBackgroundWorker.IsBusy == true)
            {
                txtHost.Text       = tfsServerValue;
                txtPort.Text       = tfsPortValue;
                chkTFS2010.Checked = tfs2010Value;
                txtCollection.Text = tfsCollectionValue;
                MessageBox.Show("Please cancel from the File menu or wait for the current process to finish.", "Working...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else if (tfsInfoBackgroundWorker.IsBusy == true)
            {
                MessageBox.Show("Please cancel from the File menu or wait for the current process to finish.", "Working...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                tfsServerValue          = txtHost.Text.ToString();
                tfsPortValue            = txtPort.Text.ToString();
                tfs2010Value            = chkTFS2010.Checked;
                tfsCollectionValue      = txtCollection.Text.ToString();
                toolStripBusy.ForeColor = Color.Red;
                toolStripBusy.Text      = "Busy";
            }

            //clear out projects and roles combo boxes
            tfsConnected          = false;
            cboRoles.DataSource   = null;
            cboProject.DataSource = null;

            toolStripServer.Text     = "Not Connected";
            toolStripPort.Text       = "Not Connected";
            toolStripCollection.Text = "Not Connected";
            toolStripVersion.Text    = "Not Connected";

            if (connectionBackgroundWorker.IsBusy == false)
            {
                rtfMain.Clear();
            }

            //set form level variables from appropriate UI elements
            serverName    = txtHost.Text;
            portNumber    = txtPort.Text;
            tfsCollection = txtCollection.Text;

            #region URI customization

            if (chkHttps.Checked == true)
            {
                http = "https://";
            }
            if (chkHttps.Checked == false)
            {
                http = "http://";
            }

            if (txtPath.Text == "tfs")
            {
                tfsDir = "/tfs/";
            }
            if ((txtPath.Text != "tfs") && (txtPath.Text != ""))
            {
                tfsDir = "/" + txtPath.Text + "/";
            }

            #endregion

            //handle collection name in the URI, only available in TFS 2010
            if (chkTFS2010.Checked == true)
            {
                if (tfsCollection.ToLower() == "all-collections")
                {
                    serverURI      = string.Concat(http, serverName, colon, portNumber, tfsDir);
                    allCollections = true;
                }
                else
                {
                    serverURI = string.Concat(http, serverName, colon, portNumber, tfsDir, tfsCollection);
                }
            }
            else
            {
                serverURI = string.Concat(http, serverName, colon, portNumber);
            }

            //hide spaces in the server URI by replacing them with underscores. For display purposes only!
            serverURInospace = serverURI;
            if (serverURI.Contains(" "))
            {
                serverURInospace = serverURI.Replace(" ", "_");
            }

            try
            {
                //revert to error text if server name has no value
                if (serverName == "")
                {
                    throw new Exception();
                }

                //revert to error text if server port has no value
                if (portNumber == "")
                {
                    throw new Exception();
                }

                if (tfsDir == null)
                {
                    throw new Exception();
                }

                //chkTFS2010 shouldn't be checked if tfsCollection has a value
                if ((chkTFS2010.Checked == true) && (tfsCollection == ""))
                {
                    throw new Exception();
                }

                //chkTFS2010 should be checked if tfsCollection has a value
                if ((chkTFS2010.Checked == false) && (tfsCollection != ""))
                {
                    throw new Exception();
                }

                //Go do all the connection work on another thread
                if (connectionBackgroundWorker.IsBusy == false)
                {
                    connectionBackgroundWorker.RunWorkerAsync();
                }
                else
                {
                    MessageBox.Show("Please cancel from the File menu or wait for the current process to finish.", "Working...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                //remove persistent connection info
                toolStripServer.Text     = "Not Connected";
                toolStripPort.Text       = "Not Connected";
                toolStripCollection.Text = "Not Connected";
                toolStripVersion.Text    = "Not Connected";

                //ensure that project level UI controls are disabled
                UIControl UIControl1 = new UIControl(this);
                UIControl1.disableProjectUIControls();


                //neither serverName nor portNumber nor path can be null
                if ((serverName == "") || (portNumber == "") || (tfsDir == null))
                {
                    toolStripBusy.ForeColor = Color.Black;
                    toolStripBusy.Text      = "Idle";
                    string error = "Server Name, Port Number and TFS Path can't be null!\n";
                    doProcessException(error);
                    rtfMain.AppendText("\nPlease check your server name, port number and TFS Path values and try again.\n");
                }
                //if chkTFS2010 is checked, tfsCollection cannot be null
                else if ((chkTFS2010.Checked == true) && (tfsCollection == ""))
                {
                    toolStripBusy.ForeColor = Color.Black;
                    toolStripBusy.Text      = "Idle";
                    string error = "For TFS 2010 a collection name MUST be specified!\n";
                    doProcessException(error);
                    rtfMain.AppendText("\nPlease check your collection name and version input values and try again.\n");
                }
                //if a collection name is specified chkTFS2010 must be checked
                else if ((chkTFS2010.Checked == false) && (tfsCollection.Length > 0))
                {
                    toolStripBusy.ForeColor = Color.Black;
                    toolStripBusy.Text      = "Idle";
                    string error = "TFS 2010 collection specified for non-2010 version!\n";
                    doProcessException(error);
                    rtfMain.AppendText("\nPlease check your collection name and/or version input values and try again.\n");
                }
                //catch all other errors - likely connection errors from bad input
                else
                {
                    toolStripBusy.ForeColor = Color.Black;
                    toolStripBusy.Text      = "Idle";
                    doProcessException(ex.Message.ToString());
                    rtfMain.AppendText("\nPlease check your input values and try again.\n");
                }
            }
            //reset allCollections, determining its value on each click of Connect
            allCollections = false;
        }
Ejemplo n.º 3
0
        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
            }
        }