private static ValidationRule Create(ValidationRuleDefinition definition, RoleEntry roleEntry)
        {
            ExTraceGlobals.PublicCreationAPITracer.TraceDebug <string, string>((long)definition.GetHashCode(), "Entering ValidationRuleFactory.GetValidationRule({0}) - Creating ValidationRule. Name: '{1}'", (null == roleEntry) ? "<NULL>" : roleEntry.ToString(), definition.Name);
            OrganizationValidationRuleDefinition organizationValidationRuleDefinition = definition as OrganizationValidationRuleDefinition;

            if (organizationValidationRuleDefinition != null)
            {
                return(new OrganizationValidationRule(organizationValidationRuleDefinition, roleEntry));
            }
            IEnumerable <Capability>             restrictedCapabilities = definition.RestrictedCapabilities;
            List <CapabilityIdentifierEvaluator> list = new List <CapabilityIdentifierEvaluator>();

            foreach (Capability capability in restrictedCapabilities)
            {
                list.Add(CapabilityIdentifierEvaluatorFactory.Create(capability));
            }
            IEnumerable <Capability>             overridingAllowCapabilities = definition.OverridingAllowCapabilities;
            List <CapabilityIdentifierEvaluator> list2 = new List <CapabilityIdentifierEvaluator>();

            foreach (Capability capability2 in overridingAllowCapabilities)
            {
                list2.Add(CapabilityIdentifierEvaluatorFactory.Create(capability2));
            }
            if (definition.Expressions == null)
            {
                return(new RestrictedValidationRule(definition, list, list2, roleEntry));
            }
            return(new ExpressionFilterValidationRule(definition, list, list2, roleEntry));
        }
        private void RemoveObsoleteEntriesAndParameters(ExchangeRole role)
        {
            if (role.RoleType == RoleType.UnScoped)
            {
                return;
            }
            List <RoleEntry> list = new List <RoleEntry>();

            foreach (RoleEntry roleEntry in role.RoleEntries)
            {
                RoleEntry roleEntry2 = roleEntry.FindAndIntersectWithMatchingParameters(this.allAllowedRoleEntriesForSKU);
                if (roleEntry2 != null)
                {
                    list.Add(roleEntry2);
                    if (roleEntry2 != roleEntry)
                    {
                        base.WriteVerbose(Strings.ConfirmationMessageRemoveManagementRoleEntry(roleEntry.ToString(), role.Id.ToString()));
                        base.WriteVerbose(Strings.ConfirmationMessageNewManagementRoleEntry(roleEntry2.ToString(), role.Id.ToString()));
                    }
                }
                else
                {
                    base.WriteVerbose(Strings.ConfirmationMessageRemoveManagementRoleEntry(roleEntry.ToString(), role.Id.ToString()));
                }
            }
            role.RoleEntries = new MultiValuedProperty <RoleEntry>(list);
        }