CSharpTest.Net
Commit Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Interfaces Namespace > ITransactable Interface : Commit Method

Glossary Item Box

Completes the operation

Syntax

Visual Basic (Declaration) 
Sub Commit() 
C# 
void Commit()

Example

Library/Library.Test/TestFragmentedFile.cs

C#Copy Code
SharedMemoryStream shared = new SharedMemoryStream();
FragmentedFile.CreateNew(shared, 512, 100, 2).Dispose();

using (FragmentedFile ff = new FragmentedFile(shared, 512, 100, 2))
{
    long id;
    byte[] bytes = MakeBytes(255);
    using (Stream write = ff.Create(out id))
    using (ITransactable trans = (ITransactable)write)
    {
        write.Write(bytes, 0, bytes.Length);
        trans.Commit();
        Assert.AreEqual(bytes, IOStream.ReadAllBytes(ff.Open(id, FileAccess.Read)));
        trans.Rollback();
    }

    AssertThrows<InvalidDataException>(delegate() { ff.Open(id, FileAccess.Read); });
}
VB.NETCopy Code
Dim [shared] As New SharedMemoryStream()
FragmentedFile.CreateNew([shared], 512, 100, 2).Dispose()

Using ff As New FragmentedFile([shared], 512, 100, 2)
    Dim id As Long
    Dim bytes As Byte() = MakeBytes(255)
    Using write As Stream = ff.Create(id)
        Using trans As ITransactable = DirectCast(write, ITransactable)
            write.Write(bytes, 0, bytes.Length)
            trans.Commit()
            Assert.AreEqual(bytes, IOStream.ReadAllBytes(ff.Open(id, FileAccess.Read)))
            trans.Rollback()
        End Using
    End Using

    AssertThrows(Of InvalidDataException)(Function() Do
        ff.Open(id, FileAccess.Read)
    End Function)
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys