示例#1
0
        /// <summary>
        /// Navigates to a block that will be only read and not modified.
        /// </summary>
        /// <param name="blockIndex"></param>
        /// <param name="blockType">the type of this block.</param>
        /// <param name="indexValue">a value put in the footer of the block designating the index of this block</param>
        /// <returns></returns>
        public void ReadOld(uint blockIndex, BlockType blockType, uint indexValue)
        {
            BlockIndex = blockIndex;
            BlockType  = (byte)blockType;
            IndexValue = indexValue;

            ReadCount++;
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (m_diskIo.IsDisposed)
            {
                throw new ObjectDisposedException(typeof(DiskIo).FullName);
            }

            IsValid = true;

            ReadBlock(false);

            IoReadState readState = IsFooterValidFromOldBlock();

            if (readState != IoReadState.Valid)
            {
                IsValid = false;
                throw new Exception("Read Error: " + readState.ToString());
            }
        }
示例#2
0
        /// <summary>
        /// Navigates to a block that will be written to.
        /// This block must currently exist and have the correct parameters passed to this function
        /// In order to allow this block to be modified.
        /// </summary>
        /// <param name="blockIndex">the index value of this block</param>
        /// <param name="blockType">the type of this block.</param>
        /// <param name="indexValue">a value put in the footer of the block designating the index of this block</param>
        /// <returns></returns>
        public void WriteToExistingBlock(uint blockIndex, BlockType blockType, uint indexValue)
        {
            BlockIndex = blockIndex;
            BlockType  = (byte)blockType;
            IndexValue = indexValue;

            WriteCount++;
            ReadCount++;
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (m_diskIo.IsDisposed)
            {
                throw new ObjectDisposedException(typeof(DiskIo).FullName);
            }
            if (m_isReadOnly)
            {
                throw new ReadOnlyException("The subfile used for this io session is read only.");
            }
            if ((blockIndex > 10 && blockIndex <= m_lastReadonlyBlock))
            {
                throw new ArgumentOutOfRangeException("blockIndex", "Cannot write to committed blocks");
            }

            IsValid = true;

            ReadBlock(true);

            IoReadState readState = IsFooterCurrentSnapshotAndValid();

            if (readState != IoReadState.Valid)
            {
                IsValid = false;
                throw new Exception("Read Error: " + readState.ToString());
            }
        }