Export (0) Print
Expand All

LogArchiveSnapshot.ArchiveRegions Property

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

Namespace: System.IO.Log
Assembly: System.IO.Log (in system.io.log.dll)

public IEnumerable<FileRegion> ArchiveRegions { get; }
/** @property */
public IEnumerable<FileRegion> get_ArchiveRegions ()

public function get ArchiveRegions () : IEnumerable<FileRegion>

Not applicable.

Property Value

An enumerable collection of FileRegion instances containing the actual archival data.

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(); 
        } 
    } 
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft