Пример #1
0
        public BTHDataEntry(HNDataDTO data, int offset, BTH tree)
        {
            this.Key = data.Data.RangeSubset(offset, (int)tree.Header.KeySize);
            //this.Key = bytes.Skip(offset).Take((int)tree.Header.KeySize).ToArray();
            var temp = offset + (int)tree.Header.KeySize;

            this.Data       = data.Data.RangeSubset(temp, (int)tree.Header.DataSize);
            this.DataOffset = (ulong)offset + tree.Header.KeySize;
            this.ParentTree = tree;
        }
Пример #2
0
        public ExchangeProperty(BTHDataEntry entry, BTH heap)
        {
            //this.entry = entry;

            _key = entry.Data.RangeSubset(2, entry.Data.Length - 2);
            ID   = (MessageProperty)BitConverter.ToUInt16(entry.Key, 0);
            Type = (PropType)BitConverter.ToUInt16(entry.Data, 0);

            GetData(heap);
        }
Пример #3
0
        public TCRowMatrixData(byte[] bytes, TableContext context, BTH heap, int offset = 0)
        {
            ColumnXREF = new Dictionary <MessageProperty, byte[]>();
            _heap      = heap;

            //todo: cell existence test
            //var rowSize = context.TCHeader.EndOffsetCEB;
            foreach (var col in context.TCHeader.ColumnsDescriptors)
            {
                ColumnXREF.Add((MessageProperty)col.Tag, bytes.RangeSubset(offset + col.DataOffset, col.DataSize));
            }
        }
Пример #4
0
        public BTHDataNode(HID hid, BTH tree)
        {
            this.Tree = tree;

            var bytes = tree.GetHIDBytes(hid);

            this._data       = bytes;
            this.DataEntries = new List <BTHDataEntry>();
            for (int i = 0; i < bytes.Data.Length; i += (int)(tree.Header.KeySize + tree.Header.DataSize))
            {
                this.DataEntries.Add(new BTHDataEntry(bytes, i, tree));
            }
        }
Пример #5
0
        public ExchangeProperty(UInt16 ID, UInt16 type, BTH heap, byte[] key)
        {
            this.ID   = (MessageProperty)ID;
            this.Type = (PropType)type;

            /*var tempKey = new byte[key.Length + 2];
             * tempKey[0] = 0x00;
             * tempKey[1] = 0x00;
             * for (int i = 0; i < key.Length; i++)
             *  tempKey[i + 2] = key[i];*/
            this._key = key;

            GetData(heap, true);
        }
Пример #6
0
        public TableContext(NodeDataDTO nodeData)
        {
            NodeData = nodeData;
            HeapNode = new HN(NodeData);

            var tcinfoHID      = HeapNode.HeapNodes[0].Header.UserRoot;
            var tcinfoHIDbytes = HeapNode.GetHIDBytes(tcinfoHID);

            TCHeader = new TCINFOHEADER(tcinfoHIDbytes.Data);

            RowIndexBTH     = new BTH(HeapNode, TCHeader.RowIndexLocation);
            ReverseRowIndex = new Dictionary <uint, uint>();
            foreach (var prop in RowIndexBTH.Properties)
            {
                var temp = BitConverter.ToUInt32(prop.Value.Data, 0);
                ReverseRowIndex.Add(temp, BitConverter.ToUInt32(prop.Key, 0));
            }
            RowMatrix = new TCRowMatrix(this, RowIndexBTH);
        }
Пример #7
0
        public BTHIndexNode(HID hid, BTH tree, int level)
        {
            this.Level = level;
            this.HID   = hid;
            if (hid.hidBlockIndex == 0 && hid.hidIndex == 0)
            {
                return;
            }

            this.Entries = new List <BTHIndexEntry>();

            if (level == 0)
            {
                this.Data = new BTHDataNode(hid, tree);

                /*
                 * for (int i = 0; i < bytes.Length; i += (int)tree.Header.KeySize + 4)
                 *  this.Entries.Add(new BTHIndexEntry(bytes, i, tree.Header));
                 * this.DataChildren = new List<BTHDataNode>();
                 * foreach(var entry in this.Entries)
                 *  this.DataChildren.Add(new BTHDataNode(entry.HID, tree));*/
            }
            else
            {
                var bytes = tree.GetHIDBytes(hid);
                for (int i = 0; i < bytes.Data.Length; i += (int)tree.Header.KeySize + 4)
                {
                    this.Entries.Add(new BTHIndexEntry(bytes.Data, i, tree.Header));
                }
                this.Children = new List <BTHIndexNode>();
                foreach (var entry in this.Entries)
                {
                    this.Children.Add(new BTHIndexNode(entry.HID, tree, level - 1));
                }
            }
        }
