Code Snippet: Update Properties of a BCS Cache Subscription
Applies to: SharePoint Server 2010
In this article
Description
Prerequisites
To use this example
Description
The following example shows how to update the properties of a cache subscription, queries, and association subscriptions on the client.
Prerequisites
Microsoft SharePoint Server 2010 or Microsoft SharePoint Foundation 2010 installed on the server
Microsoft Office Professional Plus 2010 and Microsoft .NET Framework 3.5 installed on the client computer
Microsoft Visual Studio
At least one subscription in the Business Connectivity Services Client Cache
To use this example
Start Visual Studio on the client computer, and then create a new C# Microsoft Office application add-in project. Select .NET Framework 3.5 when you create the project.
From the View menu, select Property Pages to bring up the project properties.
On the Build tab, for the Platform target, select Any CPU.
Close the project properties window.
In Solution Explorer, under References, remove all project references except for System and System.Core.
Add the following references to the project:
Microsoft.Office.BusinessApplications.Runtime
Microsoft.BusinessData
The Office application interop assemblies
Replace the existing using statements with the following statements:
using System; using Microsoft.BusinessData.Offlining; using Microsoft.Office.BusinessData.Offlining;
Replace the code in the add-in’s startup event with the code listed at the end of this procedure.
Replace the placeholder values of <entityNamespace>, <entityName>, <viewName>, and <subscriptionName> with valid values.
Save the project.
Compile and run the project.
This opens the Office application and displays the messages printed from this code.
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();
}
See Also
Reference
RemoteOfflineRuntime
GetSubscriptionManager()