private RoleGroupCollection GetInvalidRoleGroups()
        {
            bool flag = Datacenter.IsPartnerHostedOnly(false);
            RoleGroupCollection roleGroupCollection = new RoleGroupCollection();
            List <string>       enabledRoleGroupRoleAssignmentFeatures = this.ServicePlanSettings.Organization.GetEnabledRoleGroupRoleAssignmentFeatures();

            using (List <RoleGroupDefinition> .Enumerator enumerator = RoleGroupDefinitions.RoleGroups.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    RoleGroupDefinition  roleGroupDefinition = enumerator.Current;
                    RoleGroupRoleMapping roleGroupRoleMapping;
                    if (flag)
                    {
                        roleGroupRoleMapping = HostedTenant_RoleGroupDefinition.Definition.FirstOrDefault((RoleGroupRoleMapping x) => x.RoleGroup.Equals(roleGroupDefinition.Name, StringComparison.OrdinalIgnoreCase));
                    }
                    else
                    {
                        roleGroupRoleMapping = Tenant_RoleGroupDefinition.Definition.FirstOrDefault((RoleGroupRoleMapping x) => x.RoleGroup.Equals(roleGroupDefinition.Name, StringComparison.OrdinalIgnoreCase));
                    }
                    if (roleGroupRoleMapping != null && roleGroupRoleMapping.GetRolesAssignments(enabledRoleGroupRoleAssignmentFeatures).Count == 0)
                    {
                        roleGroupCollection.Add(new RoleGroupDefinition(roleGroupDefinition));
                    }
                }
            }
            return(roleGroupCollection);
        }
        private void CreateAndValidateRoleGroups(ADObjectId usgContainerId, RoleGroupCollection roleGroups)
        {
            RoleGroupDefinition roleGroupDefinition = roleGroups.FirstOrDefault((RoleGroupDefinition x) => x.RoleGroupGuid.Equals(RoleGroup.OrganizationManagement_InitInfo.WellKnownGuid));

            if (roleGroupDefinition == null)
            {
                base.WriteError(new ExOrgAdminSGroupNotFoundException(WellKnownGuid.EoaWkGuid), ErrorCategory.ObjectNotFound, null);
            }
            roleGroups.Remove(roleGroupDefinition);
            roleGroupDefinition.ADGroup = this.CreateRoleGroup(usgContainerId, roleGroupDefinition, null);
            if (!roleGroupDefinition.ADGroup.ManagedBy.Contains(roleGroupDefinition.ADGroup.Id))
            {
                roleGroupDefinition.ADGroup.ManagedBy.Add(roleGroupDefinition.ADGroup.Id);
                this.orgDomainRecipientSession.Save(roleGroupDefinition.ADGroup);
                base.LogWriteObject(roleGroupDefinition.ADGroup);
            }
            List <ADObjectId> manageBy = new List <ADObjectId>
            {
                roleGroupDefinition.ADGroup.Id
            };

            foreach (RoleGroupDefinition roleGroupDefinition2 in roleGroups)
            {
                roleGroupDefinition2.ADGroup = this.CreateRoleGroup(usgContainerId, roleGroupDefinition2, manageBy);
            }
            roleGroups.Add(roleGroupDefinition);
        }
        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);
        }