Provides a file stream that can be used to open a file and does all of the background work required to translate virtual position data into physical ones.
Inheritance: ISupportsBinaryStream
示例#1
0
        public void Test1()
        {
            File.Delete(@"C:\Temp\fileTemp.~d2i");
            File.Delete(@"C:\Temp\fileTemp.d2i");
            using (SimplifiedFileWriter writer = new SimplifiedFileWriter(@"C:\Temp\fileTemp.~d2i", @"C:\Temp\fileTemp.d2i", 4096, FileFlags.ManualRollover))
            {
                using (ISupportsBinaryStream file = writer.CreateFile(SubFileName.CreateRandom()))
                    using (BinaryStream bs = new BinaryStream(file))
                    {
                        bs.Write(1);
                    }

                writer.Commit();
            }


            using (TransactionalFileStructure reader = TransactionalFileStructure.OpenFile(@"C:\Temp\fileTemp.d2i", true))
            {
                using (SubFileStream file = reader.Snapshot.OpenFile(0))
                    using (BinaryStream bs = new BinaryStream(file))
                    {
                        if (bs.ReadInt32() != 1)
                        {
                            throw new Exception();
                        }
                    }
            }
        }
        /// <summary>
        /// Opens a ArchiveFileStream that can be used to read/write to the file passed to this function.
        /// </summary>
        /// <param name="fileIndex">The index of the file to open.</param>
        /// <returns></returns>
        public SubFileStream OpenFile(int fileIndex)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (fileIndex < 0 || fileIndex >= m_fileHeaderBlock.Files.Count)
            {
                throw new ArgumentOutOfRangeException("fileIndex", "The file index provided could not be found in the header.");
            }
            SubFileHeader subFile    = m_fileHeaderBlock.Files[fileIndex];
            SubFileStream fileStream = new SubFileStream(m_dataReader, subFile, m_fileHeaderBlock, isReadOnly: false);

            m_openedFiles.Add(fileStream);
            return(fileStream);
        }
示例#3
0
        public void TestMultipleFiles()
        {
            Random r = new Random(1);

            File.Delete(@"C:\Temp\fileTemp.~d2i");
            File.Delete(@"C:\Temp\fileTemp.d2i");
            using (SimplifiedFileWriter writer = new SimplifiedFileWriter(@"C:\Temp\fileTemp.~d2i", @"C:\Temp\fileTemp.d2i", 4096, FileFlags.ManualRollover))
            {
                for (int i = 0; i < 10; i++)
                {
                    using (ISupportsBinaryStream file = writer.CreateFile(SubFileName.CreateRandom()))
                        using (BinaryStream bs = new BinaryStream(file))
                        {
                            bs.Write((byte)1);
                            for (int x = 0; x < 100000; x++)
                            {
                                bs.Write(r.NextDouble());
                            }
                        }
                }
                writer.Commit();
            }

            r = new Random(1);
            using (TransactionalFileStructure reader = TransactionalFileStructure.OpenFile(@"C:\Temp\fileTemp.d2i", true))
            {
                for (int i = 0; i < 10; i++)
                {
                    using (SubFileStream file = reader.Snapshot.OpenFile(i))
                        using (BinaryStream bs = new BinaryStream(file))
                        {
                            if (bs.ReadUInt8() != 1)
                            {
                                throw new Exception();
                            }

                            for (int x = 0; x < 100000; x++)
                            {
                                if (bs.ReadDouble() != r.NextDouble())
                                {
                                    throw new Exception();
                                }
                            }
                        }
                }
            }
        }
            public IoSession(SubFileStream stream)
            {
                m_stream          = stream;
                m_lastEditedBlock = stream.m_dataReader.LastCommittedHeader.LastAllocatedBlock;
                m_isReadOnly      = stream.m_isReadOnly;
                m_blockDataLength = m_stream.m_blockSize - FileStructureConstants.BlockFooterLength;
                m_ioSessions      = new SubFileDiskIoSessionPool(stream.m_dataReader, stream.m_fileHeaderBlock, stream.m_subFile, stream.m_isReadOnly);

                if (m_isReadOnly)
                {
                    m_parser = new IndexParser(m_ioSessions);
                }
                else
                {
                    m_pager  = new ShadowCopyAllocator(m_ioSessions);
                    m_parser = m_pager;
                }
            }
            public IoSession(SubFileStream stream)
            {
                m_stream = stream;
                m_lastEditedBlock = stream.m_dataReader.LastCommittedHeader.LastAllocatedBlock;
                m_isReadOnly = stream.m_isReadOnly;
                m_blockDataLength = m_stream.m_blockSize - FileStructureConstants.BlockFooterLength;
                m_ioSessions = new SubFileDiskIoSessionPool(stream.m_dataReader, stream.m_fileHeaderBlock, stream.m_subFile, stream.m_isReadOnly);

                if (m_isReadOnly)
                {
                    m_parser = new IndexParser(m_ioSessions);
                }
                else
                {
                    m_pager = new ShadowCopyAllocator(m_ioSessions);
                    m_parser = m_pager;
                }
            }
 public SimplifiedIoSession(SubFileStream stream)
 {
     m_stream = stream;
     m_dataIoSession = stream.m_dataReader.CreateDiskIoSession(stream.m_fileHeaderBlock, stream.m_subFile);
     m_blockDataLength = m_stream.m_blockSize - FileStructureConstants.BlockFooterLength;
 }
 public SimplifiedIoSession(SubFileStream stream)
 {
     m_stream          = stream;
     m_dataIoSession   = stream.m_dataReader.CreateDiskIoSession(stream.m_fileHeaderBlock, stream.m_subFile);
     m_blockDataLength = m_stream.m_blockSize - FileStructureConstants.BlockFooterLength;
 }