IDatabaseSnapshotRestore.OnPreRestore 方法

提供了从一个其快照数据库 (SPDatabase对象) 的还原处理的准备工作。

命名空间:  Microsoft.SharePoint.Administration.Backup
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Sub OnPreRestore ( _
    args As SPDatabaseSnapshotRestoreEvent _
)
用法
Dim instance As IDatabaseSnapshotRestore
Dim args As SPDatabaseSnapshotRestoreEvent

instance.OnPreRestore(args)
void OnPreRestore(
    SPDatabaseSnapshotRestoreEvent args
)

参数

备注

实现此方法以提供从快照还原数据库之前执行的自定义逻辑。请考虑使用您的实现为用户提供取消还原操作的机会。

重要信息注释重要信息

如果它不能执行任何必要的前提条件,恢复到您的实现必须引发异常。有关详细信息,请参阅SPDatabaseSnapshot.Restore()的重载的参考主题。

从您自己的代码不调用此方法。还原过程会调用它。

示例

下面的示例演示可能用于数据库的实现。"this"指的是自定义的对象类型名开发人员已从SPDatabase派生的SupplementalDatabaseIDatabaseSnapshotRestore实现。该方法使数据库脱机,然后允许继续执行还原操作之前的 5 秒钟暂停线程。

public void OnPreRestore(SPDatabaseSnapshotRestoreEvent args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }

    try
    {
        this.Status = SPObjectStatus.Offline;
        this.Update();
        Thread.Sleep(5000);
    }
    catch (exception)
    {
        Exception e = new Exception(String.Format("Restoration from {0} cancelled because pre-restoration steps could not be executed.", args.Snapshot.Name), exception);
        throw e;
    }
}

另请参阅

引用

IDatabaseSnapshotRestore 接口

IDatabaseSnapshotRestore 成员

Microsoft.SharePoint.Administration.Backup 命名空间