Exemplo n.º 1
0
        /// <summary>
        /// Permanently remove a record from the stream, identified by the <see cref="IQueueStreamHandle"/> attached to the <see cref="QueueStreamRecord"/>
        /// returned by <see cref="ReadNextRecord"/>.
        /// </summary>
        /// <param name="location">The handle returned by ReadNextRecord</param>
        public void DeleteRecord(IQueueStreamHandle location)
        {
            var handle = location as QueueStreamHandle;

            if (handle == null)
            {
                throw new ArgumentException("The provided location cursor is invalid for this stream", "location");
            }
            if (handle.Generation != _generation)
            {
                return;
            }
            if (!_recordMap.ContainsKey(handle.Position))
            {
                return;
            }
            _stream.Position = handle.Position;
            _stream.Write(DeletedMarker, 0, DeletedMarker.Length);
            _recordMap.Remove(handle.Position);
            if (_recordMap.Count == 0)
            {
                // no undeleted records in file, truncate
                _stream.SetLength(0);
                _generation++;
            }
        }
        /// <summary>
        /// Permanently remove a record from the stream, identified by the <see cref="IQueueStreamHandle"/> attached to the <see cref="QueueStreamRecord"/>
        /// returned by <see cref="ReadNextRecord"/>.
        /// </summary>
        /// <param name="location">The handle attached to the <see cref="QueueStreamRecord"/>
        /// returned by <see cref="ReadNextRecord"/></param>
        public void DeleteRecord(IQueueStreamHandle location)
        {
            EnsureInstanceNotDisposed();
            if (!(location is QueueStreamHandle))
            {
                throw new ArgumentException("The provided location handle is invalid for this stream", "location");
            }
            var handle     = (QueueStreamHandle)location;
            var streamInfo = GetStreamInfoFromHandle(handle);

            if (streamInfo == null)
            {
                return;
            }
            streamInfo.Stream.Seek(handle.Position, SeekOrigin.Begin);
            streamInfo.Stream.Write(DeletedMarker, 0, DeletedMarker.Length);
            RemoveHandle(handle, streamInfo);
        }
Exemplo n.º 3
0
 //--- Constructors ---
 /// <summary>
 /// Create a new record
 /// </summary>
 /// <remarks>
 /// Only used by implementors of <see cref="IQueueStream"/>
 /// </remarks>
 /// <param name="stream">A stream containing the bytes of only this record. Should be positioned at the 0 byte</param>
 /// <param name="handle">An implementation of <see cref="IQueueStreamHandle"/> used by the creator of this instance to track the record in question</param>
 public QueueStreamRecord(Stream stream, IQueueStreamHandle handle)
 {
     Stream = stream;
     Handle = handle;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Permanently remove a record from the stream, identified by the <see cref="IQueueStreamHandle"/> attached to the <see cref="QueueStreamRecord"/>
        /// returned by <see cref="ReadNextRecord"/>.
        /// </summary>
        /// <param name="location">The handle returned by ReadNextRecord</param>
        public void DeleteRecord(IQueueStreamHandle location)
        {
            var handle = location as QueueStreamHandle;
            if(handle == null) {
                throw new ArgumentException("The provided location cursor is invalid for this stream", "location");
            }
            if(handle.Generation != _generation) {
                return;
            }
            if(!_recordMap.ContainsKey(handle.Position)) {
                return;
            }
            _stream.Position = handle.Position;
            _stream.Write(DeletedMarker, 0, DeletedMarker.Length);
            _recordMap.Remove(handle.Position);
            if(_recordMap.Count == 0) {

                // no undeleted records in file, truncate
                _stream.SetLength(0);
                _generation++;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Permanently remove a record from the stream, identified by the <see cref="IQueueStreamHandle"/> attached to the <see cref="QueueStreamRecord"/>
 /// returned by <see cref="ReadNextRecord"/>.
 /// </summary>
 /// <param name="location">The handle attached to the <see cref="QueueStreamRecord"/>
 /// returned by <see cref="ReadNextRecord"/></param>
 public void DeleteRecord(IQueueStreamHandle location)
 {
     EnsureInstanceNotDisposed();
     if(!(location is QueueStreamHandle)) {
         throw new ArgumentException("The provided location handle is invalid for this stream", "location");
     }
     var handle = (QueueStreamHandle)location;
     var streamInfo = GetStreamInfoFromHandle(handle);
     if(streamInfo == null) {
         return;
     }
     streamInfo.Stream.Seek(handle.Position, SeekOrigin.Begin);
     streamInfo.Stream.Write(DeletedMarker, 0, DeletedMarker.Length);
     RemoveHandle(handle, streamInfo);
 }
Exemplo n.º 6
0
 //--- Constructors ---
 /// <summary>
 /// Create a new record
 /// </summary>
 /// <remarks>
 /// Only used by implementors of <see cref="IQueueStream"/>
 /// </remarks>
 /// <param name="stream">A stream containing the bytes of only this record. Should be positioned at the 0 byte</param>
 /// <param name="handle">An implementation of <see cref="IQueueStreamHandle"/> used by the creator of this instance to track the record in question</param>
 public QueueStreamRecord(Stream stream, IQueueStreamHandle handle) {
     Stream = stream;
     Handle = handle;
 }
 //--- Constructors ---
 public Item(T data, IQueueStreamHandle handle)
 {
     _data  = data;
     Handle = handle;
 }