For file-level transactions, Reloads the file from it's original (or last committed) state.
Syntax
Visual Basic (Declaration) | |
---|
Public Sub Rollback() |
C# | |
---|
public void Rollback() |
Exceptions
Example
Library/Library.Test/TestTransactedCompoundFile.cs
C# | Copy Code |
---|
using (TempFile temp = new TempFile())
{
byte[] sample = new byte[1024];
new Random().NextBytes(sample);
List<uint> handles = new List<uint>();
using (TransactedCompoundFile file = new TransactedCompoundFile(temp.TempPath))
{
for (int i = 0; i < 1000; i++)
{
var hid = file.Create();
handles.Add(hid);
file.Write(hid, sample, i, sample.Length - i);
CompareBytes(sample, i, sample.Length - i, IOStream.ReadAllBytes(file.Read(hid)));
}
file.Commit();
}
using (TransactedCompoundFile file = new TransactedCompoundFile(temp.TempPath))
{
byte[] dummy = new byte[1024];
for (int i = 0; i < 1000; i++)
{
file.Write(handles[i], dummy, 0, dummy.Length);
file.Delete(handles[i]);
}
file.Rollback();
for (int i = 0; i < 1000; i++)
{
CompareBytes(sample, i, sample.Length - i, IOStream.ReadAllBytes(file.Read(handles[i])));
}
}
} |
VB.NET | Copy Code |
---|
Using temp As New TempFile()
Dim sample As Byte() = New Byte(1024) {}
New Random().NextBytes(sample)
Dim [handles] As New List(Of UInteger)()
Using file As New TransactedCompoundFile(temp.TempPath)
Dim i As Integer = 0
While i < 1000
Dim hid As var = file.Create()
[handles].Add(hid)
file.Write(hid, sample, i, sample.Length - i)
CompareBytes(sample, i, sample.Length - i, IOStream.ReadAllBytes(file.Read(hid)))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
file.Commit()
End Using
Using file As New TransactedCompoundFile(temp.TempPath)
Dim dummy As Byte() = New Byte(1024) {}
Dim i As Integer = 0
While i < 1000
file.Write([handles](i), dummy, 0, dummy.Length)
file.Delete([handles](i))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
file.Rollback()
Dim i As Integer = 0
While i < 1000
CompareBytes(sample, i, sample.Length - i, IOStream.ReadAllBytes(file.Read([handles](i))))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also