Exemple #1
0
        /// <summary>
        /// Reads a record using the previous data available.
        /// TPS uses a stupid ( prossesing costly ) method to save space. It copies data from the last record if possible
        /// </summary>
        /// <param name="previous"></param>
        /// <param name="pageDataRandomAccess"></param>
        public TPSRecord(ref TPSRecord previous, ref RandomAccess pageDataRandomAccess)
        {
            //the flag tells us what data we should be copying
            _flags = pageDataRandomAccess.leByte();
            if ((_flags & 0x80) != 0)
            {
                _recordLength = pageDataRandomAccess.leShort();
            }
            else
            {
                _recordLength = previous.RecordLength;
            }
            if ((_flags & 0x40) != 0)
            {
                _headerLength = pageDataRandomAccess.leShort();
            }
            else
            {
                _headerLength = previous.HeaderLength;
            }

            //The last part tells us how much actual record data we should copy
            int copy = _flags & 0x3F;

            _data = new byte[_recordLength];
            try {
                Buffer.BlockCopy(previous.RecordData, 0, _data, 0, copy);
                Buffer.BlockCopy(pageDataRandomAccess.leBytes(_recordLength - copy), 0, _data, copy, (_recordLength - copy));
                //We may have to check if we pulled enough bytes from the pageDataRA, incase we hit the end prematurely
            } catch (Exception ex) {
                throw new Exception("When reading " + (_recordLength - copy) + " bytes of TpsRecord");
            }
            //
            buildHeader();
        }
Exemple #2
0
        /// <summary>
        /// Returns all records of the page
        /// <returns></returns>
        public List <TPSRecord> GetRecords()
        {
            List <TPSRecord> records = new List <TPSRecord>();

            byte[] pageData = GetData();
            //go through each record in the page
            RandomAccess ra = new RandomAccess();

            ra.OpenStream(new MemoryStream(pageData));

            records.Clear();
            // Skip pages with non 0x00 flags as they don't seem to contain TpsRecords.
            if (flags == 0x00)
            {
                //data.pushPosition();
                try {
                    TPSRecord prev = null;
                    do
                    {
                        TPSRecord current = null;
                        if (prev == null)
                        {
                            current = new TPSRecord(ref ra);
                        }
                        else
                        {
                            current = new TPSRecord(ref prev, ref ra);
                        }

                        records.Add(current);
                        prev = current;
                    } while (!ra.isAtEnd() && records.Count < recordCount);
                } finally {
                    //data.popPosition();
                }
            }

            return(records);
        }