SPChangeTokenCollection.Item property (Guid)
指定的 GUID 變更語彙基元從集合中取得變更的語彙基元的物件。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
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
Type: System.GuidSystem.Guid用來識別變更語彙基元。
Property value
Type: Microsoft.SharePoint.SPChangeToken
SPChangeToken 物件,表示變更語彙基元。
備註
如果變更具有的語彙基元指定的 GUID 不存在於集合中,這個屬性會傳回a null reference (Nothing in Visual Basic)。
集合中的每個變更語彙基元被索引的語彙基元的ScopeId屬性的值。這個屬性的值是目標的相同變更語彙基元的 [ Id ] 屬性的值。因此如果SPChangeTokenCollection類別的執行個體包含在目前的 Web 應用程式中每個內容資料庫的變更語彙基元,則您可以使用可識別特定的內容資料庫做為索引至集合的 GUID,並取得上一步您可用來擷取該內容的資料庫變更的語彙基元。
Examples
下列範例會建立內容資料庫的集合和對應的集合變更語彙基元的主控台應用程式。應用程式取得識別每個資料庫,並使用它做為索引的語彙基元集合內的 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
請參閱
參照
SPChangeTokenCollection members