Partager via


SPChangeTokenCollection.Item - Propriété (Guid)

Obtient le jeton de modification avec le GUID spécifié de la collection de modification des objets jetons.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public ReadOnly Default Property Item ( _
    scopeId As Guid _
) As SPChangeToken
    Get
'Utilisation
Dim instance As SPChangeTokenCollection
Dim scopeId As Guid
Dim value As SPChangeToken

value = instance(scopeId)
public SPChangeToken this[
    Guid scopeId
] { get; }

Paramètres

  • scopeId
    Type : System.Guid

    System.Guid qui identifie le jeton de modification.

Valeur de propriété

Type : Microsoft.SharePoint.SPChangeToken
Objet SPChangeToken qui représente le jeton de modification.

Remarques

Si un jeton de modification avec le GUID spécifié n'existe pas dans la collection, cette propriété retourne une référence Null (Rien dans Visual Basic).

Chaque jeton de modification d'une collection est indexée par la valeur de la propriété du jeton ScopeId . La valeur de cette propriété est identique à la valeur de la propriété Id de la cible pour le jeton de modification. Ainsi, si une instance de la classe SPChangeTokenCollection contient des jetons de modification pour chaque base de données contenu dans l'application Web en cours, vous pouvez utiliser le GUID qui identifie une base de données de contenu particulière en tant qu'index dans la collection et obtenir un jeton que vous pouvez utiliser pour récupérer les modifications de la base contenu.

Exemples

L'exemple suivant est une application console qui crée une collection de bases de données de contenu et une collection de jetons de modification correspondante. L'application obtient le GUID qui identifie chaque base de données et l'utilise comme un index dans la collection de jetons. Il utilise ensuite le jeton qui est extrait pour interroger le journal des modifications pour la base de données à laquelle s'applique le jeton.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         // Get a collection of content databases
         SPWebApplication wa = SPWebApplication.Lookup(new Uri("https://localhost"));
         SPContentDatabaseCollection dbs = wa.ContentDatabases;

         // Create a collection of change tokens with
         // one token for each database. Each token marks the
         // current end point of the change log for a database.
         SPChangeTokenCollection tokens = new SPChangeTokenCollection();
         foreach (SPContentDatabase db in dbs)
            tokens.Add(db.CurrentChangeToken);

         // Do something that changes objects stored
         // within each database
         // .
         // .
         // .

         // Get any changes that have taken place
         long total = 0;
         foreach (SPContentDatabase db in dbs)
         {
            // Get a GUID for the db.
            // Note that a cast is needed to access the Id property.
            SPPersistedObject po = db as SPPersistedObject;
            Guid id = po.Id;

            // Use the GUID to get a token for the db
            SPChangeToken startingToken = tokens[id];
            
            // Get the first batch of changes 
            SPChangeCollection changes = db.GetChanges(startingToken);

            // Loop until there are no more changes 
            while (changes.Count > 0)
            { 
               // Accumulate a total
               total += changes.Count;

               // Go get another batch
               startingToken = changes.LastChangeToken;
               changes = db.GetChanges(startingToken);
            }
         }
         Console.WriteLine("Total changes: {0}", total.ToString());
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration

Module ConsoleApp
   Sub Main()
      ' Get a collection of content databases
      Dim wa As SPWebApplication = SPWebApplication.Lookup(New Uri("https://localhost"))
      Dim dbs As SPContentDatabaseCollection = wa.ContentDatabases

      ' Create a collection of change tokens with
      ' one token for each database. Each token marks the
      ' current end point of the change log for a database.
      Dim tokens As SPChangeTokenCollection = New SPChangeTokenCollection()
      Dim db As SPContentDatabase
      For Each db In dbs
         tokens.Add(db.CurrentChangeToken)
      Next

      ' Do something that changes objects stored
      ' within each database
      ' .
      ' .
      ' .

      ' Get any changes that have taken place
      Dim total As Long = 0
      For Each db In dbs
         ' Get a GUID for the db.
         ' Note that a cast is needed to access the Id property.
         Dim po As SPPersistedObject = CType(db, SPPersistedObject)
         Dim id As Guid = po.Id

         ' Use the GUID to get a token for the db
         Dim startingToken As SPChangeToken = tokens(id)

         ' Get the first batch of changes
         Dim changes As SPChangeCollection = db.GetChanges(startingToken)

         ' Loop until there are no more changes
         While (changes.Count > 0)

            ' Accumulate a total
            total += changes.Count

            ' Go get another batch
            startingToken = changes.LastChangeToken
            changes = db.GetChanges(startingToken)
         End While
      Next db

      Console.WriteLine("Total changes: {0}", total.ToString())
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()

   End Sub
End Module

Voir aussi

Référence

SPChangeTokenCollection classe

SPChangeTokenCollection - Membres

Item - Surcharge

Microsoft.SharePoint - Espace de noms

ScopeId