Example #1
0
        private void UpdateTeams()
        {
            foreach (string team in Teams.Select(x => x.Name).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x, StringComparer.OrdinalIgnoreCase)))
            {
                Teams.Remove(team);
            }

            using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ActiveDirectorySettings.DefaultDomain))
            {
                foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys)
                {
                    try
                    {
                        using (GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, IdentityType.Name, ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName]))
                        {
                            TeamModel teamModel = new TeamModel()
                            {
                                Description = group.Description, Name = teamName, Members = group.Members.Select(x => x.UserPrincipalName).ToArray()
                            };
                            if (teamModel != null)
                            {
                                Teams.AddOrUpdate(teamModel);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
Example #2
0
        private void UpdateTeams()
        {
            foreach (var team in Teams.Select(x => new { x.Id, Name = x.Name }).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x.Name, StringComparer.OrdinalIgnoreCase)))
            {
                Teams.Remove(team.Id);
            }

            if (MembershipService == null)
            {
                MembershipService = new ADMembershipService();
            }

            using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ActiveDirectorySettings.DefaultDomain))
            {
                foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys)
                {
                    try
                    {
                        using (GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, IdentityType.Name, ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName]))
                        {
                            TeamModel teamModel = new TeamModel()
                            {
                                Id          = group.Guid.Value,
                                Description = group.Description,
                                Name        = teamName,
                                Members     = group.GetMembers(true).Select(x => MembershipService.GetUserModel(x.Guid.Value)).ToArray()
                            };
                            if (teamModel != null)
                            {
                                Teams.AddOrUpdate(teamModel);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogException(ex);
                    }
                }
            }
        }
        private void UpdateTeams()
        {
            foreach (var team in Teams.Select(x => new { x.Id, Name = x.Name }).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x.Name, StringComparer.OrdinalIgnoreCase)))
            {
                Teams.Remove(team.Id);
            }

            if (MembershipService == null)
            {
                MembershipService = new ADMembershipService();
            }

            foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys)
            {
                string groupName = ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName];

                Log.Verbose("AD: Updating team {TeamName} (groupName {GroupName})", teamName, groupName);
                try
                {
                    GroupPrincipal group;
                    using (var pc = ADHelper.GetPrincipalGroup(groupName, out group))
                    {
                        TeamModel teamModel = new TeamModel()
                        {
                            Id          = group.Guid.Value,
                            Description = group.Description,
                            Name        = teamName,
                            Members     = group.GetMembers(true).Select(x => MembershipService.GetUserModel(x.Guid.Value)).Where(o => o != null).ToArray()
                        };
                        Teams.AddOrUpdate(teamModel);
                        Log.Verbose("AD: Updated team {TeamName} OK", teamName);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "AD: Failed to update team {TeamName}", teamName);
                }
            }
        }