예제 #1
0
        private BasePage ReadPageJournal(uint index, BinaryReader reader)
        {
            // Position cursor
            reader.Seek(index * BasePage.PAGE_SIZE);

            // Create page instance and read from disk (read page header + content page)
            var page = new BasePage();

            // target = it's the target position after reader header. It's used when header does not conaints all PAGE_HEADER_SIZE
            var target = reader.BaseStream.Position + BasePage.PAGE_HEADER_SIZE;

            // read page header
            page.ReadHeader(reader);

            // Convert BasePage to correct Page Type
            if (page.PageType == PageType.Header)
            {
                page = page.CopyTo <HeaderPage>();
            }
            else if (page.PageType == PageType.Collection)
            {
                page = page.CopyTo <CollectionPage>();
            }
            else if (page.PageType == PageType.Index)
            {
                page = page.CopyTo <IndexPage>();
            }
            else if (page.PageType == PageType.Data)
            {
                page = page.CopyTo <DataPage>();
            }
            else if (page.PageType == PageType.Extend)
            {
                page = page.CopyTo <ExtendPage>();
            }

            // read page content if page is not empty
            if (page.PageType != PageType.Empty)
            {
                // position reader to the end of page header
                reader.BaseStream.Seek(target - reader.BaseStream.Position, SeekOrigin.Current);

                // read page content
                page.ReadContent(reader);
            }

            return(page);
        }
예제 #2
0
        private BasePage ReadPageJournal(BinaryReader reader)
        {
            var stream   = reader.BaseStream;
            var posStart = stream.Position * BasePage.PAGE_SIZE;
            var posEnd   = posStart + BasePage.PAGE_SIZE;

            // Create page instance and read from disk (read page header + content page)
            var page = new BasePage();

            // read page header
            page.ReadHeader(reader);

            // Convert BasePage to correct Page Type
            if (page.PageType == PageType.Header)
            {
                page = page.CopyTo <HeaderPage>();
            }
            else if (page.PageType == PageType.Collection)
            {
                page = page.CopyTo <CollectionPage>();
            }
            else if (page.PageType == PageType.Index)
            {
                page = page.CopyTo <IndexPage>();
            }
            else if (page.PageType == PageType.Data)
            {
                page = page.CopyTo <DataPage>();
            }
            else if (page.PageType == PageType.Extend)
            {
                page = page.CopyTo <ExtendPage>();
            }

            // read page content if page is not empty
            if (page.PageType != PageType.Empty)
            {
                // read page content
                page.ReadContent(reader);
            }

            // read non-used bytes on page and position cursor to next page
            reader.ReadBytes((int)(posEnd - stream.Position));

            return(page);
        }