Partager via


Extrait de code : mettre à jour les propriétés d’un abonnement de cache BCS

Dernière modification : lundi 7 juin 2010

S’applique à : SharePoint Server 2010

Dans cet article
Description
Conditions préalables requises
Pour utiliser cet exemple

Description

L’exemple suivant montre comment mettre à jour les propriétés d’un abonnement de cache, de requêtes et d’abonnements d’association sur le client.

Conditions préalables requises

  • Microsoft SharePoint Server 2010 ou Microsoft SharePoint Foundation 2010 installé sur le serveur

  • Microsoft Office Professionnel Plus 2010 et Microsoft .NET Framework 3.5 installés sur l’ordinateur client

  • Microsoft Visual Studio

  • Au moins un abonnement dans le cache client Business Connectivity Services

Pour utiliser cet exemple

  1. Démarrez Visual Studio sur l’ordinateur client, puis créez un projet de complément d’application Microsoft Office en C#. Sélectionnez .NET Framework 3.5 lorsque vous créez le projet.

  2. Dans le menu Affichage, sélectionnez Pages des propriétés pour afficher les propriétés du projet.

  3. Sous l’onglet Générer, pour Plateforme cible, sélectionnez Any CPU.

  4. Fermez la fenêtre de propriétés du projet.

  5. Dans l’Explorateur de solutions, sous Références, supprimez toutes les références du projet à l’exception de System et System.Core.

  6. Ajoutez les références suivantes au projet :

    1. Microsoft.Office.BusinessApplications.Runtime

    2. Microsoft.BusinessData

    3. Assemblys d’interopérabilité d’application Office

  7. Remplacez les instructions using existantes par les instructions suivantes :

    using System;
    using Microsoft.BusinessData.Offlining;
    using Microsoft.Office.BusinessData.Offlining;
    
  8. Remplacez le code dans l’événement de démarrage du complément par le code fourni à la fin de cette procédure.

  9. Remplacez les valeurs des espaces réservés <entityNamespace>, <entityName>, <viewName> et <subscriptionName> par des valeurs valides.

  10. Enregistrez le projet.

  11. Compilez et exécutez le projet.

    Cette action ouvre l’application Office et affiche les messages imprimés à partir de ce 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();
}

Voir aussi

Référence

RemoteOfflineRuntime

GetSubscriptionManager()

ISubscription

GetSubscription(String, String, String, String)

ExpireAfter

Update()

Queries

ISubscriptionQuery

Enabled

ExpireAfter

Update()

Associations

ISubscriptionAssociation

Enabled

ExpireAfter

Update()