Exemple #1
0
        public void Test()
        {
            const int blockSize = 100;
            var       data      = new TradesBlock[1000];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = new TradesBlock(i, blockSize);
            }

            string fileName = GetBinFileName();

            if (AllowCreate)
            {
                using (var f = new BinIndexedFile <TradesBlock>(fileName))
                {
                    ((IBinBlockSerializer)f.Serializer).ItemCount = blockSize;
                    f.InitializeNewFile();
                    f.WriteData(0, new ArraySegment <TradesBlock>(data));

                    VerifyData(f, data);
                }
            }

            using (var bf = (BinIndexedFile <TradesBlock>)BinaryFile.Open(fileName, false, LegacyResolver))
            {
                VerifyData(bf, data);
            }
        }
Exemple #2
0
        private static void VerifyData(BinIndexedFile <TradesBlock> bf, TradesBlock[] data)
        {
            int ind = 0;

            foreach (var sg in bf.StreamSegments(0, false))
            {
                int last = sg.Count;
                for (int i = 0; i < last; i++)
                {
                    TradesBlock item = sg.Array[i];
                    if (!data[ind].Header.Equals(item.Header))
                    {
                        throw new Exception();
                    }
                    for (int j = 0; j < item.Items.Length; j++)
                    {
                        if (!data[ind].Items[j].Equals(item.Items[j]))
                        {
                            throw new Exception();
                        }
                    }

                    if (!data[ind].Header.Equals(item.Header))
                    {
                        throw new Exception();
                    }

                    ind++;
                }
            }
        }