Esempio n. 1
0
        /// <summary>
        /// GetLIstOfUserNames Method Definition
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public Boolean GetListOfUserNames(string projectName)
        {
            dtView.DataSource = null;
            dtView.Rows.Clear();
            _glUsers.Clear();

            if (projectName == "ALL")
            {
                lstProjects.Items.Clear();
                lstProjects.Items.Add("All TFS Projects");
                lstProjects.Items.Add("");
                teamProjects = _versionControl.GetAllTeamProjects(false);
                foreach (TeamProject tp in teamProjects)
                {
                    lstProjects.Items.Add(tp.Name);
                    Identity[] appGroups = _securityService.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri);
                    foreach (Identity group in appGroups)
                    {
                        Identity[] groupMembers = _securityService.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);
                        if (groupMembers.Length == 0) break;
                        foreach (Identity member in groupMembers)
                        {
                            if (member.Members.Length == 0) break;
                            if (member.Members != null)
                            {
                                foreach (string memberSid in member.Members)
                                {
                                    Identity memberInfo = _securityService.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);
                                    if (memberInfo.Type != IdentityType.WindowsUser) continue;

                                    if (_glUsers.Contains(memberInfo.Sid))
                                        _userDetail = (UserDetails)_glUsers[memberInfo.Sid];
                                    else
                                        _userDetail = new UserDetails(memberInfo);

                                    //update the project and permission
                                    _userDetail.TeamProject = tp.Name;
                                    _userDetail.Permission = group.DisplayName;
                                    _userDetail.UpdateProjectAndPermission(tp.Name, group.DisplayName);
                                    if (_glUsers.ContainsKey(memberInfo.Sid))
                                        _glUsers.Remove(memberInfo.Sid);

                                    _glUsers.Add(memberInfo.Sid, _userDetail);

                                }
                            }
                        }
                    }

                }
            }
            else if (projectName == "")
            {

            }
            else
            {
                TeamProject teamproject = _versionControl.GetTeamProject(projectName);
                Identity[] appGroups = _securityService.ListApplicationGroups(teamproject.ArtifactUri.AbsoluteUri);
                List<Identity> usernames = new List<Identity>();

                foreach (Identity group in appGroups)
                {
                    Identity[] groupMembers = _securityService.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);

                    foreach (Identity member in groupMembers)
                    {
                        if (member.Members != null)
                        {

                            foreach (string memberSid in member.Members)
                            {
                                Identity memberInfo = _securityService.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);
                                if (memberInfo.Type != IdentityType.WindowsUser) continue;

                                if (usernames.Contains(memberInfo))
                                    _userDetail = (UserDetails)_glUsers[memberInfo.Sid];
                                else
                                    _userDetail = new UserDetails(memberInfo);

                                //update the project and permission
                                _userDetail.TeamProject = teamproject.Name;
                                _userDetail.Permission = group.DisplayName;
                                _userDetail.UpdateProjectAndPermission(teamproject.Name, group.DisplayName);
                                if (_glUsers.ContainsKey(memberInfo.Sid))
                                    _glUsers.Remove(memberInfo.Sid);

                                _glUsers.Add(memberInfo.Sid, _userDetail);

                            }
                        }
                    }
                }
            }

            int sn = 0;
            dtView.Rows.Add(_glUsers.Count + 1);
            foreach (UserDetails userIdentity in _glUsers.Values)
            {
                dtView.Rows[sn].Cells[0].Value = userIdentity.UserName;
                dtView.Rows[sn].Cells[1].Value = userIdentity.ADId;
                dtView.Rows[sn].Cells[2].Value = userIdentity.EmailAdd;
                dtView.Rows[sn].Cells[3].Value = userIdentity.Domain;
                string v = string.Empty;
                Hashtable ht = userIdentity.PaR;
                foreach (string str in userIdentity.PaR.Values)
                {
                    v = string.Format("{0}{1}", v, str);
                }
                dtView.Rows[sn].Cells[4].Value = v;
                dtView.Rows[sn].Cells[5].Value = userIdentity.Status;
                sn++;
            }
            return true;
        }