Пример #8
0
        private void GetData(BTH heap, bool isTable = false)
        {
            if (PropertyLookupByTypeID.ContainsKey(Type))
            {
                var prop = PropertyLookupByTypeID[this.Type];
                MultiValue = prop.MultiValue;
                Variable   = prop.Variable;
                ByteCount  = prop.ByteCount;
            }
            //get data here

            if (!this.MultiValue && !this.Variable)
            {
                if (this.ByteCount <= 4 || (isTable && this.ByteCount <= 8))
                {
                    this.Data = this._key;
                }
                else
                {
                    this.Data = heap.GetHIDBytes(new HID(this._key)).Data;
                }
            }
            else
            {
                //oh no, it's an HNID
                var curID = BitConverter.ToUInt32(this._key, 0);

                if (curID == 0)
                {
                }
                else if ((curID & 0x1F) == 0) //must be HID
                {
                    this.Data = heap.GetHIDBytes(new HID(this._key)).Data;
                }
                else //let's assume NID
                {
                    var totalSize  = 0;
                    var dataBlocks = new List <BlockDataDTO>();
                    if (heap.HeapNode.HeapSubNode.ContainsKey(curID))
                    {
                        dataBlocks = heap.HeapNode.HeapSubNode[curID].NodeData;
                    }
                    else
                    {
                        var tempSubNodeXREF = new Dictionary <ulong, NodeDataDTO>();
                        foreach (var heapSubNode in heap.HeapNode.HeapSubNode)
                        {
                            tempSubNodeXREF.Add(heapSubNode.Key & 0xFFFFFFFF, heapSubNode.Value);
                        }
                        dataBlocks = tempSubNodeXREF[curID].NodeData;
                        //dataBlocks = entry.ParentTree.HeapNode.HeapSubNode[curID].NodeData;
                    }
                    foreach (var dataBlock in dataBlocks)
                    {
                        totalSize += dataBlock.Data.Length;
                    }
                    var allData = new byte[totalSize];
                    var curPos  = 0;
                    foreach (var datablock in dataBlocks)
                    {
                        for (int i = 0; i < datablock.Data.Length; i++)
                        {
                            allData[i + curPos] = datablock.Data[i];
                        }
                        curPos += datablock.Data.Length;
                    }
                    this.Data = allData;
                }
            }
        }
Пример #9
0
        public TCRowMatrix(TableContext tableContext, BTH heap)
        {
            this.Rows    = new List <TCRowMatrixData>();
            this.RowXREF = new Dictionary <uint, TCRowMatrixData>();

            this.TableContext = tableContext;
            var rowMatrixHNID = this.TableContext.TCHeader.RowMatrixLocation;

            if (rowMatrixHNID == 0)
            {
                return;
            }

            if ((rowMatrixHNID & 0x1F) == 0)//HID
            {
                this.TCRMData = new List <BlockDataDTO> {
                    new BlockDataDTO
                    {
                        Data = this.TableContext.HeapNode.GetHIDBytes(new HID(BitConverter.GetBytes(rowMatrixHNID))).Data
                    }
                };
            }
            else
            {
                if (this.TableContext.HeapNode.HeapSubNode.ContainsKey(rowMatrixHNID))
                {
                    this.TCRMData = this.TableContext.HeapNode.HeapSubNode[rowMatrixHNID].NodeData;
                }
                else
                {
                    var tempSubNodes = new Dictionary <ulong, NodeDataDTO>();
                    foreach (var nod in this.TableContext.HeapNode.HeapSubNode)
                    {
                        tempSubNodes.Add(nod.Key & 0xffffffff, nod.Value);
                    }
                    this.TCRMData = tempSubNodes[rowMatrixHNID].NodeData;
                }
            }
            //this.TCRMSubNodeData = this.TableContext.HeapNode.HeapSubNode[];
            var rowSize = this.TableContext.TCHeader.EndOffsetCEB;

            //var rowPerBlock = (8192 - 16)/rowSize;

            foreach (var row in this.TableContext.RowIndexBTH.Properties)
            {
                var rowIndex = BitConverter.ToUInt32(row.Value.Data, 0);

                var blockTrailerSize = 16;
                var maxBlockSize     = 8192 - blockTrailerSize;
                var recordsPerBlock  = maxBlockSize / rowSize;

                var blockIndex   = (int)rowIndex / recordsPerBlock;
                var indexInBlock = rowIndex % recordsPerBlock;
                var curRow       = new TCRowMatrixData(this.TCRMData[blockIndex].Data, this.TableContext, heap,
                                                       (int)indexInBlock * rowSize);
                this.RowXREF.Add(BitConverter.ToUInt32(row.Key, 0), curRow);
                this.Rows.Add(curRow);
            }

            /*
             * uint curIndex = 0;
             * foreach (var dataBlock in this.TCRMData)
             * {
             *  for(int i = 0;i + rowSize < dataBlock.Data.Length; i += rowSize)
             *  {
             *      var curRow = new TCRowMatrixData(dataBlock.Data, this.TableContext, i);
             *      this.RowXREF.Add(this.TableContext.ReverseRowIndex[curIndex], curRow);
             *      this.Rows.Add(curRow);
             *      curIndex++;
             *  }
             * }*/
        }