Beispiel #1
0
        /// <summary>
        /// Creates an SimplifiedSubFileStream
        /// </summary>
        /// <param name="stream">The location to read from.</param>
        /// <param name="subFile">The file to read.</param>
        /// <param name="fileHeaderBlock">The FileAllocationTable</param>
        internal SimplifiedSubFileStream(FileStream stream, SubFileHeader subFile, FileHeaderBlock fileHeaderBlock)
        {
            if (stream is null)
            {
                throw new ArgumentNullException("stream");
            }
            if (subFile is null)
            {
                throw new ArgumentNullException("subFile");
            }
            if (fileHeaderBlock is null)
            {
                throw new ArgumentNullException("fileHeaderBlock");
            }
            if (subFile.DirectBlock == 0)
            {
                throw new Exception("Must assign subFile.DirectBlock");
            }

            if (fileHeaderBlock.IsReadOnly)
            {
                throw new ArgumentException("This parameter cannot be read only when opening for writing", "fileHeaderBlock");
            }
            if (subFile.IsReadOnly)
            {
                throw new ArgumentException("This parameter cannot be read only when opening for writing", "subFile");
            }

            m_blockSize       = fileHeaderBlock.BlockSize;
            m_stream          = stream;
            m_subFile         = subFile;
            m_fileHeaderBlock = fileHeaderBlock;
        }
Beispiel #2
0
        public SimplifiedSubFileStreamIoSession(FileStream stream, SubFileHeader subFile, FileHeaderBlock header)
        {
            if (stream is null)
            {
                throw new ArgumentNullException("stream");
            }
            if (subFile is null)
            {
                throw new ArgumentNullException("subFile");
            }
            if (header is null)
            {
                throw new ArgumentNullException("header");
            }
            if (subFile.DirectBlock == 0)
            {
                throw new Exception("Must assign subFile.DirectBlock");
            }

            m_stream               = stream;
            m_header               = header;
            m_blockSize            = header.BlockSize;
            m_subFile              = subFile;
            m_memory               = new Memory(m_blockSize);
            m_buffer               = new byte[m_blockSize];
            m_currentPhysicalBlock = -1;
            m_blockDataLength      = m_blockSize - FileStructureConstants.BlockFooterLength;
        }
 /// <summary>
 /// Creates a simplified file writer.
 /// </summary>
 /// <param name="pendingFileName"></param>
 /// <param name="completeFileName"></param>
 /// <param name="blockSize"></param>
 /// <param name="flags"></param>
 public SimplifiedFileWriter(string pendingFileName, string completeFileName, int blockSize, params Guid[] flags)
 {
     m_pendingFileName             = pendingFileName;
     m_completeFileName            = completeFileName;
     m_fileHeaderBlock             = FileHeaderBlock.CreateNewSimplified(blockSize, flags).CloneEditable();
     m_fileHeaderBlock.ArchiveType = SortedTreeFile.FileType;
     m_stream = new FileStream(pendingFileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
 }
Beispiel #4
0
 /// <summary>
 /// Creates a readonly copy of a transaction.
 /// </summary>
 /// <param name="dataReader"></param>
 internal ReadSnapshot(DiskIo dataReader)
 {
     if (dataReader is null)
     {
         throw new ArgumentNullException("dataReader");
     }
     m_fileHeaderBlock = dataReader.LastCommittedHeader;
     m_dataReader      = dataReader;
 }
        /// <summary>
        /// Creates an editable copy of the transaction
        /// </summary>
        /// <param name="dataReader"> </param>
        /// <param name="delHasBeenRolledBack">the delegate to call when this transaction has been rolled back</param>
        /// <param name="delHasBeenCommitted">the delegate to call when this transaction has been committed</param>
        internal TransactionalEdit(DiskIo dataReader, Action delHasBeenRolledBack = null, Action delHasBeenCommitted = null)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }

            m_openedFiles          = new List <SubFileStream>();
            m_disposed             = false;
            m_fileHeaderBlock      = dataReader.LastCommittedHeader.CloneEditable();
            m_dataReader           = dataReader;
            m_delHasBeenCommitted  = delHasBeenCommitted;
            m_delHasBeenRolledBack = delHasBeenRolledBack;
        }
 /// <summary>
 /// Creates this file with the following data.
 /// </summary>
 /// <param name="diskIo"></param>
 /// <param name="header"></param>
 /// <param name="file"></param>
 /// <param name="isReadOnly"></param>
 public SubFileDiskIoSessionPool(DiskIo diskIo, FileHeaderBlock header, SubFileHeader file, bool isReadOnly)
 {
     LastReadonlyBlock = diskIo.LastCommittedHeader.LastAllocatedBlock;
     File        = file;
     Header      = header;
     IsReadOnly  = isReadOnly;
     SourceData  = diskIo.CreateDiskIoSession(header, file);
     SourceIndex = diskIo.CreateDiskIoSession(header, file);
     if (!isReadOnly)
     {
         DestinationData  = diskIo.CreateDiskIoSession(header, file);
         DestinationIndex = diskIo.CreateDiskIoSession(header, file);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Creates an SubFileStream
        /// </summary>
        /// <param name="dataReader">The location to read from.</param>
        /// <param name="subFile">The file to read.</param>
        /// <param name="fileHeaderBlock">The FileAllocationTable</param>
        /// <param name="isReadOnly">Determines if the stream allows editing.</param>
        internal SubFileStream(DiskIo dataReader, SubFileHeader subFile, FileHeaderBlock fileHeaderBlock, bool isReadOnly)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (subFile == null)
            {
                throw new ArgumentNullException("subFile");
            }
            if (fileHeaderBlock == null)
            {
                throw new ArgumentNullException("subFile");
            }

            if (!isReadOnly)
            {
                if (dataReader.IsReadOnly)
                {
                    throw new ArgumentException("This parameter cannot be read only when opening for writing", "dataReader");
                }
                if (fileHeaderBlock.IsReadOnly)
                {
                    throw new ArgumentException("This parameter cannot be read only when opening for writing", "fileHeaderBlock");
                }
                if (subFile.IsReadOnly)
                {
                    throw new ArgumentException("This parameter cannot be read only when opening for writing", "subFile");
                }
            }
            if (isReadOnly)
            {
                if (!fileHeaderBlock.IsReadOnly)
                {
                    throw new ArgumentException("This parameter must be read only when opening for reading", "fileHeaderBlock");
                }
                if (!subFile.IsReadOnly)
                {
                    throw new ArgumentException("This parameter must be read only when opening for reading", "subFile");
                }
            }

            m_blockSize       = dataReader.BlockSize;
            m_dataReader      = dataReader;
            m_subFile         = subFile;
            m_fileHeaderBlock = fileHeaderBlock;
            m_isReadOnly      = isReadOnly;
        }
 /// <summary>
 /// Creates a <see cref="ShadowCopyAllocator"/> that is used make shadow copies of blocks.
 /// </summary>
 /// <param name="ioSessions"></param>
 public ShadowCopyAllocator(SubFileDiskIoSessionPool ioSessions)
     : base(ioSessions)
 {
     if (ioSessions == null)
     {
         throw new ArgumentNullException("ioSessions");
     }
     if (ioSessions.IsReadOnly)
     {
         throw new ArgumentException("DataReader is read only", "ioSessions");
     }
     m_lastReadOnlyBlock = ioSessions.LastReadonlyBlock;
     m_fileHeaderBlock   = ioSessions.Header;
     m_subFileHeader     = ioSessions.File;
     m_ioSessions        = ioSessions;
 }