Implementing this interface allows a binary stream to be attached to a buffer.
Inheritance: IDisposable
コード例 #1
0
 /// <summary>
 /// Creates a <see cref="BinaryStream"/> that is at position 0 of the provided stream.
 /// </summary>
 /// <param name="stream">The base stream to use.</param>
 /// <param name="leaveOpen">Determines if the underlying stream will automatically be
 /// disposed of when this class has it's dispose method called.</param>
 public BinaryStream(ISupportsBinaryStream stream, bool leaveOpen = true)
 {
     m_args        = new BlockArguments();
     m_leaveOpen   = leaveOpen;
     m_stream      = stream;
     FirstPosition = 0;
     Current       = null;
     First         = null;
     LastRead      = null;
     LastWrite     = null;
     if (stream.RemainingSupportedIoSessions < 1)
     {
         throw new Exception("Stream has run out of read sessions");
     }
     m_mainIoSession = stream.CreateIoSession();
     //if (stream.RemainingSupportedIoSessions >= 1)
     //    m_secondaryIoSession = stream.CreateIoSession();
 }
コード例 #2
0
        /// <summary>
        /// Creates a new DiskIoSession that can be used to read from the disk subsystem.
        /// </summary>
        /// <param name="diskIo">owner of the disk</param>
        /// <param name="ioSession">the base ioSession to use for this io session</param>
        /// <param name="file">The file that will be read from this diskIoSession</param>
        public DiskIoSession(DiskIo diskIo, BinaryStreamIoSessionBase ioSession, FileHeaderBlock header, SubFileHeader file)
        {
            if (diskIo == null)
                throw new ArgumentNullException("diskIo");
            if (diskIo.IsDisposed)
                throw new ObjectDisposedException(diskIo.GetType().FullName);
            if (ioSession == null)
                throw new ArgumentNullException("ioSession");
            if (file == null)
                throw new ArgumentNullException("file");

            m_args = new BlockArguments();
            m_lastReadonlyBlock = diskIo.LastReadonlyBlock;
            m_diskMediumIoSession = ioSession;
            m_snapshotSequenceNumber = header.SnapshotSequenceNumber;
            m_fileIdNumber = file.FileIdNumber;
            m_isReadOnly = file.IsReadOnly | diskIo.IsReadOnly;
            m_blockSize = diskIo.BlockSize;
            m_diskIo = diskIo;
            IsValid = false;
            IsDisposed = false;
        }
コード例 #3
0
 protected override void Dispose(bool disposing)
 {
     if (!m_disposed)
     {
         try
         {
             // This will be done regardless of whether the object is finalized or disposed.
             if (m_mainIoSession != null)
             {
                 m_mainIoSession.Dispose();
             }
             if (m_secondaryIoSession != null)
             {
                 m_secondaryIoSession.Dispose();
             }
             if (!m_leaveOpen && m_stream != null)
             {
                 m_stream.Dispose();
             }
         }
         finally
         {
             FirstPosition        = 0;
             LastPosition         = 0;
             Current              = null;
             First                = null;
             LastRead             = null;
             LastWrite            = null;
             m_mainIoSession      = null;
             m_secondaryIoSession = null;
             m_stream             = null;
             m_disposed           = true;
         }
     }
     base.Dispose(disposing);
 }
コード例 #4
0
        /// <summary>
        /// Aquire an IO Session.
        /// </summary>
        BinaryStreamIoSessionBase ISupportsBinaryStream.CreateIoSession()
        {
            if (m_disposed)
                throw new ObjectDisposedException(GetType().FullName);
            if (RemainingSupportedIoSessions == 0)
                throw new Exception("There are not any remaining IO Sessions");

            m_ioStream1 = new SimplifiedSubFileStreamIoSession(m_stream, m_subFile, m_fileHeaderBlock);
            return m_ioStream1;
        }
コード例 #5
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     if (!m_disposed)
     {
         try
         {
             if (m_ioStream1 != null)
             {
                 m_ioStream1.Dispose();
                 m_ioStream1 = null;
             }
         }
         finally
         {
             m_disposed = true; // Prevent duplicate dispose.
         }
     }
 }
コード例 #6
0
 /// <summary>
 /// Releases all the resources used by the <see cref="DiskIoSession"/> object.
 /// </summary>
 public void Dispose()
 {
     if (!IsDisposed)
     {
         try
         {
             if (m_diskMediumIoSession != null)
             {
                 m_diskMediumIoSession.Dispose();
                 m_diskMediumIoSession = null;
             }
             m_diskIo = null;
         }
         finally
         {
             GC.SuppressFinalize(this);
             IsValid = false;
             IsDisposed = true; // Prevent duplicate dispose.
         }
     }
 }
コード例 #7
0
 /// <summary>
 /// Creates a <see cref="BinaryStream"/> that is at position 0 of the provided stream.
 /// </summary>
 /// <param name="stream">The base stream to use.</param>
 /// <param name="leaveOpen">Determines if the underlying stream will automatically be 
 /// disposed of when this class has it's dispose method called.</param>
 public BinaryStream(ISupportsBinaryStream stream, bool leaveOpen = true)
 {
     m_args = new BlockArguments();
     m_leaveOpen = leaveOpen;
     m_stream = stream;
     FirstPosition = 0;
     Current = null;
     First = null;
     LastRead = null;
     LastWrite = null;
     if (stream.RemainingSupportedIoSessions < 1)
         throw new Exception("Stream has run out of read sessions");
     m_mainIoSession = stream.CreateIoSession();
     //if (stream.RemainingSupportedIoSessions >= 1)
     //    m_secondaryIoSession = stream.CreateIoSession();
 }
コード例 #8
0
 protected override void Dispose(bool disposing)
 {
     if (!m_disposed)
     {
         try
         {
             // This will be done regardless of whether the object is finalized or disposed.
             if (m_mainIoSession != null)
                 m_mainIoSession.Dispose();
             if (m_secondaryIoSession != null)
                 m_secondaryIoSession.Dispose();
             if (!m_leaveOpen && m_stream != null)
                 m_stream.Dispose();
         }
         finally
         {
             FirstPosition = 0;
             LastPosition = 0;
             Current = null;
             First = null;
             LastRead = null;
             LastWrite = null;
             m_mainIoSession = null;
             m_secondaryIoSession = null;
             m_stream = null;
             m_disposed = true;
         }
     }
     base.Dispose(disposing);
 }
コード例 #9
0
        /// <summary>
        /// Aquire an IO Session.
        /// </summary>
        BinaryStreamIoSessionBase ISupportsBinaryStream.CreateIoSession()
        {
            if (m_disposed)
                throw new ObjectDisposedException(GetType().FullName);
            if (RemainingSupportedIoSessions == 0)
                throw new Exception("There are not any remaining IO Sessions");

            BinaryStreamIoSessionBase session;
            if (m_fileHeaderBlock.IsSimplifiedFileFormat)
            {
                session = new SimplifiedIoSession(this);
            }
            else
            {
                session = new IoSession(this);
            }
            if (m_ioStream1 == null || m_ioStream1.IsDisposed)
            {
                m_ioStream1 = session;
            }
            else
            {
                m_ioStream2 = session;
            }
            return session;
        }