Exemplo n.º 1
0
 public static void WriteToFile(DataUnit dataPage, BinaryWriter writer)
 {
     long initPos = writer.Seek(100L + (dataPage.UnitID * 0x1000L));
     writer.Write((byte) dataPage.Type);
     writer.Write(dataPage.NextUnitID);
     writer.Write(dataPage.IsEmpty);
     writer.Write(dataPage.DataBlockLength);
     if (!dataPage.IsEmpty)
     {
         writer.Seek(initPos + 8L);
         writer.Write(dataPage.DataBlock, 0, dataPage.DataBlockLength);
     }
 }
Exemplo n.º 2
0
 public static void ReadFromFile(DataUnit dataPage, BinaryReader reader, bool onlyHeader)
 {
     long initPos = reader.Seek(100L + (dataPage.UnitID * 0x1000L));
     if (reader.ReadByte() != 1)
     {
         throw new FileDBException("PageID {0} is not a Data Page", new object[] { dataPage.UnitID });
     }
     dataPage.NextUnitID = reader.ReadUInt32();
     dataPage.IsEmpty = reader.ReadBoolean();
     dataPage.DataBlockLength = reader.ReadInt16();
     if (!dataPage.IsEmpty && !onlyHeader)
     {
         reader.Seek(initPos + 8L);
         dataPage.DataBlock = reader.ReadBytes(dataPage.DataBlockLength);
     }
 }
Exemplo n.º 3
0
 public static DataUnit GetNewDataPage(DataUnit basePage, Engine engine)
 {
     if (basePage.NextUnitID != uint.MaxValue)
     {
         UnitFactory.WriteToFile(basePage, engine.Writer);
         DataUnit dataPage = UnitFactory.GetDataPage(basePage.NextUnitID, engine.Reader, false);
         engine.Header.FreeDataPageID = dataPage.NextUnitID;
         if (engine.Header.FreeDataPageID == uint.MaxValue)
         {
             engine.Header.LastFreeDataPageID = uint.MaxValue;
         }
         return dataPage;
     }
     Header header = engine.Header;
     uint pageID = ++header.LastPageID;
     DataUnit newPage = new DataUnit(pageID);
     basePage.NextUnitID = newPage.UnitID;
     UnitFactory.WriteToFile(basePage, engine.Writer);
     return newPage;
 }
Exemplo n.º 4
0
 public static DataUnit GetDataPage(uint pageID, BinaryReader reader, bool onlyHeader)
 {
     DataUnit dataPage = new DataUnit(pageID);
     ReadFromFile(dataPage, reader, onlyHeader);
     return dataPage;
 }