internal PageEventArgs(UInt64 pageNumber, PageHeader pageHeader)
 {
     this.PageNumber = pageNumber;
     this.PageHeader = pageHeader;
 }
示例#2
0
        public void ParsePage(UInt64 pageNumber)
        {
            this._pageReader.LoadPage(pageNumber);

            if (1 == pageNumber)
            {
                this._pageReader.Position = 100;
            }

            var pageType = (PageType)this._pageReader.Read8();

            if (PageType.Unused == pageType)
            {
                return;
            }

            var pageHeader = new PageHeader();

            pageHeader.PageType                 = pageType;
            pageHeader.FirstFreeblockOffset     = this._pageReader.Read16();
            pageHeader.CellCount                = this._pageReader.Read16();
            pageHeader.CellContentAreaOffset    = this._pageReader.Read16();
            pageHeader.FragmentedFreeBytesCount = this._pageReader.Read8();

            if ((PageType.IndexInterior == pageType) || (PageType.TableInterior == pageType))
            {
                pageHeader.RightMostPointer = this._pageReader.Read32();
            }

            var pageEventArgs = new PageEventArgs(pageNumber, pageHeader);

            this.PageStarted?.Invoke(this, pageEventArgs);

            var cellPointerArrayOffset = this._pageReader.Position;

            for (var cellNumber = 0UL; cellNumber < pageHeader.CellCount; cellNumber++)
            {
                var cellHeader = new CellHeader();
                cellHeader.PageType = pageType;

                this._pageReader.Position = cellPointerArrayOffset;
                cellPointerArrayOffset   += 2;

                var cellOffset = this._pageReader.Read16();

                this._pageReader.Position = cellOffset;

                if (PageType.IndexInterior == pageType)
                {
                    cellHeader.LeftChildPage = this._pageReader.Read32();
                    cellHeader.PayloadSize   = this._pageReader.Decode64();
                }
                else if (PageType.TableInterior == pageType)
                {
                    cellHeader.LeftChildPage = this._pageReader.Read32();
                    cellHeader.Rowid         = this._pageReader.Decode64();
                }
                else if (PageType.IndexLeaf == pageType)
                {
                    cellHeader.PayloadSize = this._pageReader.Decode64();
                }
                else if (PageType.TableLeaf == pageType)
                {
                    cellHeader.PayloadSize = this._pageReader.Decode64();
                    cellHeader.Rowid       = this._pageReader.Decode64();
                }
                else
                {
                    // TODO
                }

                this.CellStarted?.Invoke(this, new CellEventArgs(cellNumber, cellHeader));

                if ((PageType.IndexInterior == pageType) || (PageType.IndexLeaf == pageType) || (PageType.TableLeaf == pageType))
                {
                    this.ParsePayload(pageNumber, cellNumber, cellHeader);
                }

                this.CellFinished?.Invoke(this, new CellEventArgs(cellNumber, cellHeader));
            }

            this.PageFinished?.Invoke(this, pageEventArgs);
        }