Example #1
0
        public void CreateAndOpenStore()
        {
            var indexSetStore = new IndexSetStore(store);

            var pointer = indexSetStore.Create();

            Assert.True(pointer >= 0);

            indexSetStore.Open(pointer);

            indexSetStore.Dispose();
        }
Example #2
0
        public void GetSnapshotIndex()
        {
            var indexSetStore = new IndexSetStore(store);

            var pointer = indexSetStore.Create();

            indexSetStore.Open(pointer);

            var indexSet = indexSetStore.GetSnapshotIndex();

            Assert.NotNull(indexSet);
            Assert.Empty(indexSet);

            indexSet.Dispose();

            indexSetStore.Dispose();
        }
        private void SetupInitialStore()
        {
            byte[] tableInfoBuf;

            using (var stream = new MemoryStream()) {
                var writer = new BinaryWriter(stream, Encoding.Unicode);
                writer.Write(1);
                TableInfoSerializer.Serialize(TableInfo, writer);

                tableInfoBuf = stream.ToArray();
            }

            byte[] indexSetInfoBuf;

            using (var stream = new MemoryStream()) {
                var writer = new BinaryWriter(stream, Encoding.Unicode);
                writer.Write(1);

                IndexSetInfoSerializer.Serialize(IndexSetInfo, writer);

                indexSetInfoBuf = stream.ToArray();
            }

            try {
                Store.Lock();

                // Allocate an 80 byte header
                using (var headerWriter = Store.CreateArea(80)) {
                    long headerPointer = headerWriter.Id;

                    // Allocate space to store the DataTableInfo serialization
                    using (var dataTableDefWriter = Store.CreateArea(tableInfoBuf.Length)) {
                        long tableInfoOffset = dataTableDefWriter.Id;

                        // Allocate space to store the DataIndexSetInfo serialization
                        using (var indexSetWriter = Store.CreateArea(indexSetInfoBuf.Length)) {
                            long indexSetInfoPointer = indexSetWriter.Id;

                            // Allocate space for the list header
                            listHeaderOffset = recordList.Create();
                            recordList.WriteDeleteHead(-1);
                            firstDeleteChainRecord = -1;

                            // Create the index store
                            indexSetStore     = new IndexSetStore(Store);
                            indexHeaderOffset = indexSetStore.Create();

                            // Write the main header
                            headerWriter.Write((int)1);                              // Version
                            headerWriter.Write(TableId);                             // table id
                            headerWriter.Write(sequenceId);                          // initial sequence id
                            headerWriter.Write(tableInfoOffset);                     // pointer to DataTableInfo
                            headerWriter.Write(indexSetInfoPointer);                 // pointer to DataIndexSetInfo
                            headerWriter.Write(indexHeaderOffset);                   // index header pointer
                            headerWriter.Write(listHeaderOffset);                    // list header pointer
                            headerWriter.Flush();

                            // Write the table info
                            dataTableDefWriter.Write(tableInfoBuf, 0, tableInfoBuf.Length);
                            dataTableDefWriter.Flush();

                            // Write the index set info
                            indexSetWriter.Write(indexSetInfoBuf, 0, indexSetInfoBuf.Length);
                            indexSetWriter.Flush();

                            // Set the pointer to the header input the reserved area.
                            using (var fixedArea = Store.GetArea(-1)) {
                                fixedArea.Write(headerPointer);
                                fixedArea.Flush();
                            }

                            // Set the header area
                            headerArea = Store.GetArea(headerPointer);
                        }
                    }
                }
            } finally {
                Store.Unlock();
            }
        }