Ejemplo n.º 1
0
        private void TestAllocate()
        {
            try
            {
                _logger.Message("Testing Allocate");
                int address;
                Manager.CreateFile(SampleFile, 4, false);                 //Without bitmap
                Manager.CreateFile(SampleFile_BM, 4, true);               //With bitmap
                Stream fs   = new FileStream(SampleFile, FileMode.OpenOrCreate);
                Stream fsbm = new FileStream(SampleFile_BM, FileMode.OpenOrCreate);

                //Tests for Allocate
                Assert.AreEqual(Manager.Allocate(SampleFile, fs), Manager.GetEndOfFile(fs));
                Assert.AreEqual(Manager.Allocate(SampleFile_BM, fsbm), Manager.GetEndOfFile(fsbm));
                using (FileStream fsBitMap = new FileStream(SampleFile_BM + " - BitMap", FileMode.Open))
                {
                    Manager.Write(fsBitMap, Manager.HeaderSize, Converter.IntToBytes(16));
                }
                Assert.AreEqual(Manager.Allocate(SampleFile_BM, fsbm), 16);
                using (FileStream fsBitMap = new FileStream(SampleFile_BM + " - BitMap", FileMode.Open))
                {
                    Assert.AreEqual(Manager.GetEndOfFile(fsBitMap), Manager.HeaderSize);
                }

                for (int i = 0; i < 5; i++)
                {
                    address = Manager.Allocate(SampleFile_BM, fsbm);
                    Assert.AreEqual(Manager.GetEndOfFile(fsbm), address);
                    Manager.Write(fsbm, address, Converter.IntToBytes(100 + i));
                }

                fs.Close();
                fsbm.Close();
            }

            catch (Exception e)
            {
                _logger.Error(e.Message);
            }

            finally
            {
                Manager.DropFile(SampleFile);
                Manager.DropFile(SampleFile_BM);
                Manager.DropFile(SampleFile_BM + " - BitMap");
            }
        }
Ejemplo n.º 2
0
        /**
         * Inserts a record into the table
         * Those fields should be null which have not been set
         * @returns Address where it is inserted
         */

        public int InsertRecord(Record record)
        {
            //Inserting entry into record file
            String recordsPath = GetFilePath.TableRecords(table.DbName, table.Name);
            Stream fs          = new FileStream(recordsPath, FileMode.OpenOrCreate);
            int    address     = storageManager.Allocate(recordsPath, fs);

            char[] recordStream = table.RecordToCharArray(record);
            storageManager.Write(fs, address, Converter.CharToBytes(recordStream));
            fs.Close();

            return(address);
        }