コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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="LockType">
        /// If locked access to the file is requested, and of what type.
        ///
        /// 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 read locked access is desired, the database cannot be updated, until the enumerator has been disposed.
        /// If write locked access is desired, the database cannot be accessed at all, until the enumerator has been disposed.
        ///
        /// Make sure to call the <see cref="ObjectBTreeFileEnumerator{T}.Dispose"/> method when done with the enumerator, to release
        /// the database lock after use.
        /// </param>
        /// <param name="LockParent">If parent file is to be locked as well.</param>
        /// <returns>An enumerator that can be used to iterate through the collection.</returns>
        public async Task <IndexBTreeFileEnumerator <T> > GetTypedEnumerator <T>(LockType LockType, bool LockParent)
        {
            IndexBTreeFileEnumerator <T> e = await IndexBTreeFileEnumerator <T> .Create(this, this.recordHandler);

            if (LockType != LockType.None)
            {
                await e.Lock(LockType, LockParent);
            }

            return(e);
        }
コード例 #4
0
        /// <summary>
        /// Searches for the first object that is greater 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 greater than the limit object. If null is returned, the search operation could
        /// not be performed.</returns>
        public async Task <IndexBTreeFileEnumerator <T> > FindFirstGreaterThan <T>(bool Locked, GenericObject Object)
        {
            byte[] Key = this.recordHandler.Serialize(GuidMax, Object, this.genericSerializer, MissingFieldAction.Last);
            if (Key.Length > this.indexFile.InlineObjectSizeLimit)
            {
                return(null);
            }

            IndexBTreeFileEnumerator <T> Result = null;

            await this.indexFile.Lock();

            try
            {
                BlockInfo Leaf = await this.indexFile.FindLeafNodeLocked(Key);

                Result = new IndexBTreeFileEnumerator <T>(this, Locked, this.recordHandler, Leaf);

                if (!Locked)
                {
                    await this.indexFile.Release();
                }
            }
            catch (Exception ex)
            {
                if (Result != null)
                {
                    Result.Dispose();
                    Result = null;
                }
                else
                {
                    await this.indexFile.Release();
                }

                System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
            }

            return(Result);
        }
コード例 #5
0
 /// <summary>
 /// Returns an untyped enumerator that iterates through the collection in the order specified by the index.
 ///
 /// For a typed enumerator, call the <see cref="GetTypedEnumerator{T}(LockType, bool)"/> method.
 /// </summary>
 /// <returns>An enumerator that can be used to iterate through the collection.</returns>
 public async Task <IEnumerator <object> > GetEnumeratorAsync()
 {
     return(await IndexBTreeFileEnumerator <object> .Create(this, this.recordHandler));
 }