CSharpTest.Net
ForeachBlock Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > FragmentedFile Class : ForeachBlock Method

allocatedOnly
Allows enumeration of all stream, or of just the externally allocated streams
verifyReads
Determines if the checksum should be verified while reading the block bytes
ignoreException
A method that returns true to ignore the exception and continue processing

Glossary Item Box

Used for enumeration of the storage blocks in the file.

Syntax

Visual Basic (Declaration) 
Public Function ForeachBlock( _
   ByVal allocatedOnly As Boolean, _
   ByVal verifyReads As Boolean, _
   ByVal ignoreException As Converter(Of Exception,Boolean) _
) As IEnumerable(Of KeyValuePair(Of Long,Stream))

Parameters

allocatedOnly
Allows enumeration of all stream, or of just the externally allocated streams
verifyReads
Determines if the checksum should be verified while reading the block bytes
ignoreException
A method that returns true to ignore the exception and continue processing

Return Value

Enumeration of the identity and data stream of each block in the file

Example

Library/Library.Test/TestFragmentedFile.cs

C#Copy Code
Dictionary<long, byte[]> data = new Dictionary<long, byte[]>();
using (TempFile file = new TempFile())
using (FragmentedFile ff = FragmentedFile.CreateNew(file.TempPath, 512, 100, 2, FragmentedFile.OptionsDefault))
{
    //Create:
    for (int i = 0; i < 256; i++)
        data.Add(ff.Create(), null);
    //Enumerate:
    int count = 0;
    foreach (KeyValuePair<long, Stream> fragment in ff.ForeachBlock(true, true, null))
        count++;
    Assert.AreEqual(256, count);
    ff.Clear();
    //Empty?
    foreach (KeyValuePair<long, Stream> fragment in ff.ForeachBlock(true, true, null))
        Assert.Fail();
}
VB.NETCopy Code
Dim data As New Dictionary(Of Long, Byte())()
Using file As New TempFile()
    Using ff As FragmentedFile = FragmentedFile.CreateNew(file.TempPath, 512, 100, 2, FragmentedFile.OptionsDefault)
        'Create:
        Dim i As Integer = 0
        While i < 256
            data.Add(ff.Create(), Nothing)
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
        'Enumerate:
        Dim count As Integer = 0
        For Each fragment As KeyValuePair(Of Long, Stream) In ff.ForeachBlock(True, True, Nothing)
            System.Math.Max(System.Threading.Interlocked.Increment(count),count - 1)
        Next
        Assert.AreEqual(256, count)
        ff.Clear()
        'Empty?
        For Each fragment As KeyValuePair(Of Long, Stream) In ff.ForeachBlock(True, True, Nothing)
            Assert.Fail()
        Next
    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