LogStore.SetArchiveTail(SequenceNumber) Metodo

Definizione

Imposta il numero di sequenza della coda di archiviazione.Sets the sequence number of the archive tail.

public:
 void SetArchiveTail(System::IO::Log::SequenceNumber archiveTail);
public void SetArchiveTail (System.IO.Log.SequenceNumber archiveTail);
member this.SetArchiveTail : System.IO.Log.SequenceNumber -> unit
Public Sub SetArchiveTail (archiveTail As SequenceNumber)

Parametri

archiveTail
SequenceNumber

Numero di sequenza della coda di archiviazione.The sequence number of the archive tail.

Eccezioni

archiveTail non è compreso tra i numeri di sequenza di base e finale di questa sequenza.archiveTail is not between the base and last sequence numbers of this sequence.

archiveTail non è valido per questa sequenza.archiveTail is not valid for this sequence.

È stata eseguita un’operazione non valida.An invalid operation has been executed.

Si verifica un errore di I/O durante la creazione dell’istantanea dell'archivio.An I/O error occurs when creating the archive snapshot.

L'archivio dei registri non è archivable.The log store is not archivable.

Il metodo è stato chiamato dopo l'eliminazione sequenza.The method was called after the sequence has been disposed of.

Memoria insufficiente per continuare l'esecuzione di un programma.There is not enough memory to continue the execution of a program.

L'accesso per l'archivio dei registri specificato viene negato dal sistema operativo.Access for the specified log store is denied by the operating system.

Esempi

Nell'esempio seguente viene illustrato come memorizzare un LogStore in un documento XML.The following example shows how to archive a LogStore to an XML document.

class LogBackup
{ 
    static void ArchiveToXML(LogStore logStore, string fileName) 
    {  
        LogArchiveSnapshot snapshot = logStore.CreateLogArchiveSnapshot();
        
        XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.ASCII);
        
        writer.WriteStartElement("logArchive");
        foreach(FileRegion region in snapshot.ArchiveRegions) 
        {
            writer.WriteStartElement("fileRegion"); 
            writer.WriteElementString("path", region.Path); 
            writer.WriteElementString("length", region.FileLength.ToString()); 
            writer.WriteElementString("offset", region.Offset.ToString()); 
            using(Stream dataStream = region.GetStream()) 
            { 
                byte[] data = new byte[dataStream.Length]; 
                dataStream.Read(data, 0, data.Length); 
                writer.WriteElementString("data", Convert.ToBase64String(data)); 
            }
            writer.WriteEndElement();
        }
        writer.WriteEndElement(); 
        writer.Close(); 
        logStore.SetArchiveTail(snapshot.LastSequenceNumber); 
    }
    static void RestoreFromXML(string fileName) 
    { 
        using(XmlTextReader reader = new XmlTextReader(fileName)) 
        {
            reader.ReadStartElement("logArchive"); 
            while(reader.IsStartElement()) 
            { 
                string path = reader.ReadElementString("path"); 
                long length = Int64.Parse(reader.ReadElementString("length")); 
                long offset = Int64.Parse(reader.ReadElementString("offset")); 
                string dataString = reader.ReadElementString("data"); 
                byte[] data = Convert.FromBase64String(dataString); 
                FileStream fileStream;
                using(fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) 
                { 
                    fileStream.SetLength(length); 
                    fileStream.Position = offset; fileStream.Write(data, 0, data.Length); 
                }
            } 
        reader.ReadEndElement(); 
        } 
    } 
}
Friend Class LogBackup
    Private Shared Sub ArchiveToXML(ByVal logStore As LogStore, ByVal fileName As String)
        Dim snapshot As LogArchiveSnapshot = logStore.CreateLogArchiveSnapshot()

        Dim writer As New XmlTextWriter(fileName, Encoding.ASCII)

        writer.WriteStartElement("logArchive")
        For Each region As FileRegion In snapshot.ArchiveRegions
            writer.WriteStartElement("fileRegion")
            writer.WriteElementString("path", region.Path)
            writer.WriteElementString("length", region.FileLength.ToString())
            writer.WriteElementString("offset", region.Offset.ToString())
            Using dataStream As Stream = region.GetStream()
                Dim data(dataStream.Length - 1) As Byte
                dataStream.Read(data, 0, data.Length)
                writer.WriteElementString("data", Convert.ToBase64String(data))
            End Using
            writer.WriteEndElement()
        Next region
        writer.WriteEndElement()
        writer.Close()
        logStore.SetArchiveTail(snapshot.LastSequenceNumber)

    End Sub
    Private Shared Sub RestoreFromXML(ByVal fileName As String)
        Using reader As New XmlTextReader(fileName)
            reader.ReadStartElement("logArchive")
            Do While reader.IsStartElement()
                Dim path = reader.ReadElementString("path")
                Dim length = Int64.Parse(reader.ReadElementString("length"))
                Dim offset = Int64.Parse(reader.ReadElementString("offset"))
                Dim dataString = reader.ReadElementString("data")
                Dim data() = Convert.FromBase64String(dataString)
                Dim fileStream As FileStream
                fileStream = New FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)
                Using fileStream
                    fileStream.SetLength(length)
                    fileStream.Position = offset
                    fileStream.Write(data, 0, data.Length)
                End Using
            Loop
            reader.ReadEndElement()
        End Using
    End Sub
End Class

Commenti

Il numero di sequenza di base inferiore e la coda di archiviazione determinano la coda del log.The smaller of the base sequence number and the archive tail determines the tail of the log.

Si applica a