CSharpTest.Net
CommitOnDispose Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > TransactedCompoundFile.Options Class : CommitOnDispose Property

Glossary Item Box

Automatically Commit the storage file when it's disposed.

Syntax

Visual Basic (Declaration) 
Public Property CommitOnDispose As Boolean
C# 
public bool CommitOnDispose {get; set;}

Example

Library/Library.Test/TestTransactedCompoundFile.cs

C#Copy Code
using (TempFile temp1 = new TempFile())
using (TempFile temp2 = new TempFile())
{
    var options = new TransactedCompoundFile.Options(temp1.TempPath) { BlockSize = 512 };

    const int count = 4;
    byte[] sample1 = new byte[options.MaxWriteSize / 3];
    byte[] sample2 = (byte[])sample1.Clone();
    new Random().NextBytes(sample1);
    new Random().NextBytes(sample2);

    using (TransactedCompoundFile file = new TransactedCompoundFile(options))
    {
        for (uint h = 1u; h < count; h++)
            Assert.AreEqual(h, file.Create());
        for (uint h = 1u; h < count; h++)
            file.Write(h, sample1, 0, sample1.Length);
        file.Commit();//persist.
        for (uint h = 1u; h < count; h++)
            file.Write(h, sample2, 0, sample2.Length);

        file.Commit(x => temp1.CopyTo(temp2.TempPath, true), 0);
    }

    options = new TransactedCompoundFile.Options(temp2.TempPath) { BlockSize = 512, CommitOnDispose = false };

    //Verify primary has sample2 data
    options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary;
    using (TransactedCompoundFile file = new TransactedCompoundFile(options))
    {
        for (uint h = 1u; h < count; h++)
            CompareBytes(sample2, 0, sample2.Length, IOStream.ReadAllBytes(file.Read(h)));
    }
    //Verify secondary has sample1 data
    options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary;
    using (TransactedCompoundFile file = new TransactedCompoundFile(options))
    {
        for (uint h = 1u; h < count; h++)
            CompareBytes(sample1, 0, sample1.Length, IOStream.ReadAllBytes(file.Read(h)));
    }
}
VB.NETCopy Code
Using temp1 As New TempFile()
    Using temp2 As New TempFile()
        Dim options As var = New TransactedCompoundFile.Options(temp1.TempPath) With { _
            Key .BlockSize = 512 _
        }

        Const  count As Integer = 4
        Dim sample1 As Byte() = New Byte(options.MaxWriteSize / 3) {}
        Dim sample2 As Byte() = DirectCast(sample1.Clone(), Byte())
        New Random().NextBytes(sample1)
        New Random().NextBytes(sample2)

        Using file As New TransactedCompoundFile(options)
            Dim h As UInteger = 1UI
            While h < count
                Assert.AreEqual(h, file.Create())
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
            Dim h As UInteger = 1UI
            While h < count
                file.Write(h, sample1, 0, sample1.Length)
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
            file.Commit()
            'persist.
            Dim h As UInteger = 1UI
            While h < count
                file.Write(h, sample2, 0, sample2.Length)
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While

            file.Commit(Function(x) temp1.CopyTo(temp2.TempPath, True), 0)
        End Using

        options = New TransactedCompoundFile.Options(temp2.TempPath) With { _
            Key .BlockSize = 512, _
            Key .CommitOnDispose = False _
        }

        'Verify primary has sample2 data
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary
        Using file As New TransactedCompoundFile(options)
            Dim h As UInteger = 1UI
            While h < count
                CompareBytes(sample2, 0, sample2.Length, IOStream.ReadAllBytes(file.Read(h)))
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
        End Using
        'Verify secondary has sample1 data
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary
        Using file As New TransactedCompoundFile(options)
            Dim h As UInteger = 1UI
            While h < count
                CompareBytes(sample1, 0, sample1.Length, IOStream.ReadAllBytes(file.Read(h)))
                System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
            End While
        End Using
    End Using
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