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

identity
access

Glossary Item Box

Opens the file with the identity previously obtained by Create() using the access provided; however, Read+Write is not supported, use either Read or Write but not both.

Syntax

Visual Basic (Declaration) 
Public Function Open( _
   ByVal identity As Long, _
   ByVal access As FileAccess _
) As Stream
C# 
public Stream Open( 
   long identity,
   FileAccess access
)

Parameters

identity
access

Exceptions

ExceptionDescription
System.ArgumentOutOfRangeExceptionThe exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method.

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