LogArchiveSnapshot Class

Definition

Represents a snapshot of the LogStore instance that can be used to generate an archive.

public ref class LogArchiveSnapshot sealed
public sealed class LogArchiveSnapshot
type LogArchiveSnapshot = class
Public NotInheritable Class LogArchiveSnapshot
Inheritance
LogArchiveSnapshot

Examples

The following example shows how to use the LogArchiveSnapshot class 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

Remarks

A LogArchiveSnapshot object contains the information necessary to generate a consistent backup of the data in a LogStore. The actual data is contained in the enumerable collection of FileRegion objects returned by the ArchiveRegions property. Each FileRegion instance represents a sequence of bytes in a file that must be archived.

The ArchiveTail, BaseSequenceNumber, and LastSequenceNumber properties are for informational purposes only. They can be recorded along with the archive data to provide optional information, but are not required to restore the data.

Properties

ArchiveRegions

Gets an enumerable collection of FileRegion instances containing the actual archival data.

ArchiveTail

Gets the sequence number of the LogStore archive tail at the time the snapshot was taken.

BaseSequenceNumber

Gets the base sequence number of the LogStore at the time the snapshot was taken.

LastSequenceNumber

Gets the last sequence number of the LogStore at the time the snapshot was taken.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to