Esempio n. 2
0
        /// <summary>
        /// On Button Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_dp_Click(object sender, EventArgs e)
        {
            /*Code for picking from Server Picker TFS control
            DomainProjectPicker dp = new DomainProjectPicker(DomainProjectPickerMode.AllowMultiSelect);
            if (dp.ShowDialog() != DialogResult.Cancel)
            {

            }*/

            //bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
            //bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
            //bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
            //bgw.WorkerReportsProgress = true;
            //bgw.RunWorkerAsync();
            //pbrProgress.Visible = true;

            string serverChecked;
            if(rtnGIRMS27.Checked)
                serverChecked= "GIRMS27";
            else
                serverChecked= "GIRMSC9";

            _server = new TeamFoundationServer("http://"+serverChecked+":8080");

            _server.EnsureAuthenticated();
            _versionControl = (VersionControlServer)_server.GetService(typeof(VersionControlServer));
            _securityService = (IGroupSecurityService)_server.GetService(typeof(IGroupSecurityService));

            teamProjects = _versionControl.GetAllTeamProjects(false);

            lstProjects.Items.Clear();
            lstProjects.Items.Add("All TFS Projects");
            lstProjects.Items.Add("");
            dtView.DataSource = null;
            dtView.Rows.Clear();
            _glUsers.Clear();

            foreach (TeamProject tp in teamProjects)
            {
                lstProjects.Items.Add(tp.Name);
                Identity[] appGroups = _securityService.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri);
                foreach (Identity group in appGroups)
                {
                    Identity[] groupMembers = _securityService.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);
                    if (groupMembers.Length == 0) break;
                    foreach (Identity member in groupMembers)
                    {
                        if (member.Members.Length == 0) break;
                        if (member.Members != null)
                        {
                            foreach (string memberSid in member.Members)
                            {
                                Identity memberInfo = _securityService.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);
                                if (memberInfo.Type != IdentityType.WindowsUser) continue;

                                if (_glUsers.Contains(memberInfo.Sid))
                                    _userDetail = (UserDetails)_glUsers[memberInfo.Sid];
                                else
                                    _userDetail = new UserDetails(memberInfo);

                                //update the project and permission
                                _userDetail.TeamProject = tp.Name;
                                _userDetail.Permission = group.DisplayName;
                                _userDetail.UpdateProjectAndPermission(tp.Name, group.DisplayName);
                                if (_glUsers.ContainsKey(memberInfo.Sid))
                                    _glUsers.Remove(memberInfo.Sid);

                                _glUsers.Add(memberInfo.Sid, _userDetail);

                            }
                        }
                    }
                }

            }
            int sn = 0;
            dtView.Rows.Add(_glUsers.Count + 1);
            foreach (UserDetails userIdentity in _glUsers.Values)
            {
                dtView.Rows[sn].Cells[0].Value = userIdentity.UserName;
                dtView.Rows[sn].Cells[1].Value = userIdentity.ADId;
                dtView.Rows[sn].Cells[2].Value = userIdentity.EmailAdd;
                dtView.Rows[sn].Cells[3].Value = userIdentity.Domain;
                string v = string.Empty;
                Hashtable ht = userIdentity.PaR;
                foreach (string str in userIdentity.PaR.Values)
                {
                    v = string.Format("{0}{1}", v, str);
                }
                dtView.Rows[sn].Cells[4].Value = v;
                dtView.Rows[sn].Cells[5].Value = userIdentity.Status;
                sn++;
            }

            lblConnectedServer.Visible = true;
            lblServer.Text = serverChecked;
            frmTFSView.ActiveForm.Text = "Team Foundation Server - Projects & Users" + " : Connected To (" + serverChecked + ")";
            //pbrProgress.Visible = true;
        }