This class is responsible for managing the transactions that occur on the file system. Therefore, it keeps up with the latest snapshot of the file allocation table, permits only a single concurrent edit of the archive system, and determines when a file can be deleted when there are no read or write transactions. It also containst the IO system.
상속: IDisposable
예제 #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();
                        }
                    }
            }
        }
예제 #2
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();
                                }
                            }
                        }
                }
            }
        }