/// Marks item as checked out but does not remove from queue. You are expected to later call <see cref="Commit(QueueEntry{T})"/> or <see cref="Abort(QueueEntry{T})"/>
/// Non-transactional queues:
/// Removes item from queue with no need to call <see cref="Commit(QueueEntry{T})"/> or <see cref="Abort(QueueEntry{T})"/>
/// </summary>
/// <returns>An item if found or null</returns>
publicQueueEntry<T>Dequeue()
{
varresult=Dequeue(1);
if(result.Count==0)
{
returnnull;
}
else
{
returnresult[0];
}
}
/// <summary>
/// Batch equivalent of <see cref="Dequeue"/>
/// </summary>
/// <param name="batchSize">The maximum number of items to dequeue</param>
/// <returns>The items found or an empty collection (never null)</returns>
/// Aborts all currently checked out items. Equivalent of calling <see cref="CurrentCheckouts"/> followed by <see cref="Abort(IEnumerable{QueueEntry{T}})"/>
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when queue is not transactional</exception>
publicvoidResetOrphans()
{
if(!_transactional)
{
thrownewInvalidOperationException("Cannot call "+nameof(ResetOrphans)+" unless queue is transactional");
}
varcheckouts=CurrentCheckouts();
Abort(checkouts);
}
/// <summary>
/// Aborts a transaction on a single item. See <see cref="Abort(IEnumerable{QueueEntry{T}})"/> for batches.
/// </summary>
/// <param name="item">An item that was obtained from a <see cref="Dequeue"/> call</param>
/// <exception cref="InvalidOperationException">Thrown when queue is not transactional</exception>
publicvoidAbort(QueueEntry<T>item)
{
if(!_transactional)
{
thrownewInvalidOperationException("Cannot call "+nameof(Abort)+" unless queue is transactional");
}
elseif(item==null)
{
thrownewArgumentNullException(nameof(item));
}
item.IsCheckedOut=false;
_collection.Update(item);
}
/// <summary>
/// Aborts a transation on a group of items. See <see cref="Abort(QueueEntry{T})"/> for a single item.
/// </summary>
/// <param name="items">Items that were obtained from a <see cref="Dequeue"/> call</param>
/// <exception cref="InvalidOperationException">Thrown when queue is not transactional</exception>
publicvoidAbort(IEnumerable<QueueEntry<T>>items)
{
foreach(variteminitems)
{
Abort(item);
}
}
/// <summary>
/// Commits a transaction on a single item. See <see cref="Commit(IEnumerable{QueueEntry{T}})"/> for batches.
/// </summary>
/// <param name="item">An item that was obtained from a <see cref="Dequeue"/> call</param>
/// <exception cref="InvalidOperationException">Thrown when queue is not transactional</exception>
publicvoidCommit(QueueEntry<T>item)
{
if(item==null)
{
thrownewArgumentNullException(nameof(item));
}
if(!_transactional)
{
thrownewInvalidOperationException("Cannot call "+nameof(Commit)+" unless queue is transactional");
}
BsonValueid=newBsonValue(item.Id);
_collection.Delete(id);
}
/// <summary>
/// Commits a transation on a group of items. See <see cref="Commit(QueueEntry{T})/> for a single item.
/// </summary>
/// <param name="items">Items that were obtained from a <see cref="Dequeue"/> call</param>
/// <exception cref="InvalidOperationException">Thrown when queue is not transactional</exception>
publicvoidCommit(IEnumerable<QueueEntry<T>>items)
{
foreach(variteminitems)
{
Commit(item);
}
}
/// <summary>
/// Number of items in queue, including those that have been checked out.
/// </summary>
publicintCount()
{
return_collection.Count();
}
/// <summary>
/// Removes all items from queue, including any that have been checked out.
Adds a batch of items to the queue. See <seecref="M:LiteQueue.LiteQueue`1.Enqueue(`0)"/> for adding a single item.
</summary>
<paramname="items"></param>
</member>
<membername="M:LiteQueue.LiteQueue`1.Dequeue">
<summary>
Transactional queues:
Marks item as checked out but does not remove from queue. You are expected to later call <seecref="M:LiteQueue.LiteQueue`1.Commit(LiteQueue.QueueEntry{`0})"/> or <seecref="M:LiteQueue.LiteQueue`1.Abort(LiteQueue.QueueEntry{`0})"/>
Non-transactional queues:
Removes item from queue with no need to call <seecref="M:LiteQueue.LiteQueue`1.Commit(LiteQueue.QueueEntry{`0})"/> or <seecref="M:LiteQueue.LiteQueue`1.Abort(LiteQueue.QueueEntry{`0})"/>
Aborts all currently checked out items. Equivalent of calling <seecref="M:LiteQueue.LiteQueue`1.CurrentCheckouts"/> followed by <seecref="M:LiteQueue.LiteQueue`1.Abort(System.Collections.Generic.IEnumerable{LiteQueue.QueueEntry{`0}})"/>
</summary>
<exceptioncref="T:System.InvalidOperationException">Thrown when queue is not transactional</exception>
Aborts a transaction on a single item. See <seecref="M:LiteQueue.LiteQueue`1.Abort(System.Collections.Generic.IEnumerable{LiteQueue.QueueEntry{`0}})"/> for batches.
</summary>
<paramname="item">An item that was obtained from a <seecref="M:LiteQueue.LiteQueue`1.Dequeue"/> call</param>
<exceptioncref="T:System.InvalidOperationException">Thrown when queue is not transactional</exception>
Commits a transaction on a single item. See <seecref="M:LiteQueue.LiteQueue`1.Commit(System.Collections.Generic.IEnumerable{LiteQueue.QueueEntry{`0}})"/> for batches.
</summary>
<paramname="item">An item that was obtained from a <seecref="M:LiteQueue.LiteQueue`1.Dequeue"/> call</param>
<exceptioncref="T:System.InvalidOperationException">Thrown when queue is not transactional</exception>
</member>
<!-- Badly formed XML comment ignored for member "M:LiteQueue.LiteQueue`1.Commit(System.Collections.Generic.IEnumerable{LiteQueue.QueueEntry{`0}})" -->
<membername="M:LiteQueue.LiteQueue`1.Count">
<summary>
Number of items in queue, including those that have been checked out.
</summary>
</member>
<membername="M:LiteQueue.LiteQueue`1.Clear">
<summary>
Removes all items from queue, including any that have been checked out.