private void PurgeInvalidAssignmentsFromRoleGroup(RoleGroupRoleMapping rgMapping, ADGroup roleGroup, List <ExchangeRole> topCannedRoles)
        {
            TaskLogger.LogEnter();
            if (!InstallCannedRbacRoleAssignments.MonitoredDCOnlyRoleGroups.Contains(rgMapping.RoleGroup))
            {
                return;
            }
            List <string> list = new List <string>(rgMapping.Assignments.Length * 2);

            RoleAssignmentDefinition[] assignments = rgMapping.Assignments;
            for (int i = 0; i < assignments.Length; i++)
            {
                RoleAssignmentDefinition assignmentDefinition = assignments[i];
                List <ExchangeRole>      list2 = topCannedRoles.FindAll((ExchangeRole x) => x.RoleType.Equals(assignmentDefinition.RoleType));
                if (list2 != null)
                {
                    foreach (ExchangeRole exchangeRole in list2)
                    {
                        list.Add(exchangeRole.DistinguishedName);
                        list.Add(exchangeRole.Id.GetChildId(RoleDefinition.GetDCSafeNameForRole(exchangeRole.Name)).DistinguishedName);
                    }
                }
            }
            ADPagedReader <ExchangeRoleAssignment> adpagedReader = this.configurationSession.FindPaged <ExchangeRoleAssignment>(base.OrgContainerId.GetDescendantId(ExchangeRoleAssignment.RdnContainer), QueryScope.SubTree, new ComparisonFilter(ComparisonOperator.Equal, ExchangeRoleAssignmentSchema.User, roleGroup.Id), null, 0);

            using (IEnumerator <ExchangeRoleAssignment> enumerator2 = adpagedReader.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    ExchangeRoleAssignment roleAssignment = enumerator2.Current;
                    if (!list.Contains(roleAssignment.Role.DistinguishedName, StringComparer.OrdinalIgnoreCase))
                    {
                        if (topCannedRoles.Find((ExchangeRole x) => x.Name.Equals(roleAssignment.Role.Name, StringComparison.OrdinalIgnoreCase) && x.RoleType.Equals(RoleType.UnScoped)) == null)
                        {
                            ExchangeRole exchangeRole2 = this.configurationSession.Read <ExchangeRole>(roleAssignment.Role);
                            if (exchangeRole2 != null && !exchangeRole2.RoleType.Equals(RoleType.UnScoped))
                            {
                                this.RemoveRoleAssignment(roleAssignment);
                            }
                        }
                    }
                }
            }
            TaskLogger.LogExit();
        }
        internal static RoleGroupCollection RoleGroupsToCreate()
        {
            RoleGroupCollection roleGroupCollection = new RoleGroupCollection();

            Datacenter.ExchangeSku exchangeSku = Datacenter.GetExchangeSku();
            RoleGroupRoleMapping[] definition;
            if (Datacenter.IsMicrosoftHostedOnly(false))
            {
                definition = Datacenter_RoleGroupDefinition.Definition;
            }
            else if (Datacenter.IsPartnerHostedOnly(false))
            {
                definition = Hosting_RoleGroupDefinition.Definition;
            }
            else if (Datacenter.IsDatacenterDedicated(false))
            {
                definition = Dedicated_RoleGroupDefinition.Definition;
            }
            else
            {
                definition = Enterprise_RoleGroupDefinition.Definition;
            }
            using (List <RoleGroupDefinition> .Enumerator enumerator = RoleGroupDefinitions.RoleGroups.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    RoleGroupDefinition roleGroup = enumerator.Current;
                    if (roleGroup.AlwaysCreateOnSku != null && roleGroup.AlwaysCreateOnSku.Contains(exchangeSku))
                    {
                        roleGroupCollection.Add(new RoleGroupDefinition(roleGroup));
                    }
                    else
                    {
                        RoleGroupRoleMapping roleGroupRoleMapping = definition.FirstOrDefault((RoleGroupRoleMapping x) => x.RoleGroup.Equals(roleGroup.Name, StringComparison.OrdinalIgnoreCase));
                        if (roleGroupRoleMapping != null)
                        {
                            roleGroupCollection.Add(new RoleGroupDefinition(roleGroup));
                        }
                    }
                }
            }
            return(roleGroupCollection);
        }