Пример #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>
        /// 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);
        }