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); } }
private int WriteTopPage(FileStreamWrapper stream, int lastPageAddress) { // update the header ListHdr header = this.pageHeaderList.Pop(); header.NextPageIndex = lastPageAddress; // update the page StoragePage page = this.pageList.Pop(); page.WriteRecord(ListHdr.HeaderRecordIdx, header); // get the page to write to int pageIdx = header.PageWriteIndex; // write the page pageIdx = page.WritePageData(stream, pageIdx); this.pageIdxList.Insert(0, pageIdx); return(pageIdx); }