Example #1
0
        /// <summary>
        /// Releases all the resources used by the <see cref="TransactionalFileStructure"/> object.
        /// </summary>
        public void Dispose()
        {
            if (!m_disposed)
            {
                try
                {
                    if (m_currentTransaction != null)
                    {
                        m_currentTransaction.Dispose();
                        m_currentTransaction = null;
                    }

                    if (m_diskIo != null)
                    {
                        m_diskIo.Dispose();
                        m_diskIo = null;
                    }
                }
                finally
                {
                    GC.SuppressFinalize(this);
                    m_disposed = true; // Prevent duplicate dispose.
                }
            }
        }
        public void Test()
        {
            Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);

            DiskIo stream = DiskIo.CreateMemoryFile(Globals.MemoryPool, BlockSize);

            TestReadAndWrites(stream);

            TestReadAndWritesWithCommit(stream);
            TestReadAndWritesToDifferentFilesWithCommit(stream);
            TestBinaryStream(stream);
            stream.Dispose();
            Assert.IsTrue(true);
            Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
        }
Example #3
0
        public void Test()
        {
            Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
            DiskIo          stream = DiskIo.CreateMemoryFile(Globals.MemoryPool, BlockSize);
            FileHeaderBlock fat    = stream.LastCommittedHeader;

            //obtain a readonly copy of the file allocation table.
            fat = stream.LastCommittedHeader;
            TestCreateNewFile(stream, fat);
            fat = stream.LastCommittedHeader;
            TestOpenExistingFile(stream, fat);
            fat = stream.LastCommittedHeader;
            TestRollback(stream, fat);
            fat = stream.LastCommittedHeader;
            TestVerifyRollback(stream, fat);
            Assert.IsTrue(true);
            stream.Dispose();
            Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
        }
Example #4
0
        /// <summary>
        /// Opens an existing file.
        /// </summary>
        public static TransactionalFileStructure OpenFile(string fileName, bool isReadOnly)
        {
            if (fileName is null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (!File.Exists(fileName))
            {
                throw new Exception("fileName Does Not Exists");
            }

            DiskIo disk = DiskIo.OpenFile(fileName, Globals.MemoryPool, isReadOnly);

            if (!isReadOnly && disk.LastCommittedHeader.IsSimplifiedFileFormat)
            {
                disk.Dispose();
                throw new Exception("Cannot open a simplified file structure with write support.");
            }
            return(new TransactionalFileStructure(disk));
        }