Exemplo n.º 1
0
        public override void WriteOffsetMap(BinaryWriter bw, DBEntry entry, List <Tuple <int, short> > OffsetMap, int record_offset = 0)
        {
            var minmax     = entry.MinMax();
            var ids        = new HashSet <int>(entry.GetPrimaryKeys());
            var duplicates = entry.Header.OffsetDuplicates;

            int m = 0;

            for (int x = minmax.Item1; x <= minmax.Item2; x++)
            {
                if (ids.Contains(x)) //Insert the offset map
                {
                    var kvp = OffsetMap[m];
                    bw.Write(kvp.Item1 + record_offset);
                    bw.Write(kvp.Item2);
                    m++;
                }
                else if (duplicates.ContainsKey(x)) //Reinsert our duplicates
                {
                    var hiddenkvp = OffsetMap[duplicates[x]];
                    bw.Write(hiddenkvp.Item1 + record_offset);
                    bw.Write(hiddenkvp.Item2);
                }
                else
                {
                    bw.BaseStream.Position += sizeof(int) + sizeof(short); //0 fill
                }
            }

            ids.Clear();
        }
Exemplo n.º 2
0
        public override void WriteIndexTable(BinaryWriter bw, DBEntry entry)
        {
            int m = 0;

            int[] ids;
            ids = entry.GetPrimaryKeys().ToArray();

            if (entry.Header.HasSecondIndex)
            {
                //TODO figure out if it is always the 2nd column
                ushort[] secondids = entry.Data.Rows.Cast <DataRow>().Select(x => x.Field <ushort>(2)).ToArray();

                //Write all of the secondary ids
                foreach (ushort id in secondids)
                {
                    //Populate missing secondary ids with 0
                    if (m > 0 && (ids[m] - ids[m - 1]) > 1)
                    {
                        bw.BaseStream.Position += sizeof(int) * (ids[m] - ids[m - 1] - 1);
                    }

                    bw.Write((int)id);
                    m++;
                }
            }

            //Write all the IDs
            bw.WriteArray(ids);
        }
Exemplo n.º 3
0
        public override void WriteIndexTable <T>(BinaryWriter bw, DBEntry <T> entry)
        {
            int m = 0;

            int[] ids = entry.GetPrimaryKeys().ToArray();

            if (entry.Header.HasSecondIndex)
            {
                PropertyInfo secondId  = entry.TableStructure[2];
                ushort[]     secondids = entry.Rows.Select(x => (ushort)secondId.GetValue(x)).ToArray();

                //Write all of the secondary ids
                foreach (ushort id in secondids)
                {
                    //Populate missing secondary ids with 0
                    if (m > 0 && (ids[m] - ids[m - 1]) > 1)
                    {
                        bw.BaseStream.Position += sizeof(int) * (ids[m] - ids[m - 1] - 1);
                    }

                    bw.Write((int)id);
                    m++;
                }
            }

            //Write all the primary IDs
            bw.WriteArray(ids);
        }
Exemplo n.º 4
0
        public override void WriteIndexTable <T>(BinaryWriter bw, DBEntry <T> entry)
        {
            int m = 0;

            int[]        ids;
            PropertyInfo secondId = entry.TableStructure[2];

            if (!HasOffsetTable)
            {
                ids = entry.GetUniqueRows().Select(x => (int)entry.PrimaryKey.GetValue(x)).ToArray();
            }
            else
            {
                ids = entry.GetPrimaryKeys().ToArray();
            }

            if (entry.Header.HasSecondIndex)
            {
                //TODO figure out if it is always the 2nd column
                ushort[] secondids = entry.Rows.Select(x => (ushort)secondId.GetValue(x)).ToArray();

                //Write all of the secondary ids
                foreach (ushort id in secondids)
                {
                    //Populate missing secondary ids with 0
                    if (m > 0 && (ids[m] - ids[m - 1]) > 1)
                    {
                        bw.BaseStream.Position += sizeof(int) * (ids[m] - ids[m - 1] - 1);
                    }

                    bw.Write((int)id);
                    m++;
                }
            }

            //Write all the IDs
            bw.WriteArray(ids);
        }
Exemplo n.º 5
0
        public override void WriteOffsetMap <T>(BinaryWriter bw, DBEntry <T> entry, List <Tuple <int, short> > OffsetMap)
        {
            bw.Scrub(OffsetMapOffset); //Scrub to after header

            //Write the offset map
            var ids = entry.GetPrimaryKeys().ToList();

            for (int x = 0; x < ids.Count(); x++)
            {
                var kvp = OffsetMap[x];
                bw.Write(ids[x]);
                bw.Write(kvp.Item1);
                bw.Write(kvp.Item2);
            }
            ids.Clear();

            //Clear string table size
            long pos = bw.BaseStream.Position;

            bw.Scrub(entry.Header.StringTableOffset);
            bw.Write(0);
            bw.Scrub(pos);
        }
Exemplo n.º 6
0
        public override void WriteHeader <T>(BinaryWriter bw, DBEntry <T> entry)
        {
            Tuple <int, int> minmax = entry.MinMax();

            bw.BaseStream.Position = 0;

            base.WriteHeader(bw, entry);

            bw.Write(TableHash);
            bw.Write(LayoutHash);
            bw.Write(Build);
            bw.Write(TimeStamp);
            bw.Write(minmax.Item1); //MinId
            bw.Write(minmax.Item2); //MaxId
            bw.Write(Locale);

            //WCH5 has the offsetmap BEFORE the data, create placeholder data
            if (HasOffsetTable)
            {
                OffsetMapOffset         = (int)bw.BaseStream.Position;
                bw.BaseStream.Position += entry.GetPrimaryKeys().Count() * (sizeof(int) + sizeof(int) + sizeof(short));
            }
        }