Assists in the writing of a simplified file. This file can only be appended to and it must be sequentially written.
Inheritance: IDisposable
Ejemplo n.º 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();
                        }
                    }
            }
        }
Ejemplo n.º 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();
                                }
                            }
                        }
                }
            }
        }