Example #1
0
        /// <summary>
        /// Del an item from the second item. Delete is expensive as it has to search throught all records.
        /// </summary>
        /// <param name="SectionPosition"></param>
        /// <param name="BlockPosition"></param>
        public void Del(long SectionPosition, long BlockPosition)
        {
            ItemHeader header = loadHeader(SectionPosition);

            if (header.BlockPosition <= 0)
            {
                return;
            }

            Item nextitem = loadItem(header.FirstRecordPointer);

            if (nextitem.ContentBlockPosition == BlockPosition)
            {
                header.FirstRecordPointer = nextitem.NextRecord;
                header.counter            = header.counter - 1;
                Stream.Position           = header.BlockPosition;
                Stream.Write(header.ToBytes(), 0, 14);
            }
            else
            {
                bool delok = Del(nextitem, BlockPosition);
                if (delok)
                {
                    header.counter  = header.counter - 1;
                    Stream.Position = header.BlockPosition;
                    Stream.Write(header.ToBytes(), 0, 14);
                }
            }
        }
Example #2
0
        private void Add(ItemHeader header, long BlockPosition)
        {
            Item item = new Item();

            item.ContentBlockPosition = BlockPosition;
            item.NextRecord           = header.FirstRecordPointer;

            long writeposition = Stream.Length;

            Stream.Position = writeposition;
            Stream.Write(item.ToBytes(), 0, 18);

            header.FirstRecordPointer = writeposition;
            header.counter            = header.counter + 1;

            Stream.Position = header.BlockPosition;
            Stream.Write(header.ToBytes(), 0, 14);
        }
Example #3
0
        private ItemHeader CreateNewSection()
        {
            ItemHeader header = new ItemHeader();

            header.counter            = 0;
            header.FirstRecordPointer = 0;
            Int64 writeposition;

            writeposition = Stream.Length;

            Stream.Position = writeposition;

            Stream.Write(header.ToBytes(), 0, 14);

            header.BlockPosition = writeposition;

            return(header);
        }
Example #4
0
        /// <summary>
        /// Dequeue one item
        /// </summary>
        /// <param name="SectionPosition"></param>
        /// <returns></returns>
        public long DeQueue(long SectionPosition)
        {
            lock (_object)
            {
                ItemHeader header = loadHeader(SectionPosition);

                if (header.counter < 1)
                {
                    return(-1);
                }

                Item item = loadItem(header.FirstRecordPointer);

                header.counter            = header.counter - 1;
                header.FirstRecordPointer = item.NextRecord;

                Stream.Position = header.BlockPosition;
                Stream.Write(header.ToBytes(), 0, 14);

                return(item.ContentBlockPosition);
            }
        }