4、为访问群体添加复杂的基于AND 、OR和()的规则
我们可以使用括号与AND ,OR共同作用,组合出更复杂的规则来。 Sharepoint Portal Server的对象模型可以支持最多三层括号的嵌套。
注意:如果一个访问群体对应复杂的规则,您就不能在Web管理页面中查看或编辑其属性了。不过不用担心,您仍可以在Web管理页面中查看其包含的成员。
下面是个组合出复杂规则的例子
TopologyManager topology = new TopologyManager();
PortalSite portal = topology.PortalSites[new Uri("http://server_name")];
PortalContext context = PortalApplication.GetContext(portal);
AudienceManager AudMgr = new AudienceManager(context);
Audience a = null;
bool ruleListNotEmpty = false;
try
{
a = AudMgr.Audiences["Engineer"];
}
catch(AudienceArgumentException ex)
{}
ArrayList aRules = a.AudienceRules;
if( aRules == null )
{
aRules = new ArrayList();
}
else
{
ruleListNotEmpty = true;
}
try
{
if (ruleListNotEmpty)
{
aRules.Add(new AudienceRuleComponent(null, "AND", null));
}
AudienceRuleComponent r0 = new AudienceRuleComponent(null, "(", null);
aRules.Add(r0);
AudienceRuleComponent r1 = new AudienceRuleComponent("FirstName", "Contains", "a");
aRules.Add(r1);
AudienceRuleComponent r2 = new AudienceRuleComponent(null, "AND", null);
aRules.Add(r2);
AudienceRuleComponent r3 = new AudienceRuleComponent("WorkEmail", "Contains", "DepA.com");
aRules.Add(r3);
AudienceRuleComponent r4 = new AudienceRuleComponent(null, ")", null);
aRules.Add(r4);
AudienceRuleComponent r5 = new AudienceRuleComponent(null, "OR", null);
aRules.Add(r5);
AudienceRuleComponent r6 = new AudienceRuleComponent(null, "(", null);
aRules.Add(r6);
AudienceRuleComponent r7 = new AudienceRuleComponent("FirstName", "Contains", "b");
aRules.Add(r7);
AudienceRuleComponent r8 = new AudienceRuleComponent(null, "AND", null);
aRules.Add(r8);
AudienceRuleComponent r9 = new AudienceRuleComponent("WorkEmail", "Contains", "DepB.com");
aRules.Add(r9);
AudienceRuleComponent r10 = new AudienceRuleComponent(null, ")", null);
aRules.Add(r10);
a.AudienceRules = aRules;
a.Commit();
}