// reads a page from persistent storage private void aReadPageData(StoragePage page, int pageIndex) { lock (ManagerLock) { page.ReadPageData(this.dataFile, pageIndex); } }
private DBHdr ReadDBRoot() { DBHdr dbRoot = null; try { StoragePage rootPage = new StoragePage(); rootPage.ReadPageData(this.dataFile, RootPage); dbRoot = (DBHdr)rootPage.ReadRecord(0); } catch (Exception) { dbRoot = null; } return(dbRoot); }
public void SP_TestReadWritePage() { string dataFile = "SP_TestData1.tpdb"; if (File.Exists(dataFile)) { File.Delete(dataFile); } TestData[] pageData = { new TestData{data = "Record_0", recordIdx = 0}, new TestData{data = "Record_1", recordIdx = 1}, new TestData{data = "Record_2", recordIdx = 2} }; int pageIndex = int.MinValue; // write the page using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile)) { // populate the page with some data StoragePage page = new StoragePage(); AddRecords(page, pageData); // write the file to disk pageIndex = page.WritePageData(dataFileStream, -1); } // read the page using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile)) { // read page from file StoragePage page = new StoragePage(); page.ReadPageData(dataFileStream, pageIndex); // validate the page data ReadRecords(page, pageData); } }