本文整理汇总了C#中System.IO.Log.LogArchiveSnapshot.LastSequenceNumber属性的典型用法代码示例。如果您正苦于以下问题:C# LogArchiveSnapshot.LastSequenceNumber属性的具体用法?C# LogArchiveSnapshot.LastSequenceNumber怎么用?C# LogArchiveSnapshot.LastSequenceNumber使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.IO.Log.LogArchiveSnapshot
的用法示例。
在下文中一共展示了LogArchiveSnapshot.LastSequenceNumber属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArchiveToXML
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();
}
}
}