CSharpTest.Net
CreateNew(IFactory<Stream>,Int32,Int32,Int32) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > FragmentedFile Class > CreateNew Method : CreateNew(IFactory<Stream>,Int32,Int32,Int32) Method

streamFactory
blockSize
growthRate
cacheLimit

Glossary Item Box

Creates a new file (or truncates an existing one) that stores multiple smaller files

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function CreateNew( _
   ByVal streamFactory As IFactory(Of Stream), _
   ByVal blockSize As Integer, _
   ByVal growthRate As Integer, _
   ByVal cacheLimit As Integer _
) As FragmentedFile
C# 
public static FragmentedFile CreateNew( 
   IFactory<Stream> streamFactory,
   int blockSize,
   int growthRate,
   int cacheLimit
)

Parameters

streamFactory
blockSize
growthRate
cacheLimit

Example

Library/Library.Test/TestFragmentedFile.cs

C#Copy Code
using (SharedMemoryStream shared = new SharedMemoryStream())
using (FragmentedFile ff = FragmentedFile.CreateNew(shared, 512, 100, 2))
{
    long id = ff.Create();
    using (Stream write = ff.Open(id, FileAccess.Write))
    {
        Assert.IsFalse(write.CanRead);
        Assert.IsTrue(write.CanWrite);
        Assert.IsFalse(write.CanSeek);
        PrimitiveSerializer.Int64.WriteTo(id, write);
        write.Flush();//no-op

        AssertThrows<NotSupportedException>(delegate() { write.Position = 0; });
        AssertThrows<NotSupportedException>(delegate() { GC.KeepAlive(write.Position); });
        AssertThrows<NotSupportedException>(delegate() { GC.KeepAlive(write.Length); });
        AssertThrows<NotSupportedException>(delegate() { write.SetLength(1); });
        AssertThrows<NotSupportedException>(delegate() { write.Seek(1, SeekOrigin.Begin); });
        AssertThrows<NotSupportedException>(delegate() { write.ReadByte(); });
    }
}
VB.NETCopy Code
Using [shared] As New SharedMemoryStream()
    Using ff As FragmentedFile = FragmentedFile.CreateNew([shared], 512, 100, 2)
        Dim id As Long = ff.Create()
        Using write As Stream = ff.Open(id, FileAccess.Write)
            Assert.IsFalse(write.CanRead)
            Assert.IsTrue(write.CanWrite)
            Assert.IsFalse(write.CanSeek)
            PrimitiveSerializer.Int64.WriteTo(id, write)
            write.Flush()
            'no-op
            AssertThrows(Of NotSupportedException)(Function() Do
                write.Position = 0
            End Function)
            AssertThrows(Of NotSupportedException)(Function() Do
                GC.KeepAlive(write.Position)
            End Function)
            AssertThrows(Of NotSupportedException)(Function() Do
                GC.KeepAlive(write.Length)
            End Function)
            AssertThrows(Of NotSupportedException)(Function() Do
                write.SetLength(1)
            End Function)
            AssertThrows(Of NotSupportedException)(Function() Do
                write.Seek(1, SeekOrigin.Begin)
            End Function)
            AssertThrows(Of NotSupportedException)(Function() Do
                write.ReadByte()
            End Function)
        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