代码段:更新 BCS 缓存订阅的属性
上次修改时间: 2010年6月7日
适用范围: SharePoint Server 2010
本文内容
说明
必备组件
使用该示例
说明
以下示例演示了如何更新客户端上的缓存订阅、查询和关联订阅的属性。
必备组件
服务器上安装了 Microsoft SharePoint Server 2010 或 Microsoft SharePoint Foundation 2010
客户端计算机上安装了 Microsoft Office Professional Plus 2010 和 Microsoft .NET Framework 3.5
Microsoft Visual Studio
Business Connectivity Services 客户端缓存中至少有一个订阅
使用该示例
启动客户端计算机上的 Visual Studio,然后新建一个 C# Microsoft Office 应用程序加载项项目。在创建项目时,选择".NET Framework 3.5"。
从"视图"菜单中,选择"属性页"以显示项目属性。
在"生成"选项卡中,为"目标平台"选择"任何 CPU"。
关闭项目属性窗口。
在"解决方案资源管理器"中的"引用"下,移除除 System 和 System.Core 之外的所有项目引用。
将以下引用添加到项目中:
Microsoft.Office.BusinessApplications.Runtime
Microsoft.BusinessData
Office 应用程序互操作程序集
使用以下语句替换现有 using 语句:
using System; using Microsoft.BusinessData.Offlining; using Microsoft.Office.BusinessData.Offlining;
将加载项启动事件中的代码替换为该过程末尾列出的代码。
将 <entityNamespace>、<entityName>、<viewName> 和 <subscriptionName> 占位符值替换为有效值。
保存该项目。
编译并运行该项目。
这将打开 Office 应用程序并显示根据该代码输出的消息。
RemoteOfflineRuntime remoteOfflineRuntime = new RemoteOfflineRuntime();
// Read the subscription.
ISubscription sub =
remoteOfflineRuntime.GetSubscriptionManager().GetSubscription(
"<entityNamespace>", "<entityName>", "<viewName>", "<subscriptionName>");
// Updating the Subscription Refresh Interval.
sub.ExpireAfter = new TimeSpan(0, 30, 0);
sub.Update();
// Enumerate through the queries of the subscription, change their refresh
// interval, and enable them.
// If the properties are going to be changed for a particular query, we
// could check the name of the subscription query to determine whether
// the properties are to be changed.
foreach (ISubscriptionQuery query in sub.Queries)
{
// If the subscription query is disabled, enable it.
if (query.Enabled == false)
{
query.Enabled = true;
}
// Set the refresh interval of the query.
query.ExpireAfter = TimeSpan.FromMinutes(10);
// Update the properties of the subscription query.
query.Update();
}
// Enumerate through the Associations of the subscription, change
// their refresh interval, and enable them.
// If the properties are going to be changed for a particular Association
// we could check the name of the subscription Association to determine
// whether the properties are to be changed.
foreach (ISubscriptionAssociation association in sub.Associations)
{
// If the subscription association is disabled, enable it.
if (association.Enabled == false)
{
association.Enabled = true;
}
// Set the refresh interval of the association.
association.ExpireAfter = TimeSpan.FromMinutes(10);
// Update the properties of the subscription association.
association.Update();
}