/// <summary> /// Searches for the first object that is lasser than a hypothetical limit object. /// </summary> /// <typeparam name="T">The typed enumerator uses /// the object serializer of <typeparamref name="T"/> to deserialize objects by default.</typeparam> /// <param name="Locked">If the resulting enumerator should be opened in locked mode or not.</param> /// <param name="Object">Limit object to search for.</param> /// <returns>Enumerator that can be used to enumerate objects in index order. First object will be the first /// object that is lesser than the limit object. If null is returned, the search operation could /// not be performed.</returns> public async Task <IndexBTreeFileEnumerator <T> > FindLastLesserThan <T>(bool Locked, GenericObject Object) { byte[] Key = this.recordHandler.Serialize(Guid.Empty, Object, this.genericSerializer, MissingFieldAction.First); if (Key.Length > this.indexFile.InlineObjectSizeLimit) { return(null); } IndexBTreeFileEnumerator <T> Result = null; try { Result = new IndexBTreeFileEnumerator <T>(this, this.recordHandler); if (Locked) { await Result.LockRead(); } BlockInfo Leaf = await this.indexFile.FindLeafNodeLocked(Key); Result.SetStartingPoint(Leaf); } catch (Exception ex) { if (Result != null) { Result.Dispose(); Result = null; } System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); } return(Result); }
/// <summary> /// Returns an typed enumerator that iterates through the collection in the order specified by the index. The typed enumerator uses /// the object serializer of <typeparamref name="T"/> to deserialize objects by default. /// </summary> /// <param name="Locked">If locked access to the file is requested. /// /// If unlocked access is desired, any change to the database will invalidate the enumerator, and further access to the /// enumerator will cause an <see cref="InvalidOperationException"/> to be thrown. /// /// If locked access is desired, the database cannot be updated, until the enumerator has been dispose. Make sure to call /// the <see cref="IndexBTreeFileEnumerator{T}.Dispose"/> method when done with the enumerator, to release the database /// after use.</param> /// <returns>An enumerator that can be used to iterate through the collection.</returns> public async Task <IndexBTreeFileEnumerator <T> > GetTypedEnumerator <T>(bool Locked) { IndexBTreeFileEnumerator <T> e = new IndexBTreeFileEnumerator <T>(this, this.recordHandler); if (Locked) { await e.LockRead(); } return(e); }