令牌对象更改的集合中获取具有指定 GUID 的更改标记。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public ReadOnly Default Property Item ( _
scopeId As Guid _
) As SPChangeToken
Get
用法
Dim instance As SPChangeTokenCollection
Dim scopeId As Guid
Dim value As SPChangeToken
value = instance(scopeId)
public SPChangeToken this[
Guid scopeId
] { get; }
参数
scopeId
类型:System.GuidSystem.Guid标识的更改标记。
属性值
类型:Microsoft.SharePoint.SPChangeToken
SPChangeToken 对象,该对象表示的更改标记。
备注
如果集合中不存在具有指定 GUID 的更改标记,该属性会返回空引用(无 在 Visual Basic 中)。
集合中的每个更改标记进行标记的ScopeId属性的值的索引。此属性的值是用于更改标记的目标的Id属性的值相同。因此SPChangeTokenCollection类的一个实例包含当前 Web 应用程序中的每个内容数据库的更改标记,您可以使用标识为索引集合中的特定内容数据库的 GUID 和得到一个标记,您可以使用它们来检索该内容数据库的更改。
示例
下面的示例是一个控制台应用程序创建内容数据库的集合和更改标记的相应集合。应用程序获取的 GUID 来标识每个数据库,并将其用作索引集合中的标记。然后,它使用的标记,它将检索查询标记应用于数据库的更改日志。
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