Visual Basic (Declaration) | |
---|---|
Public Overloads Sub Commit() |
C# | |
---|---|
public void Commit() |
Library/Library.Test/TestTransactedCompoundFile.cs
C# | Copy Code |
---|---|
uint handle; byte[] bytes = RandomBytes(2140); using (TempFile temp = new TempFile()) { using (TransactedCompoundFile test = new TransactedCompoundFile(new TransactedCompoundFile.Options(temp.TempPath) { BlockSize=512, CreateNew = true })) { Assert.AreEqual(TransactedCompoundFile.FirstIdentity, test.Create()); test.Write(TransactedCompoundFile.FirstIdentity, Encoding.UTF8.GetBytes("Roger was here."), 0, 15); Assert.AreEqual("Roger was here.", Encoding.UTF8.GetString(IOStream.ReadAllBytes(test.Read(TransactedCompoundFile.FirstIdentity)))); for (int i = 0; i < 10; i++) { var id = test.Create(); test.Write(id, bytes, i, 300); if (i % 2 == 0) test.Delete(id); } handle = test.Create(); test.Write(handle, bytes, 1000, bytes.Length - 1000); CompareBytes(bytes, 1000, bytes.Length - 1000, IOStream.ReadAllBytes(test.Read(handle))); test.Write(handle, bytes, 0, bytes.Length); CompareBytes(bytes, 0, bytes.Length, IOStream.ReadAllBytes(test.Read(handle))); test.Commit(); } using (TransactedCompoundFile test = new TransactedCompoundFile(new TransactedCompoundFile.Options(temp.TempPath) { BlockSize=512, CreateNew = false })) { Assert.AreEqual("Roger was here.", Encoding.UTF8.GetString(IOStream.ReadAllBytes(test.Read(TransactedCompoundFile.FirstIdentity)))); CompareBytes(bytes, 0, bytes.Length, IOStream.ReadAllBytes(test.Read(handle))); } } |
VB.NET | Copy Code |
---|---|
Dim handle As UInteger Dim bytes As Byte() = RandomBytes(2140) Using temp As New TempFile() Using test As New TransactedCompoundFile(New TransactedCompoundFile.Options(temp.TempPath) With { _ Key .BlockSize = 512, _ Key .CreateNew = True _ }) Assert.AreEqual(TransactedCompoundFile.FirstIdentity, test.Create()) test.Write(TransactedCompoundFile.FirstIdentity, Encoding.UTF8.GetBytes("Roger was here."), 0, 15) Assert.AreEqual("Roger was here.", Encoding.UTF8.GetString(IOStream.ReadAllBytes(test.Read(TransactedCompoundFile.FirstIdentity)))) Dim i As Integer = 0 While i < 10 Dim id As var = test.Create() test.Write(id, bytes, i, 300) If i Mod 2 = 0 Then test.Delete(id) End If System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1) End While handle = test.Create() test.Write(handle, bytes, 1000, bytes.Length - 1000) CompareBytes(bytes, 1000, bytes.Length - 1000, IOStream.ReadAllBytes(test.Read(handle))) test.Write(handle, bytes, 0, bytes.Length) CompareBytes(bytes, 0, bytes.Length, IOStream.ReadAllBytes(test.Read(handle))) test.Commit() End Using Using test As New TransactedCompoundFile(New TransactedCompoundFile.Options(temp.TempPath) With { _ Key .BlockSize = 512, _ Key .CreateNew = False _ }) Assert.AreEqual("Roger was here.", Encoding.UTF8.GetString(IOStream.ReadAllBytes(test.Read(TransactedCompoundFile.FirstIdentity)))) CompareBytes(bytes, 0, bytes.Length, IOStream.ReadAllBytes(test.Read(handle))) End Using End Using |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7