예제 #1
0
        /// <summary>
        /// NOTE: call for TFS 2010 only.
        /// Adds a user to a TFS security group
        /// </summary>
        /// <param name="teamProjName">The name of the team project</param>
        /// <param name="searchableGroupName">The name of the group in [TeamProject]\GroupName format</param>
        /// <param name="userName">The name of the user to add</param>
        /// <returns>True, if successful</returns>
        private bool AddMemberToGroup_TFS10(string teamProjName, string searchableGroupName, string userName)
        {
            try
            {
                Identity userIdentity =
                    groupSecuritySvc.ReadIdentityFromSource(SearchFactor.AccountName, userName);
                Identity groupIdentity =
                    groupSecuritySvc.ReadIdentity(SearchFactor.AccountName, searchableGroupName, QueryMembership.Direct);

                if (groupSecuritySvc.IsMember(groupIdentity.Sid, userIdentity.Sid))
                {
                    FileHelper.Log("User {0} already part of group {1}", userName, searchableGroupName);
                }
                else
                {
                    groupSecuritySvc.AddMemberToApplicationGroup(groupIdentity.Sid, userIdentity.Sid);
                    FileHelper.Log("User {0} added to group {1}", userName, searchableGroupName);
                }
            }
            catch (Exception ex)
            {
                FileHelper.Log(ex.Message);
                FileHelper.Log(ex.StackTrace);
                return(false);
            }
            return(true);
        }