public List <TfsUser> Users() { List <TfsUser> lst = new List <TfsUser>(); TeamProject tp = GetTeamProject(); Identity[] appGroups = secSrv.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri); foreach (Identity group in appGroups) { Identity[] groupMembers = secSrv.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Direct); foreach (Identity member in groupMembers) { if (member.Members != null) { foreach (string memberSid in member.Members) { lst.Add(GetTfsUser(memberSid)); } } } } return(lst); }
private static IEnumerable <Identity> GetUsers(TfsProject SourceProject) { HashSet <Identity> users = new HashSet <Identity>(); Queue <Identity> queuedItems = new Queue <Identity>(); IGroupSecurityService gss = SourceProject.collection.GetService <IGroupSecurityService>(); Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded); Identity[] sourceUserIds = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.Direct); foreach (var item in sourceUserIds) { if (item != null) { queuedItems.Enqueue(item); } } while (queuedItems.Any()) { var firstSid = queuedItems.Dequeue(); if (firstSid == null) { continue; } try { users.Add(firstSid); if (firstSid.Members.Length == 0) { continue; } Identity[] members = gss.ReadIdentities(SearchFactor.Sid, firstSid.Members, QueryMembership.Direct); foreach (var item in members) { if (item == null) { continue; } if (users.Add(item)) { if (item.Type == IdentityType.WindowsUser) { continue; } queuedItems.Enqueue(item); } } } catch (Exception ex) { Debug.WriteLine(ex); } } return(users); }
/// <summary> /// Retrieves all TFS users and populates the Users property. /// </summary> private void PopulateUsers() { Users = new List <string>(); // These must use QueryMembership.Expanded otherwise additional information doesn't get returned IGroupSecurityService service = TfsCollection.GetService <IGroupSecurityService>(); Identity usersInCollection = service.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded); Identity[] members = service.ReadIdentities(SearchFactor.Sid, usersInCollection.Members, QueryMembership.Expanded); for (int i = 0; i < members.Length; i++) { // Basic filtering if (!members[i].SecurityGroup) //&& !usernames.Contains(username)) { string name = members[i].DisplayName; if (string.IsNullOrEmpty(name)) { name = members[i].AccountName; } _users.Add(name); } } _users.Sort(); }
public void GetUserName(TfsTeamProjectCollection tfs) { BindingList <KeyValuePair <string, string> > userdata = new BindingList <KeyValuePair <string, string> >(); IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService)); Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded); Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None); foreach (Identity user in UserId) { if (user == null) { continue; } else if (!user.SecurityGroup) { userdata.Add(new KeyValuePair <string, string>("q1", user.Domain + @"\" + user.AccountName)); } } cmbUser.DataSource = null; cmbUser.Items.Clear(); cmbUser.DataSource = new BindingSource(userdata, null); cmbUser.DisplayMember = "Value"; cmbUser.ValueMember = "Key"; }
public IEnumerable <Identity> GetAllUsersInTFSBasedOnIdentity() { Collection.EnsureAuthenticated(); IGroupSecurityService gss = Collection.GetService <IGroupSecurityService>(); Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded); return(gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None)); }
public async Task <Identity[]> GetAllUsersInTFSBasedOnIdentityAsync() { Collection.EnsureAuthenticated(); IGroupSecurityService gss = Collection.GetService <IGroupSecurityService>(); Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded); var readUsersTask = Task.Factory.StartNew(() => gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None).OrderBy(u => u.DisplayName).Select(u => u).ToArray()); return(await readUsersTask); }
/// <summary> /// Retreive User List of the Project /// </summary> /// <returns>List<string> of users</string></returns> public static List <string> RetreiveUserList() { List <string> userList = new List <string>(); dicoUser = new Dictionary <string, string>(); dicoUserMail = new Dictionary <string, string>(); //Call to Work Item Store to have access tfscoll and Get Services IGroupSecurityService GetWorkItemStore(); IGroupSecurityService groupsecurityservice = (IGroupSecurityService)tfsColl.GetService <IGroupSecurityService>(); if (vcs == null) { vcs = (VersionControlServer)tfsColl.GetService <VersionControlServer>(); } TeamProject teamProject = vcs.GetTeamProject(tfsExt.ActiveProjectContext.ProjectName); Identity[] appGroups = groupsecurityservice.ListApplicationGroups(teamProject.ArtifactUri.AbsoluteUri); //Identity idSid = groupsecurityservice.ReadIdentity() foreach (Identity group in appGroups) { Identity[] groupMembers = groupsecurityservice.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 = groupsecurityservice.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None); if (userList.Contains(memberInfo.DisplayName)) { continue; } userList.Add(memberInfo.DisplayName); dicoUser.Add(memberInfo.DisplayName, memberInfo.AccountName); dicoUserMail.Add(memberInfo.DisplayName, memberInfo.MailAddress); } } } } userList.Sort(); return(userList); }
private void SyncToGSS() { m_dispNameToAccName.Clear(); Identity identity = m_gss.ReadIdentity(SearchFactor.EveryoneApplicationGroup, "Team Foundation Valid Users", QueryMembership.Expanded); Identity[] identities = m_gss.ReadIdentities(SearchFactor.Sid, identity.Members, QueryMembership.None); foreach (Identity id in identities) { if (id.Type == IdentityType.WindowsUser && !m_dispNameToAccName.ContainsKey(id.DisplayName)) { m_dispNameToAccName.Add(id.DisplayName, id.AccountName); } } m_lastSyncTime = DateTime.Now; }
static void Main(string[] args) { TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://server:8080/tfs/DefaultCollection")); tfs.EnsureAuthenticated(); IGroupSecurityService gss = tfs.GetService <IGroupSecurityService>(); Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded); Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.Direct); foreach (Identity user in UserId) { if (user != null) { Console.WriteLine(user.AccountName); Console.WriteLine(user.Domain); } } Console.ReadKey(); }
private Identity[] GetMemberList() { var list = new List <Identity>(); Identity[] appGroups = gss.ListApplicationGroups(project.Uri.ToString()); foreach (Identity group in appGroups) { Identity[] groupMembers = gss.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded); foreach (Identity member in groupMembers) { Console.WriteLine(member.DisplayName); if (member.Members != null) { foreach (string memberSid in member.Members) { Identity memberInfo = gss.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None); list.Add(memberInfo); } } } } return(list.Distinct().ToArray()); }
/*BinarySearch---------------- * public static int BinarySearch(int start, int end) * { * * int mid = (start + end) / 2; * Changeset cs = null; * try * { * while (true) * { * if (version.GetChangeset(mid) != null) * { * cs = version.GetChangeset(mid); * break; * } * else * { * mid++; * } * } * if (cs.CreationDate.CompareTo(DateStart) < 0) * { * * BinarySearch(mid, end); * * } * if (cs.CreationDate.CompareTo(DateEnd) > 0) * { * * BinarySearch(start, mid); * } * * * return mid; * * * * * } * * catch (ResourceAccessException) * { * return BinarySearch(start + 1, end); * } * * * } */ static void Main(string[] args) { Console.WriteLine("123!"); //查询时间 Boolean startDateBoo = true; while (startDateBoo) { try { //DateTime.TryParse(string.Format("{yyyy-MM-DD}:00", starttime),out dt); // /* //* 暂时注释,输入时间 datestart and dateend,try timeformate catch System.Console.Write("Input the start time (yyyy-mm-dd): "); startdate = Console.ReadLine(); string starttime = startdate + " 00:00:00"; DateStart = DateTime.ParseExact(starttime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); startDateBoo = false; } catch (FormatException) { Console.WriteLine("Unable to convert to date"); startDateBoo = true; } } Boolean endDateBoo = true; while (endDateBoo) { System.Console.Write("Input the end time (yyyy-mm-dd): "); enddate = Console.ReadLine(); string endtime = enddate + " 23:59:59"; try { DateEnd = DateTime.ParseExact(endtime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); endDateBoo = false; } catch (FormatException) { Console.WriteLine("Unable to convert to date"); endDateBoo = true; } } //创建文件 //StreamWriter sw = File.AppendText(System.Environment.CurrentDirectory + "\\AnalysisResult.csv"); FileStream fs = new FileStream(Environment.CurrentDirectory + "\\" + startdate + "---" + enddate + "_Result.csv", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); fs.SetLength(0); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("changesetID,owner,group,createDate,branch,linkID,linktype,comment"); //服务器连接,相关对象的获取 TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://tfs.slb.com/tfs/Real-Time_Collection/")); //版本控制 version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer; //--------------------------team group------------------------------------------- TeamProject[] tepro = version.GetAllTeamProjects(true); TeamProject mypro = tepro[0]; string rootFolder = mypro.ArtifactUri.AbsoluteUri; IGroupSecurityService gss = (IGroupSecurityService)tpc.GetService(typeof(IGroupSecurityService)); Identity[] appGroups = gss.ListApplicationGroups(rootFolder); ArrayList RtGroup = new ArrayList(); for (int k = 0; k < appGroups.Length; k++) { Identity group = appGroups[k]; //Console.WriteLine(k +" " +group.DisplayName + "**************************"); if ("Real time".Equals(group.DisplayName)) { Identity[] groupMembers = gss.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded); foreach (Identity member in groupMembers) { if (member.Members != null) { //Console.WriteLine(member.Members.Length); //Thread.Sleep(3000); foreach (string memberSid in member.Members) { Identity memberInfo = gss.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.Expanded); //Console.WriteLine(memberInfo.DisplayName); RtGroup.Add(memberInfo.DisplayName); } } } } } //------------------------------------------------------------------ VersionSpec fromDateVersion = new DateVersionSpec(DateStart); VersionSpec toDateVersion = new DateVersionSpec(DateEnd); // using versionControl API you can query histroy for changes set IEnumerable changesets = version.QueryHistory(string.Concat("$/", mypro.Name), VersionSpec.Latest, 0, RecursionType.Full, null, fromDateVersion, toDateVersion, int.MaxValue, true, true); System.Console.WriteLine("-----------"); foreach (Changeset changeset in changesets) { Changeset cs = changeset; System.Console.WriteLine(cs.ChangesetId + " *** " + cs.CommitterDisplayName); Change[] thchan = cs.Changes; string branch = thchan[0].Item.ServerItem; String[] braPath = branch.Split('/'); if (braPath.Length > 4) { branch = ""; for (int k = 1; k < 4; k++) { branch = branch + braPath[k] + "/"; } if ("Release".Equals(braPath[3])) { branch = branch + braPath[4]; } } System.Console.WriteLine(branch); //associatedWork----------------------------------- AssociatedWorkItemInfo[] work = cs.AssociatedWorkItems; string linkid = ""; string linktype = ""; if (work.Length == 1) { linkid = (work[0].Id).ToString(); linktype = work[0].WorkItemType; } else { for (int k = 0; k < work.Length; k++) { if (!("Task".Equals(work[k].WorkItemType))) { linkid = linkid + "[" + (k + 1) + "] " + (work[k].Id).ToString() + " "; linktype = linktype + "[" + (k + 1) + "] " + work[k].WorkItemType + " "; } if (k == work.Length - 1 && "".Equals(linkid)) { linkid = (work[k].Id).ToString(); linktype = work[k].WorkItemType; } } } //teamInfo----------------------------------- string teamName = "othres"; if (RtGroup.Contains(cs.CommitterDisplayName)) { teamName = "Real time"; } //----------------------------------- sw.WriteLine("" + cs.ChangesetId + ',' + cs.CommitterDisplayName + ',' + teamName + ',' + cs.CreationDate + ',' + branch + ',' + linkid + ',' + linktype + ',' + Regex.Replace(cs.Comment, @"[\n\r]", "")); //foreach (Change change in changeset.Changes) //{ //string fileName = change.Item.ServerItem; //} } /*原本查询方式 * // changeset 相关信息的获取-------------------------------------- * int latestId = version.GetLatestChangesetId(); * Changeset cs; * for (int i = latestId; i>0; i--) * { * try * { * cs = version.GetChangeset(i); * if (cs == null) * { * System.Console.WriteLine("No result"); * continue; * } * if ((DateStart.CompareTo(cs.CreationDate)<=0) && ((DateEnd.CompareTo(cs.CreationDate)>=0))) * { * System.Console.WriteLine("changesetid:" + i + "!!"); * //branch * Change[] thchan = cs.Changes; * string branch = thchan[0].Item.ServerItem; * String[] braPath = branch.Split('/'); * if (braPath.Length > 4) * { * branch =""; * for (int k = 1; k < 4; k++) * { * branch = branch + braPath[k] + "/"; * } * if ("Release".Equals(braPath[3])) * { * branch = branch + braPath[4]; * } * } * System.Console.WriteLine(branch); * * //associatedWork----------------------------------- * AssociatedWorkItemInfo[] work = cs.AssociatedWorkItems; * string linkid = ""; * string linktype = ""; * if (work.Length == 1) * { * linkid = (work[0].Id).ToString(); * linktype = work[0].WorkItemType; * } * else * { * for (int k = 0; k < work.Length; k++) * { * if (!("Task" .Equals(work[k].WorkItemType))) * { * linkid = linkid + "[" + (k + 1) + "] " + (work[k].Id).ToString(); * linktype = linktype + "[" + (k + 1) + "] " + work[k].WorkItemType; * } * if (k == work.Length - 1 && "".Equals(linkid)) * { * linkid = (work[k].Id).ToString(); * linktype = work[k].WorkItemType; * } * * } * } * * //teamInfo----------------------------------- * string teamName = "othres"; * if (RtGroup.Contains(cs.CommitterDisplayName)) * { * teamName = "Real time"; * } * //----------------------------------- * * sw.WriteLine("" + i + ',' + cs.CommitterDisplayName + ',' + teamName + ',' + cs.CreationDate + ',' + branch + ','+ linkid + ',' + linktype + ',' + Regex.Replace(cs.Comment, @"[\n\r]", "")); * * } * if ((DateStart.CompareTo(cs.CreationDate) > 0)) * { * break; * } * } * catch (ResourceAccessException) * { * continue; * } * } */ sw.Close(); fs.Close(); System.Console.WriteLine("******end*****"); Thread.Sleep(5000); }
private void GetTFSUsersFromServer() { try { gss = (IGroupSecurityService)server.GetService(typeof(IGroupSecurityService)); SIDS = gss.ReadIdentity(SearchFactor.AccountName, _settings.TeamFoundationServerUserGroup, QueryMembership.Expanded); TFSUsers = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.InnerException.ToString(), e.Message); } }
static void Main(string[] args) { Console.WriteLine("123!"); //查询时间 Boolean startDateBoo = true; while (startDateBoo) { try { //DateTime.TryParse(string.Format("{yyyy-MM-DD}:00", starttime),out dt); // /* //* 暂时注释,输入时间 datestart and dateend,try timeformate catch System.Console.Write("Input the start time (yyyy-mm-dd): "); startdate = Console.ReadLine(); string starttime = startdate + " 00:00:00"; DateStart = DateTime.ParseExact(starttime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); startDateBoo = false; } catch (FormatException) { Console.WriteLine("Unable to convert to date"); startDateBoo = true; } } Boolean endDateBoo = true; while (endDateBoo) { System.Console.Write("Input the end time (yyyy-mm-dd): "); enddate = Console.ReadLine(); string endtime = enddate + " 23:59:59"; try { DateEnd = DateTime.ParseExact(endtime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); endDateBoo = false; } catch (FormatException) { Console.WriteLine("Unable to convert to date"); endDateBoo = true; } } //创建文件 //StreamWriter sw = File.AppendText(System.Environment.CurrentDirectory + "\\AnalysisResult.csv"); FileStream fs = new FileStream(Environment.CurrentDirectory + "\\" + startdate + "---" + enddate + "_Result.csv", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); fs.SetLength(0); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("ChangesetID,Owner,Group,CreateDate,Branch,LinkID,LinkType,Comment"); //服务器连接,相关对象的获取 TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://tfs.slb.com/tfs/Real-Time_Collection/")); //版本控制 version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer; //--------------------------team group------------------------------------------- System.Console.WriteLine("Getting Team Information......"); TeamProject[] tepro = version.GetAllTeamProjects(true); TeamProject mypro = tepro[0]; string rootFolder = mypro.ArtifactUri.AbsoluteUri; IGroupSecurityService gss = (IGroupSecurityService)tpc.GetService(typeof(IGroupSecurityService)); Identity[] appGroups = gss.ListApplicationGroups(rootFolder); Dictionary <string, ArrayList> groupMap = new Dictionary <string, ArrayList>(); ArrayList RTgroup = new ArrayList(); RTgroup.Add("Yizhou WANG"); groupMap.Add("Real time", RTgroup); groupMap.Add("Data delivery", new ArrayList()); groupMap.Add("Photon", new ArrayList()); groupMap.Add("ProXimity", new ArrayList()); groupMap.Add("Visualization", new ArrayList()); groupMap.Add("QA", new ArrayList()); for (int k = 0; k < appGroups.Length; k++) { Identity group = appGroups[k]; if (groupMap.ContainsKey(group.DisplayName)) { Identity[] groupMembers = gss.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 = gss.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.Expanded); groupMap[group.DisplayName].Add(memberInfo.DisplayName); } } } } } //------------------------------------------------------------------ VersionSpec fromDateVersion = new DateVersionSpec(DateStart); VersionSpec toDateVersion = new DateVersionSpec(DateEnd); // using versionControl API you can query histroy for changes set IEnumerable changesets = version.QueryHistory(string.Concat("$/", mypro.Name), VersionSpec.Latest, 0, RecursionType.Full, null, fromDateVersion, toDateVersion, int.MaxValue, true, true); //查询 changeset 相关信息的获取-------------------------------------- Dictionary <string, ArrayList> countUnlinked = new Dictionary <string, ArrayList>(); Dictionary <string, ArrayList> countTasklinked = new Dictionary <string, ArrayList>(); System.Console.WriteLine("Query Changesets by Date......"); string csTime = ""; foreach (Changeset changeset in changesets) { Changeset cs = changeset; if (csTime.Equals(cs.CreationDate.ToShortDateString()) == false) { if ("".Equals(csTime) == false) { System.Console.WriteLine(" done!"); } csTime = cs.CreationDate.ToShortDateString().ToString(); System.Console.Write(csTime); } //System.Console.WriteLine(cs.ChangesetId + " *** " + cs.CommitterDisplayName); Change[] thchan = cs.Changes; string branch = thchan[0].Item.ServerItem; String[] braPath = branch.Split('/'); if (braPath.Length > 4) { branch = ""; for (int k = 1; k < 4; k++) { branch = branch + braPath[k] + "/"; } if ("Release".Equals(braPath[3])) { branch = branch + braPath[4]; } } //System.Console.WriteLine(branch); //teamInfo----------------------------------- string teamName = "others"; foreach (KeyValuePair <string, ArrayList> groupInfo in groupMap) { if (groupInfo.Value.Contains(cs.CommitterDisplayName)) { teamName = groupInfo.Key; } } //----------------------------------- //associatedWork----------------------------------- AssociatedWorkItemInfo[] work = cs.AssociatedWorkItems; string linkid = ""; string linktype = ""; if (work == null || work.Length < 1) { if (countUnlinked.ContainsKey(cs.CommitterDisplayName)) { countUnlinked[cs.CommitterDisplayName].Add(cs.ChangesetId); } else { countUnlinked.Add(cs.CommitterDisplayName, new ArrayList()); countUnlinked[cs.CommitterDisplayName].Add(cs.ChangesetId); } sw.WriteLine("" + cs.ChangesetId + ',' + cs.CommitterDisplayName + ',' + teamName + ',' + cs.CreationDate + ',' + branch + ',' + linkid + ',' + linktype + ',' + Regex.Replace(cs.Comment, @"[\n\r]", "")); } else if (work.Length == 1) { if ("Task".Equals(work[0].WorkItemType)) { if (countTasklinked.ContainsKey(cs.CommitterDisplayName)) { countTasklinked[cs.CommitterDisplayName].Add(cs.ChangesetId); } else { countTasklinked.Add(cs.CommitterDisplayName, new ArrayList()); countTasklinked[cs.CommitterDisplayName].Add(cs.ChangesetId); } } linkid = (work[0].Id).ToString(); linktype = work[0].WorkItemType; sw.WriteLine("" + cs.ChangesetId + ',' + cs.CommitterDisplayName + ',' + teamName + ',' + cs.CreationDate + ',' + branch + ',' + linkid + ',' + linktype + ',' + Regex.Replace(cs.Comment, @"[\n\r]", "")); } else { for (int k = 0; k < work.Length; k++) { if (!("Task".Equals(work[k].WorkItemType))) { linkid = (work[k].Id).ToString(); linktype = work[k].WorkItemType; sw.WriteLine("" + cs.ChangesetId + ',' + cs.CommitterDisplayName + ',' + teamName + ',' + cs.CreationDate + ',' + branch + ',' + linkid + ',' + linktype + ',' + Regex.Replace(cs.Comment, @"[\n\r]", "")); } if (k == work.Length - 1 && "".Equals(linkid)) { if (countTasklinked.ContainsKey(cs.CommitterDisplayName)) { countTasklinked[cs.CommitterDisplayName].Add(cs.ChangesetId); } else { countTasklinked.Add(cs.CommitterDisplayName, new ArrayList()); countTasklinked[cs.CommitterDisplayName].Add(cs.ChangesetId); } linkid = (work[k].Id).ToString(); linktype = work[k].WorkItemType; sw.WriteLine("" + cs.ChangesetId + ',' + cs.CommitterDisplayName + ',' + teamName + ',' + cs.CreationDate + ',' + branch + ',' + linkid + ',' + linktype + ',' + Regex.Replace(cs.Comment, @"[\n\r]", "")); } } } //sw.WriteLine("" + cs.ChangesetId + ',' + cs.CommitterDisplayName + ',' + teamName + ',' + cs.CreationDate + ',' + branch + ',' + linkid + ',' + linktype + ',' + Regex.Replace(cs.Comment, @"[\n\r]", "")); } sw.Close(); fs.Close(); System.Console.WriteLine(" done!"); System.Console.WriteLine("**********end**********"); // 统计信息 FileStream cfs = new FileStream(Environment.CurrentDirectory + "\\" + startdate + "---" + enddate + "_Count.csv", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); cfs.SetLength(0); StreamWriter csw = new StreamWriter(cfs); csw.WriteLine("Owner,Group,Unlinked,Task Linked"); Dictionary <string, ArrayList> .KeyCollection keyUnlinked = countUnlinked.Keys; Dictionary <string, ArrayList> .KeyCollection keyTasklinked = countTasklinked.Keys; IEnumerable <string> union = keyUnlinked.Concat(keyTasklinked); HashSet <string> unionSet = new HashSet <string>(union); foreach (string name in unionSet) { int unLinked = 0; int taskLinked = 0; if (countUnlinked.ContainsKey(name)) { unLinked = countUnlinked[name].Count; } if (countTasklinked.ContainsKey(name)) { taskLinked = countTasklinked[name].Count; } string teamName = "others"; foreach (KeyValuePair <string, ArrayList> groupInfo in groupMap) { if (groupInfo.Value.Contains(name)) { teamName = groupInfo.Key; } } csw.WriteLine("" + name + ',' + teamName + ',' + unLinked + ',' + taskLinked); } csw.Close(); cfs.Close(); System.Console.WriteLine("**********Count Over**********"); Thread.Sleep(5000); }
/// <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; }
public IEnumerable <Identity> GetMembers() { var groupSid = groupSecurityService.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded); return(groupSecurityService.ReadIdentities(SearchFactor.Sid, groupSid.Members, QueryMembership.None).Where(a => a.Type == IdentityType.WindowsUser || a.Type == IdentityType.WindowsGroup)); }