/// <summary>
        /// Gets an enumerator for all entries in the dictionary.
        /// </summary>
        /// <param name="Locked">If the file should be locked.</param>
        /// <returns>Enumerator</returns>
        public async Task <ObjectBTreeFileEnumerator <KeyValuePair <string, object> > > GetEnumerator(bool Locked)
        {
            ObjectBTreeFileEnumerator <KeyValuePair <string, object> > Result = null;

            try
            {
                Result = new ObjectBTreeFileEnumerator <KeyValuePair <string, object> >(this.dictionaryFile, this.recordHandler, this.keyValueSerializer);
                if (Locked)
                {
                    await Result.Lock();
                }
            }
            catch (Exception ex)
            {
                if (Result != null)
                {
                    Result.Dispose();
                    Result = null;
                }

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

            return(Result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets an enumerator for all entries in the dictionary.
        /// </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>
        /// <returns>Enumerator</returns>
        public async Task <ObjectBTreeFileEnumerator <KeyValuePair <string, object> > > GetEnumerator(LockType LockType)
        {
            ObjectBTreeFileEnumerator <KeyValuePair <string, object> > Result = null;

            try
            {
                Result = await ObjectBTreeFileEnumerator <KeyValuePair <string, object> > .Create(this.dictionaryFile, this.recordHandler, this.keyValueSerializer);

                if (LockType != LockType.None)
                {
                    await Result.Lock(LockType);
                }
            }
            catch (Exception ex)
            {
                Result?.Dispose();
                Result = null;

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

            return(Result);
        }