Пример #1
0
        public BlockFile LoadBlock(int X, int Y)
        {
            string    FileName = Path.Combine(FileDirectory, FileBaseName + "_" + (Y * BlockWidth + X) + ".mdata");
            BlockFile Block;

            using (Stream FileStream = File.Open(FileName, FileMode.Open))
            {
                NetworkReader r = new NetworkReader(FileStream);
                Block = new BlockFile();
                Block.Read(r);
            }
            return(Block);
        }
Пример #2
0
        public void BlockFile_ReadWrite_Reverse()
        {
            BlockFile bf;
            string    path;

            byte[] buf  = new byte[cbBlock];
            byte[] test = new byte[cbBlock];

            path = Path.GetTempPath() + Helper.NewGuid().ToString() + ".blocks";
            bf   = new BlockFile(path, cbBlock, 0, FileMode.Create);

            try
            {
                // Write blocks backwards read them back stepping backwards
                // as well.

                for (int i = cBlocks - 1; i >= 0; i--)
                {
                    for (int j = 0; j < cbBlock; j++)
                    {
                        buf[j] = (byte)(j + i + 7);
                    }

                    bf.Write(i, buf, cbBlock);
                }

                for (int i = cBlocks - 1; i >= 0; i--)
                {
                    for (int j = 0; j < cbBlock; j++)
                    {
                        test[j] = (byte)(j + i + 7);
                    }

                    bf.Read(i, buf, cbBlock);
                    CollectionAssert.AreEqual(test, buf);
                }
            }
            finally
            {
                if (bf != null)
                {
                    bf.Close();
                }

                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
Пример #3
0
        public void BlockFile_Preallocate()
        {
            BlockFile bf;
            string    path;

            byte[] buf  = new byte[cbBlock];
            byte[] test = new byte[cbBlock];

            path = Path.GetTempPath() + Helper.NewGuid().ToString() + ".blocks";
            bf   = new BlockFile(path, cbBlock, cBlocks, FileMode.Create);

            try
            {
                // Write blocks forward from block 0 on and then
                // read them back stepping forward as well.

                for (int i = 0; i < cBlocks; i++)
                {
                    for (int j = 0; j < cbBlock; j++)
                    {
                        buf[j] = (byte)(j + i);
                    }

                    bf.Write(i, buf, cbBlock);
                }

                for (int i = 0; i < cBlocks; i++)
                {
                    for (int j = 0; j < cbBlock; j++)
                    {
                        test[j] = (byte)(j + i);
                    }

                    bf.Read(i, buf, cbBlock);
                    CollectionAssert.AreEqual(test, buf);
                }
            }
            finally
            {
                if (bf != null)
                {
                    bf.Close();
                }

                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }