Esempio n. 1
0
        private ItemHeader loadHeader(long SectionPosition)
        {
            byte[] headerbytes = new byte[14];

            Stream.Position = SectionPosition;
            Stream.Read(headerbytes, 0, 14);

            ItemHeader header = new ItemHeader();

            header.ParseBytes(headerbytes);

            header.BlockPosition = SectionPosition;

            return(header);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 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);
            }
        }