コード例 #1
0
        public void Dispose()
        {
            disposed      = true;
            isInitialized = false;
            Directory     = null;

            if (processor != null)
            {
                processor.Dispose();
            }
            processor = null;
        }
コード例 #2
0
        public bool Initialize()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(nameof(Database <T>));
            }
            if (isInitialized)
            {
                return(false);
            }

            processor = new DatabaseProcessor <T>(this);
            processor.LoadIndex();
            isInitialized = true;
            return(isInitialized);
        }
コード例 #3
0
        /// <summary>
        /// Handles the index building process for specified range.
        /// </summary>
        private void BuildIndex(IDatabaseProcessor <T> processor, FileInfo[] dataFiles, int startIndex, int loopCount)
        {
            var localIndex = new JObject[loopCount];

            for (int i = 0; i < loopCount; i++)
            {
                var file = dataFiles[i + startIndex];
                localIndex[i] = processor.LoadData(Path.GetFileNameWithoutExtension(file.Name), false).SerializeIndex();
            }

            lock (index)
            {
                for (int i = 0; i < localIndex.Length; i++)
                {
                    Set(localIndex[i]);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Rebuilds index from scratch using specified data files.
        /// </summary>
        private void RebuildIndex(IDatabaseProcessor <T> processor)
        {
            var dataFiles = processor.GetDataFiles();

            // Task allocation variables
            int taskCount = (dataFiles.Length - 1) / RebuildDataPerTask + 1;
            var tasks     = new Task[taskCount];

            // Allocate tasks
            for (int i = 0; i < taskCount; i++)
            {
                int startIndex = i * RebuildDataPerTask;
                int loopCount  = Math.Min(RebuildDataPerTask, dataFiles.Length - startIndex);
                tasks[i] = Task.Run(() => BuildIndex(processor, dataFiles, startIndex, loopCount));
            }

            // Wait for all tasks to finish.
            Task.WaitAll(tasks);
        }
コード例 #5
0
 public DatabaseQuery(IDatabaseProcessor <T> processor)
 {
     this.processor = processor;
 }
コード例 #6
0
 public void Dispose()
 {
     disposed       = true;
     processor      = null;
     filterHandlers = null;
 }
コード例 #7
0
 public DatabaseEditor(IDatabaseProcessor <T> processor)
 {
     this.processor = processor;
 }
コード例 #8
0
 public DatabaseIndex(IDatabaseProcessor <T> processor)
 {
     RebuildIndex(processor);
 }