示例#1
0
        /// <summary>
        /// Will return a list of all pages in the block
        /// </summary>
        /// <returns></returns>
        public List <TPSPage> getPages()
        {
            RandomAccess   ra    = RandomAccess.GetInstance();
            List <TPSPage> pages = new List <TPSPage>();

            ra.jumpAbs(_start);             //jump to the start of the block

            try{
                while (ra.position < _end)                    //while we have not fallen off the end of the file

                {
                    TPSPage page = new TPSPage();
                    page.Process();
                    pages.Add(page);

                    //pages always start on the position % 100 = 0
                    //So let's jump forward to find the next start
                    if ((ra.position & 0xFF) != 0x00)
                    {
                        ra.jumpAbs((ra.position & 0xFFFFFF00L) + 0x0100);
                    }

                    //we can find the next page because the address of the page will be in the data
                    int addr = 0;
                    if (!ra.isAtEnd())
                    {
                        do
                        {
                            addr = ra.leLong();
                            ra.jumpRelative(-4);                             //backup 4 bytes

                            if (addr != ra.position)
                            {
                                ra.jumpRelative(0x0100);
                            }
                        }while ((addr != ra.position) && !ra.isAtEnd());
                    }
                }
            }catch (Exception ex) {
                ;
            }

            return(pages);
        }
示例#2
0
        /// <summary>
        /// Will read the next TPSRecord.
        /// True or false depending if there is another one in the queue
        /// </summary>
        /// <returns></returns>
        public bool Read()
        {
            //if there is anything on our temporary stack, just send the first one back to the user and remove it from thelist
            if (_returnDataStack.Count > 0)
            {
                _currentRow = _returnDataStack[0];
                _returnDataStack.RemoveAt(0);
                return(true);
            }


            //read page after page until either there are no more pages or we have something on our stack to return

            while (_tpsPages.Count > 0 && _returnDataStack.Count < 1)
            {
                TPSPage page = _tpsPages[0];
                _tpsPages.RemoveAt(0);                 //pop the page off the stack

                List <TPSRecord> pageRecords = page.GetRecords();
                foreach (TPSRecord record in pageRecords)
                {
                    //go through each record to see if we need it
                    if (record.RecordType == TPSRecord.TYPE_DATA)
                    {
                        //Check if this record belongs to a table that we are searchin for
                        //Notice that we need to generate the table ID before we can check
                        //This part is normally in the TableDataRecord file, but we want to know before
                        //parsing the whole record in the name of efficiency
                        byte[] recordTableIDBA = new byte[4];
                        if (record.RecordData.Length < 4)
                        {
                            continue;
                        }

                        //Get the tableID ( it is backwards )
                        recordTableIDBA[0] = record.RecordData[3];
                        recordTableIDBA[1] = record.RecordData[2];
                        recordTableIDBA[2] = record.RecordData[1];
                        recordTableIDBA[3] = record.RecordData[0];
                        int recordTableID = BitConverter.ToInt32(recordTableIDBA, 0);

                        if (_schema.TableID == recordTableID)
                        {
                            //Generate the record
                            Record.TableDataRecord      tdr    = new Record.TableDataRecord(record, _schema);
                            Dictionary <string, string> newRow = new Dictionary <string, string>();
                            for (int i = 0; i < tdr.TableDataRow.Table.Columns.Count; i++)
                            {
                                newRow.Add(tdr.TableDataRow.Table.Columns[i].ColumnName, tdr.TableDataRow[tdr.TableDataRow.Table.Columns[i].ColumnName].ToString());
                            }

                            _returnDataStack.Add(newRow);
                        }
                    }
                }
            }

            //Now send back a record. If not, we're out and send false
            if (_returnDataStack.Count > 0)
            {
                _currentRow = _returnDataStack[0];
                _returnDataStack.RemoveAt(0);
                return(true);
            }
            else
            {
                return(false);
            }

            return(false);
        }