コード例 #1
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public async Task DisposeAsync()
        {
            await this.e.DisposeAsync();

            this.e      = null;
            this.locked = false;
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <summary>
        /// Regenerates the index.
        /// </summary>
        /// <returns></returns>
        public async Task Regenerate()
        {
            int c = 0;
            int d = 0;

            await this.ClearAsync();

            using (ObjectBTreeFileEnumerator <object> e = await this.objectFile.GetTypedEnumeratorAsync <object>(true))
            {
                while (await e.MoveNextAsync())
                {
                    object Obj = e.Current;

                    if (Obj != null)
                    {
                        c++;
                        await this.SaveNewObject((Guid)e.CurrentObjectId, e.Current, e.CurrentSerializer);
                    }
                    else
                    {
                        d++;
                    }
                }
            }

            Log.Notice("Index regenerated.", this.indexFile.FileName,
                       new KeyValuePair <string, object>("NrObjects", c),
                       new KeyValuePair <string, object>("NrNotLoadable", d));
        }
コード例 #4
0
        /// <summary>
        /// Regenerates the index.
        /// </summary>
        /// <returns></returns>
        public async Task Regenerate()
        {
            await this.ClearAsync();

            using (ObjectBTreeFileEnumerator <object> e = this.objectFile.GetTypedEnumerator <object>(true))
            {
                while (e.MoveNext())
                {
                    await this.SaveNewObject((Guid)e.CurrentObjectId, e.Current, e.CurrentSerializer);
                }
            }
        }
コード例 #5
0
        internal IndexBTreeFileEnumerator(IndexBTreeFile File, IndexRecords RecordHandler)
        {
            this.file                = File;
            this.recordHandler       = RecordHandler;
            this.provider            = this.file.ObjectFile.Provider;
            this.hasCurrent          = false;
            this.currentObjectId     = Guid.Empty;
            this.current             = default;
            this.currentSerializer   = null;
            this.timeoutMilliseconds = File.IndexFile.TimeoutMilliseconds;

            this.e = new ObjectBTreeFileEnumerator <object>(this.file.IndexFile, RecordHandler);
        }
コード例 #6
0
        /// <summary>
        /// Loads the entire table and returns it as an array.
        /// </summary>
        /// <returns>Array of key-value pairs.</returns>
        public async Task <KeyValuePair <string, object>[]> ToArrayAsync()
        {
            List <KeyValuePair <string, object> > Result = new List <KeyValuePair <string, object> >();

            using (ObjectBTreeFileEnumerator <KeyValuePair <string, object> > e = await this.GetEnumerator(true))
            {
                while (await e.MoveNextAsync())
                {
                    Result.Add(e.Current);
                }
            }

            return(Result.ToArray());
        }
コード例 #7
0
        /// <summary>
        /// <see cref="ICollection{T}.CopyTo(T[], int)"/>
        /// </summary>
        public void CopyTo(KeyValuePair <string, object>[] array, int arrayIndex)
        {
            Task <ObjectBTreeFileEnumerator <KeyValuePair <string, object> > > Task = this.GetEnumerator(true);

            FilesProvider.Wait(Task, this.timeoutMilliseconds);

            using (ObjectBTreeFileEnumerator <KeyValuePair <string, object> > e = Task.Result)
            {
                while (e.MoveNext())
                {
                    array[arrayIndex++] = e.Current;
                }
            }
        }
コード例 #8
0
        public void CopyTo(object[] array, int arrayIndex)
        {
            Task <ObjectBTreeFileEnumerator <KeyValuePair <string, object> > > Task = this.dictionary.GetEnumerator(LockType.Read);

            FilesProvider.Wait(Task, this.dictionary.DictionaryFile.TimeoutMilliseconds);

            using (ObjectBTreeFileEnumerator <KeyValuePair <string, object> > e = Task.Result)
            {
                while (e.MoveNext())
                {
                    array[arrayIndex++] = e.Current.Value;
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public async Task DisposeAsync()
        {
            if (!(this.e is null))
            {
                await this.e.DisposeAsync();

                this.e = null;
            }

            if (this.lockType != LockType.None && this.lockParent)
            {
                await this.file.ObjectFile.EndLock(this.lockType);
            }
        }
コード例 #10
0
        internal IndexBTreeFileEnumerator(IndexBTreeFile File, bool Locked, IndexRecords RecordHandler, BlockInfo StartingPoint)
        {
            this.file                = File;
            this.locked              = Locked;
            this.recordHandler       = RecordHandler;
            this.provider            = this.file.ObjectFile.Provider;
            this.hasCurrent          = false;
            this.currentObjectId     = Guid.Empty;
            this.current             = default(T);
            this.currentSerializer   = null;
            this.timeoutMilliseconds = File.IndexFile.TimeoutMilliseconds;

            this.e = new ObjectBTreeFileEnumerator <object>(this.file.IndexFile, Locked, RecordHandler, StartingPoint);
        }
コード例 #11
0
        /// <summary>
        /// Regenerates the index.
        /// </summary>
        /// <returns></returns>
        public async Task Regenerate()
        {
            LinkedList <object> Objects        = new LinkedList <object>();
            LinkedList <Guid>   ObjectIds      = new LinkedList <Guid>();
            IObjectSerializer   LastSerializer = null;
            int Count = 0;
            int c     = 0;
            int d     = 0;

            await this.ClearAsync();

            using (ObjectBTreeFileEnumerator <object> e = await this.objectFile.GetTypedEnumeratorAsync <object>(LockType.Write))
            {
                while (await e.MoveNextAsync())
                {
                    object            Obj        = e.Current;
                    IObjectSerializer Serializer = e.CurrentSerializer;

                    if (!(Obj is null))
                    {
                        if (LastSerializer is null || Serializer != LastSerializer)
                        {
                            if (Count > 0)
                            {
                                await this.SaveNewObjects(ObjectIds, Objects, LastSerializer);

                                ObjectIds.Clear();
                                Objects.Clear();
                                Count = 0;
                            }

                            LastSerializer = Serializer;
                        }

                        ObjectIds.AddLast((Guid)e.CurrentObjectId);
                        Objects.AddLast(Obj);
                        c++;
                        Count++;

                        if (Count >= 1000)
                        {
                            await this.SaveNewObjects(ObjectIds, Objects, LastSerializer);

                            ObjectIds.Clear();
                            Objects.Clear();
                            Count = 0;
                        }
                    }
コード例 #12
0
ファイル: StringDictionary.cs プロジェクト: iamr8/IoTGateway
        /// <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);
        }
コード例 #13
0
        /// <summary>
        /// Regenerates the index.
        /// </summary>
        /// <returns></returns>
        public async Task Regenerate()
        {
            LinkedList <object> Objects        = new LinkedList <object>();
            LinkedList <Guid>   ObjectIds      = new LinkedList <Guid>();
            IObjectSerializer   LastSerializer = null;
            int Count = 0;
            int c     = 0;
            int d     = 0;

            await this.ClearAsync();

            using (ObjectBTreeFileEnumerator <object> e = await this.objectFile.GetTypedEnumeratorAsync <object>(true))
            {
                while (await e.MoveNextAsync())
                {
                    object            Obj        = e.Current;
                    IObjectSerializer Serializer = e.CurrentSerializer;

                    if (Obj != null)
                    {
                        if (LastSerializer is null || Serializer != LastSerializer)
                        {
                            LastSerializer = Serializer;

                            if (Count > 0)
                            {
                                await this.SaveNewObjects(ObjectIds, Objects, LastSerializer);

                                ObjectIds.Clear();
                                Objects.Clear();
                                Count = 0;
                            }
                        }

                        ObjectIds.AddLast((Guid)e.CurrentObjectId);
                        Objects.AddLast(Obj);
                        c++;
                        Count++;

                        if (Count >= 1000)
                        {
                            await this.SaveNewObjects(ObjectIds, Objects, LastSerializer);

                            ObjectIds.Clear();
                            Objects.Clear();
                            Count = 0;
                        }
                    }
                    else
                    {
                        d++;
                    }
                }

                if (Count > 0)
                {
                    await this.SaveNewObjects(ObjectIds, Objects, LastSerializer);
                }
            }

            Log.Notice("Index regenerated.", this.indexFile.FileName,
                       new KeyValuePair <string, object>("NrObjects", c),
                       new KeyValuePair <string, object>("NrNotLoadable", d));
        }