IBackupRestore.OnRestore - Méthode

Lit les informations sauvegardées le contenu et le copie dans la cible de l'opération de restauration.

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

Syntaxe

'Déclaration
Function OnRestore ( _
    sender As Object, _
    args As SPRestoreInformation _
) As Boolean
'Utilisation
Dim instance As IBackupRestore
Dim sender As Object
Dim args As SPRestoreInformation
Dim returnValue As Boolean

returnValue = instance.OnRestore(sender, _
    args)
bool OnRestore(
    Object sender,
    SPRestoreInformation args
)

Paramètres

Valeur renvoyée

Type : System.Boolean
true en cas de réussite ; dans le cas contraire, false.

Remarques

Si votre classe de contenu peut être migrée, votre code doit vérifier quelle est la méthode de restauration et appeler Rename() si la méthode est New.

Si votre classe de contenu n'a aucun contenu à l'extérieur de tous les objets enfants IBackupRestore que peut-être, votre implémentation doit simplement définissez la CurrentProgess() au moins 50 pour cent et true comme dans l'exemple suivant. Faire ne pas appeler la méthode OnRestore de tous les objets enfant IBackupRestore .

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }
    if (args.RestoreMethod == SPRestoreMethodType.New)
    {
        args.Rename();
    }

    args.CurrentProgress = 50;
    return true;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If
    If args.RestoreMethod = SPRestoreMethodType.New Then
        args.Rename()
    End If

    args.CurrentProgress = 50
    Return True
End Function

Si votre classe possède du contenu à l'extérieur des objets enfants IBackupRestore qu'elle peut avoir, votre implémentation doit copier ce contenu vers la destination de restauration. Retournez false si cette copie échoue pour quelque raison que ce soit.

L'exemple suivant montre la structure globale d'une implémentation significative de OnRestore() :

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }
    if (args.RestoreMethod == SPRestoreMethodType.New)
    {
        args.Rename();
    }

    args.CurrentProgress = 50;
    Boolean successSignal = true;

    // TODO: Implement copying your content to the destination.
    //       If the copy fails, set successSignal to false.

    return successSignal;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If
    If args.RestoreMethod = SPRestoreMethodType.New Then
        args.Rename()
    End If

    args.CurrentProgress = 50
    Dim successSignal As Boolean = True

    ' TODO: Implement copying your content to the destination.
    '       If the copy fails, set successSignal to false.

    Return successSignal
End Function

Si un service Windows ou une application, doit être suspendu ou arrêté pendant la restauration, vous pouvez le faire au début de OnRestore. (Redémarrez le service ou l'application dans OnPostRestore(Object, SPBackupInformation)). Ne le faites pas ce travail en OnPreRestore(Object, SPBackupInformation) cette dernière méthode est appelée pour chaque composant, même s'il n'est pas en cours de restauration ; mais OnBackupComplete est appelée uniquement pour les composants qui sont restaurés, afin qu'il n'y a aucune garantie qu'une application ou un service arrêtée dans la phase de préparation serait obtenir redémarrée.

La méthode OnRestore ne s'exécutera pas si OnPreRestore renvoie false. Si OnRestore retourne false, la méthode OnPostRestore ne fonctionnera pas.

Exemples

L'exemple suivant montre une implémentation de OnRestore qui restaure les fichiers sur un serveur frontal. FrontEndFilePaths est un champ privé. Elle contient une collection de chemins d'accès des fichiers qui doivent être restaurés.

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }

    // If the CriticalFiles object was deleted from the farm after it was
    // backed up, restore it to the configuration database.
    CriticalFiles cf = SPFarm.Local.GetChild<CriticalFiles>(this.Name);
    if (cf == null)
    {
        this.Update();
        args.Log(SPBackupRestoreLogSeverity.Verbose, this.Name + " added back to configuration database.");
    }

    Boolean successSignal = true;

    // TODO: The following loop restores files to the local server. If there are 
    //       multiple front end servers, your code must iterate through all of 
    //       SPFarm.Local.Servers and restore the same files to every server whose
    //       Role property is SPServerRole.WebFrontEnd

    foreach (String path in FrontEndFilePaths)
    {
        FileInfo backupCopy = new FileInfo(path);
        FileInfo file = new FileInfo(args.Location + @"\" + backupCopy.Name);
        try
        {
            file.CopyTo(path, true);
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " + file.Name);
        }
        catch (Exception e)
        {
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name + " not restored: " + e.Message);
            successSignal = false;
        }
    }
    
    args.CurrentProgress = 50;
    return successSignal;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If

    ' If the CriticalFiles object was deleted from the farm after it was
    ' backed up, restore it to the configuration database.
    Dim cf As CriticalFiles = SPFarm.Local.GetChild(Of CriticalFiles)(Me.Name)
    If cf Is Nothing Then
        Me.Update()
        args.Log(SPBackupRestoreLogSeverity.Verbose, Me.Name & " added back to configuration database.")
    End If

    Dim successSignal As Boolean = True

    ' TODO: The following loop restores files to the local server. If there are 
    '       multiple front end servers, your code must iterate through all of 
    '       SPFarm.Local.Servers and restore the same files to every server whose
    '       Role property is SPServerRole.WebFrontEnd

    For Each path As String In FrontEndFilePaths
        Dim backupCopy As New FileInfo(path)
        Dim file As New FileInfo(args.Location & "\" & backupCopy.Name)
        Try
            file.CopyTo(path, True)
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " & file.Name)
        Catch e As Exception
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name & " not restored: " & e.Message)
            successSignal = False
        End Try
    Next path

    args.CurrentProgress = 50
    Return successSignal
End Function

Voir aussi

Référence

IBackupRestore interface

IBackupRestore - Membres

Microsoft.SharePoint.Administration.Backup - Espace de noms